Date: prev next · Thread: first prev next last
2013 Archives by date, by thread · List index


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/2715

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/15/2715/1

add gcc-wrapper

Change-Id: I961bd23d1ec382d247a489cda42194ce9f4fe1da
---
M Repository.mk
A solenv/Executable_g++-wrapper.mk
A solenv/Executable_gcc-wrapper.mk
M solenv/Module_solenv.mk
A solenv/StaticLibrary_wrapper.mk
M solenv/gbuild/ExternalProject.mk
A solenv/gcc-wrappers/g++.cxx
A solenv/gcc-wrappers/gcc.cxx
A solenv/gcc-wrappers/wrapper.cxx
A solenv/gcc-wrappers/wrapper.hxx
10 files changed, 331 insertions(+), 6 deletions(-)



diff --git a/Repository.mk b/Repository.mk
index ffcf18c..6c7e971 100644
--- a/Repository.mk
+++ b/Repository.mk
@@ -110,6 +110,8 @@
 $(eval $(call gb_Helper_register_executables,OOO,\
        crashrep_com \
        gengal \
+       gcc-wrapper \
+       g++-wrapper \
        guiloader \
        guistdio \
        langsupport \
@@ -138,6 +140,7 @@
        directxcanvas \
        winextendloaderenv \
        winlauncher \
+       wrapper \
 ))
 
 else
diff --git a/solenv/Executable_g++-wrapper.mk b/solenv/Executable_g++-wrapper.mk
new file mode 100755
index 0000000..526ff3a
--- /dev/null
+++ b/solenv/Executable_g++-wrapper.mk
@@ -0,0 +1,20 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_Executable_Executable,g++-wrapper))
+
+$(eval $(call gb_Executable_add_exception_objects,g++-wrapper,\
+       solenv/gcc-wrappers/g++ \
+))
+
+$(eval $(call gb_Executable_use_static_libraries,g++-wrapper,\
+    wrapper \
+))
+
+# vim:set noet sw=4 ts=4:
diff --git a/solenv/Executable_gcc-wrapper.mk b/solenv/Executable_gcc-wrapper.mk
new file mode 100644
index 0000000..ae76a33
--- /dev/null
+++ b/solenv/Executable_gcc-wrapper.mk
@@ -0,0 +1,20 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_Executable_Executable,gcc-wrapper))
+
+$(eval $(call gb_Executable_add_exception_objects,gcc-wrapper,\
+       solenv/gcc-wrappers/gcc \
+))
+
+$(eval $(call gb_Executable_use_static_libraries,gcc-wrapper,\
+    wrapper \
+))
+
+# vim:set noet sw=4 ts=4:
diff --git a/solenv/Module_solenv.mk b/solenv/Module_solenv.mk
index 3edb91b..f0bb4c2 100644
--- a/solenv/Module_solenv.mk
+++ b/solenv/Module_solenv.mk
@@ -31,15 +31,20 @@
        Executable_concat-deps \
 ))
 
-ifneq ($(OS),WNT)
-ifneq ($(OS),IOS)
-ifneq ($(OS),ANDROID)
+ifeq ($(COM),MSC)
+$(eval $(call gb_Module_add_targets,solenv,\
+       StaticLibrary_wrapper \
+       Executable_gcc-wrapper \
+       Executable_g++-wrapper \
+))
+endif
+
+
+ifneq ($(filter-out WNT IOS ANDROID,$(OS)),)
 $(eval $(call gb_Module_add_targets,solenv,\
        CustomTarget_gdb \
        Package_gdb \
 ))
-endif
-endif
 endif
 
 # vim: set shiftwidth=4 tabstop=4 noexpandtab:
diff --git a/solenv/StaticLibrary_wrapper.mk b/solenv/StaticLibrary_wrapper.mk
new file mode 100755
index 0000000..8fe81ef
--- /dev/null
+++ b/solenv/StaticLibrary_wrapper.mk
@@ -0,0 +1,16 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_StaticLibrary_StaticLibrary,wrapper))
+
+$(eval $(call gb_StaticLibrary_add_exception_objects,wrapper,\
+       solenv/gcc-wrappers/wrapper \
+))
+
+# vim:set noet sw=4 ts=4:
diff --git a/solenv/gbuild/ExternalProject.mk b/solenv/gbuild/ExternalProject.mk
index 20c0973..6443af3 100644
--- a/solenv/gbuild/ExternalProject.mk
+++ b/solenv/gbuild/ExternalProject.mk
@@ -180,6 +180,16 @@
 
 endef
 
+# Use the gcc wrappers for a autoconf based project
+#
+# gb_ExternalProject_register_targets project state_target
+define gb_ExternalProject_use_autoconf
+ifeq ($(COM),MSC)
+$(call gb_ExternalProject_get_preparation_target,$(1)) : $(call 
gb_Executable_get_runtime_dependencies,gcc-wrapper) \
+       $(call gb_Executable_get_runtime_dependencies,g++-wrapper)
+$(call gb_ExternalProject_get_state_target,$(1),$(2)): WRAPPERS := $(AUTOCONF_WRAPPERS)
+endif
+endef
 
 # Run a target command
 #
