78f286716f3f4a9a6c6103c35b53c1b300c31e9f
[amitay/samba.git] / third_party / waf / waflib / Tools / gcc.py
1 #! /usr/bin/env python
2 # encoding: utf-8
3 # WARNING! Do not edit! https://waf.io/book/index.html#_obtaining_the_waf_file
4
5 #!/usr/bin/env python
6 # encoding: utf-8
7 # Thomas Nagy, 2006-2016 (ita)
8 # Ralf Habacker, 2006 (rh)
9 # Yinon Ehrlich, 2009
10
11 """
12 gcc/llvm detection.
13 """
14
15 from waflib.Tools import ccroot, ar
16 from waflib.Configure import conf
17
18 @conf
19 def find_gcc(conf):
20         """
21         Find the program gcc, and if present, try to detect its version number
22         """
23         cc = conf.find_program(['gcc', 'cc'], var='CC')
24         conf.get_cc_version(cc, gcc=True)
25         conf.env.CC_NAME = 'gcc'
26
27 @conf
28 def gcc_common_flags(conf):
29         """
30         Common flags for gcc on nearly all platforms
31         """
32         v = conf.env
33
34         v.CC_SRC_F            = []
35         v.CC_TGT_F            = ['-c', '-o']
36
37         if not v.LINK_CC:
38                 v.LINK_CC = v.CC
39
40         v.CCLNK_SRC_F         = []
41         v.CCLNK_TGT_F         = ['-o']
42         v.CPPPATH_ST          = '-I%s'
43         v.DEFINES_ST          = '-D%s'
44
45         v.LIB_ST              = '-l%s' # template for adding libs
46         v.LIBPATH_ST          = '-L%s' # template for adding libpaths
47         v.STLIB_ST            = '-l%s'
48         v.STLIBPATH_ST        = '-L%s'
49         v.RPATH_ST            = '-Wl,-rpath,%s'
50
51         v.SONAME_ST           = '-Wl,-h,%s'
52         v.SHLIB_MARKER        = '-Wl,-Bdynamic'
53         v.STLIB_MARKER        = '-Wl,-Bstatic'
54
55         v.cprogram_PATTERN    = '%s'
56
57         v.CFLAGS_cshlib       = ['-fPIC']
58         v.LINKFLAGS_cshlib    = ['-shared']
59         v.cshlib_PATTERN      = 'lib%s.so'
60
61         v.LINKFLAGS_cstlib    = ['-Wl,-Bstatic']
62         v.cstlib_PATTERN      = 'lib%s.a'
63
64         v.LINKFLAGS_MACBUNDLE = ['-bundle', '-undefined', 'dynamic_lookup']
65         v.CFLAGS_MACBUNDLE    = ['-fPIC']
66         v.macbundle_PATTERN   = '%s.bundle'
67
68 @conf
69 def gcc_modifier_win32(conf):
70         """Configuration flags for executing gcc on Windows"""
71         v = conf.env
72         v.cprogram_PATTERN    = '%s.exe'
73
74         v.cshlib_PATTERN      = '%s.dll'
75         v.implib_PATTERN      = 'lib%s.dll.a'
76         v.IMPLIB_ST           = '-Wl,--out-implib,%s'
77
78         v.CFLAGS_cshlib       = []
79
80         # Auto-import is enabled by default even without this option,
81         # but enabling it explicitly has the nice effect of suppressing the rather boring, debug-level messages
82         # that the linker emits otherwise.
83         v.append_value('LINKFLAGS', ['-Wl,--enable-auto-import'])
84
85 @conf
86 def gcc_modifier_cygwin(conf):
87         """Configuration flags for executing gcc on Cygwin"""
88         gcc_modifier_win32(conf)
89         v = conf.env
90         v.cshlib_PATTERN = 'cyg%s.dll'
91         v.append_value('LINKFLAGS_cshlib', ['-Wl,--enable-auto-image-base'])
92         v.CFLAGS_cshlib = []
93
94 @conf
95 def gcc_modifier_darwin(conf):
96         """Configuration flags for executing gcc on MacOS"""
97         v = conf.env
98         v.CFLAGS_cshlib       = ['-fPIC']
99         v.LINKFLAGS_cshlib    = ['-dynamiclib']
100         v.cshlib_PATTERN      = 'lib%s.dylib'
101         v.FRAMEWORKPATH_ST    = '-F%s'
102         v.FRAMEWORK_ST        = ['-framework']
103         v.ARCH_ST             = ['-arch']
104
105         v.LINKFLAGS_cstlib    = []
106
107         v.SHLIB_MARKER        = []
108         v.STLIB_MARKER        = []
109         v.SONAME_ST           = []
110
111 @conf
112 def gcc_modifier_aix(conf):
113         """Configuration flags for executing gcc on AIX"""
114         v = conf.env
115         v.LINKFLAGS_cprogram  = ['-Wl,-brtl']
116         v.LINKFLAGS_cshlib    = ['-shared','-Wl,-brtl,-bexpfull']
117         v.SHLIB_MARKER        = []
118
119 @conf
120 def gcc_modifier_hpux(conf):
121         v = conf.env
122         v.SHLIB_MARKER        = []
123         v.STLIB_MARKER        = []
124         v.CFLAGS_cshlib       = ['-fPIC','-DPIC']
125         v.cshlib_PATTERN      = 'lib%s.sl'
126
127 @conf
128 def gcc_modifier_openbsd(conf):
129         conf.env.SONAME_ST = []
130
131 @conf
132 def gcc_modifier_osf1V(conf):
133         v = conf.env
134         v.SHLIB_MARKER        = []
135         v.STLIB_MARKER        = []
136         v.SONAME_ST           = []
137
138 @conf
139 def gcc_modifier_platform(conf):
140         """Execute platform-specific functions based on *gcc_modifier_+NAME*"""
141         # * set configurations specific for a platform.
142         # * the destination platform is detected automatically by looking at the macros the compiler predefines,
143         #   and if it's not recognised, it fallbacks to sys.platform.
144         gcc_modifier_func = getattr(conf, 'gcc_modifier_' + conf.env.DEST_OS, None)
145         if gcc_modifier_func:
146                 gcc_modifier_func()
147
148 def configure(conf):
149         """
150         Configuration for gcc
151         """
152         conf.find_gcc()
153         conf.find_ar()
154         conf.gcc_common_flags()
155         conf.gcc_modifier_platform()
156         conf.cc_load_tools()
157         conf.cc_add_flags()
158         conf.link_add_flags()