[pypy-svn] r73549 - in pypy/branch/cpython-extension/pypy/translator: c/gcc/test platform

afa at codespeak.net afa at codespeak.net
Thu Apr 8 15:44:11 CEST 2010


Author: afa
Date: Thu Apr  8 15:44:10 2010
New Revision: 73549

Modified:
   pypy/branch/cpython-extension/pypy/translator/c/gcc/test/test_asmgcroot.py
   pypy/branch/cpython-extension/pypy/translator/platform/posix.py
Log:
Fix generation of Makefile with the --shared option


Modified: pypy/branch/cpython-extension/pypy/translator/c/gcc/test/test_asmgcroot.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/c/gcc/test/test_asmgcroot.py	(original)
+++ pypy/branch/cpython-extension/pypy/translator/c/gcc/test/test_asmgcroot.py	Thu Apr  8 15:44:10 2010
@@ -53,7 +53,12 @@
                 redirect = ' 2> NUL'
             else:
                 redirect = ''
-            g = os.popen('"%s" %s %d%s' % (exe_name, arg0, arg1, redirect), 'r')
+            if config.translation.shared and os.name == 'posix':
+                env = 'LD_LIBRARY_PATH="%s" ' % (exe_name.dirpath(),)
+            else:
+                env = ''
+            g = os.popen(
+                '%s"%s" %s %d%s' % (env, exe_name, arg0, arg1, redirect), 'r')
             for line in g:
                 print >> sys.stderr, 'RUN:', line.rstrip()
                 lines.append(line)

Modified: pypy/branch/cpython-extension/pypy/translator/platform/posix.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/platform/posix.py	(original)
+++ pypy/branch/cpython-extension/pypy/translator/platform/posix.py	Thu Apr  8 15:44:10 2010
@@ -77,6 +77,12 @@
         if shared:
             linkflags = self._args_for_shared(linkflags)
 
+        if shared:
+            libname = exe_name.new(ext='').basename
+            target_name = 'lib' + exe_name.new(ext=self.so_ext).basename
+        else:
+            target_name = exe_name.basename
+
         m = GnuMakefile(path)
         m.exe_name = exe_name
         m.eci = eci
@@ -98,8 +104,8 @@
         m.comment('automatically generated makefile')
         definitions = [
             ('PYPYDIR', autopath.pypydir),
-            ('TARGET', exe_name.basename),
-            ('DEFAULT_TARGET', '$(TARGET)'),
+            ('TARGET', target_name),
+            ('DEFAULT_TARGET', exe_name.basename),
             ('SOURCES', rel_cfiles),
             ('OBJECTS', rel_ofiles),
             ('LIBS', self._libs(eci.libraries)),
@@ -125,6 +131,16 @@
         for rule in rules:
             m.rule(*rule)
 
+        if shared:
+            m.definition('SHARED_IMPORT_LIB', libname),
+            m.rule('main.c', '',
+                   'echo "'
+                   'int $(PYPY_MAIN_FUNCTION)(int, char*[]); '
+                   'int main(int argc, char* argv[]) '
+                   '{ return $(PYPY_MAIN_FUNCTION)(argc, argv); }" > $@')
+            m.rule('$(DEFAULT_TARGET)', ['$(TARGET)', 'main.o'],
+                   '$(CC_LINK) main.o -L. -l$(SHARED_IMPORT_LIB) -o $@')
+
         return m
 
     def execute_makefile(self, path_to_makefile, extra_opts=[]):



More information about the Pypy-commit mailing list