@@ -190,8 +200,17 @@
 # default log_filename is <run_target>.log
 #
 
+AUTOCONF_WRAPPERS := \
+       REAL_CC="$(shell cygpath -w $(CC))" \
+       CC="$(call gb_Executable_get_target,gcc-wrapper)" \
+       REAL_CXX="$(shell cygpath -w $(CXX))" \
+       CXX="$(call gb_Executable_get_target,g++-wrapper)" \
+    LD="$(shell cygpath -w $(COMPATH)/bin/link.exe) -nologo"
+
 define gb_ExternalProject_run
-$(call gb_Helper_print_on_error,cd $(EXTERNAL_WORKDIR)/$(3) && $(2) && touch 
$@,$(EXTERNAL_WORKDIR)/$(if $(3),$(3)/,)$(if $(4),$(4),$(1).log))
+$(call gb_Helper_print_on_error,cd $(EXTERNAL_WORKDIR)/$(3) && \
+       $(if $(filter MSC,$(COM)),$(if $(WRAPPERS),export $(WRAPPERS) &&)) \
+       $(2) && touch $@,$(EXTERNAL_WORKDIR)/$(if $(3),$(3)/,)$(if $(4),$(4),$(1).log))
 endef
 
 # vim: set noet sw=4 ts=4:
