Cleared file executable bit that was set earlier by a mistake
[cython.git] / Cython / Mac / DarwinSystem.py
1 #
2 #   Pyrex - Darwin system interface
3 #
4
5 verbose = 0
6 gcc_pendantic = True
7 gcc_warnings_are_errors = True
8 gcc_all_warnings = True
9 gcc_optimize = False
10
11 import os, sys
12 from Cython.Utils import replace_suffix
13 from Cython.Compiler.Errors import PyrexError
14
15 version_string = "%s.%s" % sys.version_info[:2]
16
17 py_include_dirs = [
18     "/Library/Frameworks/Python.framework/Versions/%s/Headers" % version_string
19 ]
20
21 # MACOSX_DEPLOYMENT_TARGET can be set to 10.3 in most cases.
22 # But for the built-in Python 2.5.1 on Leopard, it needs to be set for 10.5.
23 # This looks like a bug that will be fixed in 2.5.2.  If Apple updates their
24 # Python to 2.5.2, this fix should be OK.
25 import distutils.sysconfig as sc
26 python_prefix = sc.get_config_var('prefix')
27 leopard_python_prefix = '/System/Library/Frameworks/Python.framework/Versions/2.5'
28 full_version = "%s.%s.%s" % sys.version_info[:3]
29 if python_prefix == leopard_python_prefix and full_version == '2.5.1':
30     os.environ["MACOSX_DEPLOYMENT_TARGET"] = "10.5"
31 else:
32     os.environ["MACOSX_DEPLOYMENT_TARGET"] = "10.3"
33
34 compilers = ["gcc", "g++"]
35 compiler_options = \
36     "-g -c -fno-strict-aliasing -Wno-long-double -no-cpp-precomp " \
37     "-mno-fused-madd -fno-common -dynamic " \
38     .split()
39 if gcc_pendantic:
40     compiler_options.extend(["-pedantic", "-Wno-long-long"])
41 if gcc_warnings_are_errors:
42     compiler_options.append("-Werror")
43 if gcc_all_warnings:
44     compiler_options.append("-Wall")
45     compiler_options.append("-Wno-unused-function")
46 if gcc_optimize:
47     compiler_options.append("-O")
48
49 linkers = ["gcc", "g++"]
50 linker_options = \
51     "-Wl,-F.,-w -bundle -undefined dynamic_lookup" \
52     .split()
53 #linker_options = \
54 #       "-Wl,-F.,-w -bundle -framework Python" \
55 #       .split()
56
57 class CCompilerError(PyrexError):
58     pass
59
60 def c_compile(c_file, verbose_flag = 0, cplus = 0, obj_suffix = ".o"):
61     #  Compile the given C source file to produce
62     #  an object file. Returns the pathname of the
63     #  resulting file.
64     c_file = os.path.join(os.getcwd(), c_file)
65     o_file = replace_suffix(c_file, obj_suffix)
66     include_options = []
67     for dir in py_include_dirs:
68         include_options.append("-I%s" % dir)
69     compiler = compilers[bool(cplus)]
70     args = [compiler] + compiler_options + include_options + [c_file, "-o", o_file]
71     if verbose_flag or verbose:
72         print(" ".join(args))
73     #print compiler, args ###
74     status = os.spawnvp(os.P_WAIT, compiler, args)
75     if status != 0:
76         raise CCompilerError("C compiler returned status %s" % status)
77     return o_file
78
79 def c_link(obj_file, verbose_flag = 0, extra_objects = [], cplus = 0):
80     return c_link_list([obj_file] + extra_objects, verbose_flag, cplus)
81
82 def c_link_list(obj_files, verbose_flag = 0, cplus = 0):
83     #  Link the given object files into a dynamically
84     #  loadable extension file. Returns the pathname
85     #  of the resulting file.
86     out_file = replace_suffix(obj_files[0], ".so")
87     linker = linkers[bool(cplus)]
88     args = [linker] + linker_options + obj_files + ["-o", out_file]
89     if verbose_flag or verbose:
90         print(" ".join(args))
91     status = os.spawnvp(os.P_WAIT, linker, args)
92     if status != 0:
93         raise CCompilerError("Linker returned status %s" % status)
94     return out_file