3 # Thomas Nagy, 2006-2018 (ita)
4 # Ralf Habacker, 2006 (rh)
11 from waflib.Tools import ccroot, ar
12 from waflib.Configure import conf
17 Find the program gcc, and if present, try to detect its version number
19 cc = conf.find_program(['gcc', 'cc'], var='CC')
20 conf.get_cc_version(cc, gcc=True)
21 conf.env.CC_NAME = 'gcc'
24 def gcc_common_flags(conf):
26 Common flags for gcc on nearly all platforms
31 v.CC_TGT_F = ['-c', '-o']
37 v.CCLNK_TGT_F = ['-o']
41 v.LIB_ST = '-l%s' # template for adding libs
42 v.LIBPATH_ST = '-L%s' # template for adding libpaths
44 v.STLIBPATH_ST = '-L%s'
45 v.RPATH_ST = '-Wl,-rpath,%s'
47 v.SONAME_ST = '-Wl,-h,%s'
48 v.SHLIB_MARKER = '-Wl,-Bdynamic'
49 v.STLIB_MARKER = '-Wl,-Bstatic'
51 v.cprogram_PATTERN = '%s'
53 v.CFLAGS_cshlib = ['-fPIC']
54 v.LINKFLAGS_cshlib = ['-shared']
55 v.cshlib_PATTERN = 'lib%s.so'
57 v.LINKFLAGS_cstlib = ['-Wl,-Bstatic']
58 v.cstlib_PATTERN = 'lib%s.a'
60 v.LINKFLAGS_MACBUNDLE = ['-bundle', '-undefined', 'dynamic_lookup']
61 v.CFLAGS_MACBUNDLE = ['-fPIC']
62 v.macbundle_PATTERN = '%s.bundle'
65 def gcc_modifier_win32(conf):
66 """Configuration flags for executing gcc on Windows"""
68 v.cprogram_PATTERN = '%s.exe'
70 v.cshlib_PATTERN = '%s.dll'
71 v.implib_PATTERN = '%s.dll.a'
72 v.IMPLIB_ST = '-Wl,--out-implib,%s'
76 # Auto-import is enabled by default even without this option,
77 # but enabling it explicitly has the nice effect of suppressing the rather boring, debug-level messages
78 # that the linker emits otherwise.
79 v.append_value('LINKFLAGS', ['-Wl,--enable-auto-import'])
82 def gcc_modifier_cygwin(conf):
83 """Configuration flags for executing gcc on Cygwin"""
84 gcc_modifier_win32(conf)
86 v.cshlib_PATTERN = 'cyg%s.dll'
87 v.append_value('LINKFLAGS_cshlib', ['-Wl,--enable-auto-image-base'])
91 def gcc_modifier_darwin(conf):
92 """Configuration flags for executing gcc on MacOS"""
94 v.CFLAGS_cshlib = ['-fPIC']
95 v.LINKFLAGS_cshlib = ['-dynamiclib']
96 v.cshlib_PATTERN = 'lib%s.dylib'
97 v.FRAMEWORKPATH_ST = '-F%s'
98 v.FRAMEWORK_ST = ['-framework']
101 v.LINKFLAGS_cstlib = []
108 def gcc_modifier_aix(conf):
109 """Configuration flags for executing gcc on AIX"""
111 v.LINKFLAGS_cprogram = ['-Wl,-brtl']
112 v.LINKFLAGS_cshlib = ['-shared','-Wl,-brtl,-bexpfull']
116 def gcc_modifier_hpux(conf):
120 v.CFLAGS_cshlib = ['-fPIC','-DPIC']
121 v.cshlib_PATTERN = 'lib%s.sl'
124 def gcc_modifier_openbsd(conf):
125 conf.env.SONAME_ST = []
128 def gcc_modifier_osf1V(conf):
135 def gcc_modifier_platform(conf):
136 """Execute platform-specific functions based on *gcc_modifier_+NAME*"""
137 # * set configurations specific for a platform.
138 # * the destination platform is detected automatically by looking at the macros the compiler predefines,
139 # and if it's not recognised, it fallbacks to sys.platform.
140 gcc_modifier_func = getattr(conf, 'gcc_modifier_' + conf.env.DEST_OS, None)
141 if gcc_modifier_func:
146 Configuration for gcc
150 conf.gcc_common_flags()
151 conf.gcc_modifier_platform()
154 conf.link_add_flags()
155 conf.check_gcc_o_space()