diff --git a/solenv/gcc-wrappers/g++.cxx b/solenv/gcc-wrappers/g++.cxx
new file mode 100755
index 0000000..d2ee3d5
--- /dev/null
+++ b/solenv/gcc-wrappers/g++.cxx
@@ -0,0 +1,25 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+* This file is part of the LibreOffice project.
+*
+* This Source Code Form is subject to the terms of the Mozilla Public
+* License, v. 2.0. If a copy of the MPL was not distributed with this
+* file, You can obtain one at http://mozilla.org/MPL/2.0/.
+*/
+
+#include "wrapper.hxx"
+
+int main(int argc, char *argv[]) {
+    vector<string> rawargs(argv + 1, argv + argc);
+
+    string command=getexe("REAL_CXX");
+
+    string args=processccargs(rawargs);
+
+    setupccenv();
+
+    return startprocess(command,args);
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/solenv/gcc-wrappers/gcc.cxx b/solenv/gcc-wrappers/gcc.cxx
new file mode 100755
index 0000000..b8983cf
--- /dev/null
+++ b/solenv/gcc-wrappers/gcc.cxx
@@ -0,0 +1,25 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+* This file is part of the LibreOffice project.
+*
+* This Source Code Form is subject to the terms of the Mozilla Public
+* License, v. 2.0. If a copy of the MPL was not distributed with this
+* file, You can obtain one at http://mozilla.org/MPL/2.0/.
+*/
+
+#include "wrapper.hxx"
+
+int main(int argc, char *argv[]) {
+    vector<string> rawargs(argv + 1, argv + argc);
+
+    string command=getexe("REAL_CC");
+
+    string args=processccargs(rawargs);
+
+    setupccenv();
+
+    return startprocess(command,args);
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/solenv/gcc-wrappers/wrapper.cxx b/solenv/gcc-wrappers/wrapper.cxx
new file mode 100644
index 0000000..4976305
--- /dev/null
+++ b/solenv/gcc-wrappers/wrapper.cxx
@@ -0,0 +1,168 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+* This file is part of the LibreOffice project.
+*
+* This Source Code Form is subject to the terms of the Mozilla Public
+* License, v. 2.0. If a copy of the MPL was not distributed with this
+* file, You can obtain one at http://mozilla.org/MPL/2.0/.
+*/
+
+#include "wrapper.hxx"
+
+#include <windows.h>
+
+#define BUFLEN 2048
+
+string getexe(string exename) {
+    char* cmdbuf;
+    size_t cmdlen;
+    _dupenv_s(&cmdbuf,&cmdlen,exename.c_str());
+    if(!cmdbuf) {
+        cout << "Error " << exename << " not defined. Did you forget to source the enviroment?" << 
endl;
+        exit(1);
+    }
+    string command(cmdbuf);
+    free(cmdbuf);
+    return command;
+}
+
+void setupccenv() {
+    // Set-up library path
+    string libpath="LIB=";
+    char* libbuf;
+    size_t liblen;
+    _dupenv_s(&libbuf,&liblen,"ILIB");
+    libpath.append(libbuf);
+    free(libbuf);
+    if(_putenv(libpath.c_str())<0) {
+        cerr << "Error: could not export LIB" << endl;
+        exit(1);
+    }
+
+    // Set-up include path
+    string includepath="INCLUDE=.;";
+    char* incbuf;
+    size_t inclen;
+    _dupenv_s(&incbuf,&inclen,"SOLARINC");
+    string inctmp(incbuf);
+    free(incbuf);
+
+    // 3 = strlen(" -I")
+    for(size_t pos=0; pos != string::npos;) {
+        size_t endpos=inctmp.find(" -I",pos+3);
+        size_t len=endpos-pos-3;
+        if(endpos==string::npos)
+            includepath.append(inctmp,pos+3,endpos);
+        else if(len>0) {
+            includepath.append(inctmp,pos+3,len);
+            includepath.append(";");
+        }
+        pos=inctmp.find(" -I",pos+len);
+    }
+    if(_putenv(includepath.c_str())<0) {
+        cerr << "Error: could not export INCLUDE" << endl;
+        exit(1);
+    }
+}
+
+string processccargs(vector<string> rawargs) {
+    // suppress the msvc banner
+    string args=" -nologo";
+    // TODO: should these options be enabled globally?
+    args.append(" -EHsc");
+    args.append(" -MD");
+
+    for(vector<string>::iterator i = rawargs.begin(); i != rawargs.end(); ++i) {
+        args.append(" ");
+        if(*i == "-o") {
+            // TODO: handle more than just exe output
+            args.append("-Fe");
+            ++i;
+            args.append(*i);
+        }
+        else if(*i == "-g")
+            args.append("-Zi");
+        else if(!(*i).compare(0,2,"-D")) {
+            // need to re-escape strings for preprocessor
+            for(size_t pos=(*i).find("\"",0); pos!=string::npos; pos=(*i).find("\"",pos)) {
+                (*i).replace(pos,0,"\\");
+                pos+=2;
+            }
+            args.append(*i);
+        }
+        else
+            args.append(*i);
+    }
+    return args;
+}
+
+int startprocess(string command, string args) {
+    STARTUPINFO si;
+    PROCESS_INFORMATION pi;
+    SECURITY_ATTRIBUTES sa;
+
+    HANDLE childout_read;
+    HANDLE childout_write;
+
+    memset(&sa,0,sizeof(sa));
+    memset(&si,0,sizeof(si));
+    memset(&pi,0,sizeof(pi));
+
+    sa.nLength=sizeof(sa);
+    sa.bInheritHandle=TRUE;
+
+    if(!CreatePipe(&childout_read,&childout_write,&sa,0)) {
+        cerr << "Error: could not create sdtout pipe" << endl;
+        exit(1);
+    }
+
+    si.cb=sizeof(si);
+    si.dwFlags |= STARTF_USESTDHANDLES;
+    si.hStdOutput=childout_write;
+    si.hStdError=childout_write;
+
+    // Commandline may be modified by CreateProcess
+    char* cmdline=_strdup(args.c_str());
+
+    if(!CreateProcess(command.c_str(), // Process Name
+        cmdline, // Command Line
+        NULL, // Process Handle not Inheritable
+        NULL, // Thread Handle not Inheritable
+        TRUE, // Handles are Inherited
+        0, // No creation flags
+        NULL, // Enviroment for process
+        NULL, // Use same starting directory
+        &si, // Startup Info
+        &pi) // Process Information
+        ) {
+            cerr << "Error: could not create process" << endl;
+            exit(1);
+    }
+
+    // if you don't close this the process will hang
+    CloseHandle(childout_write);
+
+    // Get Process output
+    char buffer[BUFLEN];
+    DWORD readlen, writelen, ret;
+    HANDLE stdout_handle=GetStdHandle(STD_OUTPUT_HANDLE);
+    while(true) {
+        int success=ReadFile(childout_read,buffer,BUFLEN,&readlen,NULL);
+        // check if the child process has exited
+        if(GetLastError()==ERROR_BROKEN_PIPE)
+            break;
+        if(!success) {
+            cerr << "Error: could not read from subprocess stdout" << endl;
+            exit(1);
+        }
+        if(readlen!=0) {
+                WriteFile(stdout_handle,buffer,readlen,&writelen,NULL);
+        }
+    }
+    GetExitCodeProcess(pi.hProcess, &ret);
+    CloseHandle(pi.hThread);
+    CloseHandle(pi.hProcess);
+    return int(ret);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/solenv/gcc-wrappers/wrapper.hxx b/solenv/gcc-wrappers/wrapper.hxx
new file mode 100755
index 0000000..9850741
--- /dev/null
+++ b/solenv/gcc-wrappers/wrapper.hxx
@@ -0,0 +1,24 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+* This file is part of the LibreOffice project.
+*
+* This Source Code Form is subject to the terms of the Mozilla Public
+* License, v. 2.0. If a copy of the MPL was not distributed with this
+* file, You can obtain one at http://mozilla.org/MPL/2.0/.
+*/
+
+#include <string>
+#include <iostream>
+#include <vector>
+
+using namespace std;
+
+string getexe(string exename);
+
+void setupccenv();
+
+string processccargs(vector<string> rawargs);
+
+int startprocess(string command, string args);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

-- 
To view, visit https://gerrit.libreoffice.org/2715
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I961bd23d1ec382d247a489cda42194ce9f4fe1da
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Peter Foley <pefoley2@verizon.net>


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.