build: fixed uname output to be on target machine when cross compiling
[nivanova/samba-autobuild/.git] / buildtools / wafsamba / wscript
1 #!/usr/bin/env python
2
3 # this is a base set of waf rules that everything else pulls in first
4
5 import sys, wafsamba
6 import Options, os, preproc
7 from samba_utils import *
8 from optparse import SUPPRESS_HELP
9
10 def set_options(opt):
11     opt.tool_options('compiler_cc')
12
13     opt.tool_options('gnu_dirs')
14
15     gr = opt.add_option_group('library handling options')
16
17     gr.add_option('--bundled-libraries',
18                    help=("comma separated list of bundled libraries. May include !LIBNAME to disable bundling a library. Can be 'NONE' or 'ALL' [auto]"),
19                    action="store", dest='BUNDLED_LIBS', default='')
20
21     extension_default = Options.options['BUNDLED_EXTENSION_DEFAULT']
22     gr.add_option('--bundled-library-extension',
23                    help=("name extension for bundled libraries [%s]" % extension_default),
24                    action="store", dest='BUNDLED_EXTENSION', default=extension_default)
25
26     extension_exception = Options.options['BUNDLED_EXTENSION_EXCEPTION']
27     gr.add_option('--bundled-extension-exception',
28                    help=("comman separated list of libraries to not apply extension to [%s]" % extension_exception),
29                    action="store", dest='BUNDLED_EXTENSION_EXCEPTION', default=extension_exception)
30
31     builtin_defauilt = Options.options['BUILTIN_LIBRARIES_DEFAULT']
32     gr.add_option('--builtin-libraries',
33                    help=("command separated list of libraries to build directly into binaries [%s]" % builtin_defauilt),
34                    action="store", dest='BUILTIN_LIBRARIES', default=builtin_defauilt)
35
36     gr.add_option('--minimum-library-version',
37                    help=("list of minimum system library versions (LIBNAME1:version,LIBNAME2:version)"),
38                    action="store", dest='MINIMUM_LIBRARY_VERSION', default='')
39
40     gr.add_option('--disable-shared',
41                    help=("Disable all use of shared libraries"),
42                    action="store_true", dest='disable_shared', default=False)
43     gr.add_option('--disable-rpath',
44                    help=("Disable use of rpath for build binaries"),
45                    action="store_true", dest='disable_rpath_build', default=False)
46     gr.add_option('--disable-rpath-install',
47                    help=("Disable use of rpath for installed binaries"),
48                    action="store_true", dest='disable_rpath_install', default=False)
49
50     opt.add_option('--with-modulesdir',
51                    help=("modules directory [PREFIX/modules]"),
52                    action="store", dest='MODULESDIR', default='${PREFIX}/modules')
53
54     gr = opt.option_group('developer options')
55
56     gr.add_option('-C',
57                    help='enable configure cacheing',
58                    action='store_true', dest='enable_configure_cache')
59     gr.add_option('--enable-developer',
60                    help=("Turn on developer warnings and debugging"),
61                    action="store_true", dest='developer', default=False)
62     gr.add_option('--picky-developer',
63                    help=("Treat all warnings as errors (enable -Werror)"),
64                    action="store_true", dest='picky_developer', default=False)
65     gr.add_option('--fatal-errors',
66                    help=("Stop compilation on first error (enable -Wfatal-errors)"),
67                    action="store_true", dest='fatal_errors', default=False)
68     gr.add_option('--enable-gccdeps',
69                    help=("Enable use of gcc -MD dependency module"),
70                    action="store_true", dest='enable_gccdeps', default=False)
71     gr.add_option('--timestamp-dependencies',
72                    help=("use file timestamps instead of content for build dependencies (BROKEN)"),
73                    action="store_true", dest='timestamp_dependencies', default=False)
74     gr.add_option('--pedantic',
75                    help=("Enable even more compiler warnings"),
76                    action='store_true', dest='pedantic', default=False)
77
78     gr.add_option('--abi-check',
79                    help=("Check ABI signatures for libraries"),
80                    action='store_true', dest='ABI_CHECK', default=False)
81     gr.add_option('--abi-check-disable',
82                    help=("Disable ABI checking (used with --enable-developer)"),
83                    action='store_true', dest='ABI_CHECK_DISABLE', default=False)
84     gr.add_option('--abi-update',
85                    help=("Update ABI signature files for libraries"),
86                    action='store_true', dest='ABI_UPDATE', default=False)
87
88     gr = opt.add_option_group('cross compilation options')
89
90     gr.add_option('--cross-compile',
91                    help=("configure for cross-compilation"),
92                    action='store_true', dest='CROSS_COMPILE', default=False)
93     gr.add_option('--cross-execute',
94                    help=("command prefix to use for cross-execution in configure"),
95                    action='store', dest='CROSS_EXECUTE', default='')
96     gr.add_option('--cross-answers',
97                    help=("answers to cross-compilation configuration (auto modified)"),
98                    action='store', dest='CROSS_ANSWERS', default='')
99     gr.add_option('--hostcc',
100                    help=("set host compiler when cross compiling"),
101                    action='store', dest='HOSTCC', default=False)
102
103     # we use SUPPRESS_HELP for these, as they are ignored, and are there only
104     # to allow existing RPM spec files to work
105     opt.add_option('--build',
106                    help=SUPPRESS_HELP,
107                    action='store', dest='AUTOCONF_BUILD', default='')
108     opt.add_option('--host',
109                    help=SUPPRESS_HELP,
110                    action='store', dest='AUTOCONF_HOST', default='')
111     opt.add_option('--program-prefix',
112                    help=SUPPRESS_HELP,
113                    action='store', dest='AUTOCONF_PROGRAM_PREFIX', default='')
114     opt.add_option('--disable-dependency-tracking',
115                    help=SUPPRESS_HELP,
116                    action='store_true', dest='AUTOCONF_DISABLE_DEPENDENCY_TRACKING', default=False)
117
118
119 @wafsamba.runonce
120 def configure(conf):
121     conf.env.hlist = []
122     conf.env.srcdir = conf.srcdir
123
124     if Options.options.timestamp_dependencies:
125         conf.ENABLE_TIMESTAMP_DEPENDENCIES()
126
127     conf.SETUP_CONFIGURE_CACHE(Options.options.enable_configure_cache)
128
129     # load our local waf extensions
130     conf.check_tool('gnu_dirs')
131     conf.check_tool('wafsamba')
132
133     conf.CHECK_CC_ENV()
134
135     conf.check_tool('compiler_cc')
136
137     # we need git for 'waf dist'
138     conf.find_program('git', var='GIT')
139
140     if Options.options.enable_gccdeps:
141         # don't enable gccdeps by default as it needs a very recent version gcc
142         conf.check_tool('gccdeps', tooldir=conf.srcdir + "/buildtools/wafsamba")
143
144     # make the install paths available in environment
145     conf.env.LIBDIR = Options.options.LIBDIR or '${PREFIX}/lib'
146     conf.env.BINDIR = Options.options.BINDIR or '${PREFIX}/bin'
147     conf.env.SBINDIR = Options.options.SBINDIR or '${PREFIX}/sbin'
148     conf.env.MODULESDIR = Options.options.MODULESDIR
149     conf.env.BUNDLED_LIBS = Options.options.BUNDLED_LIBS.split(',')
150     conf.env.BUILTIN_LIBRARIES = Options.options.BUILTIN_LIBRARIES.split(',')
151     conf.env.DISABLE_SHARED = Options.options.disable_shared
152
153     conf.env.BUNDLED_EXTENSION = Options.options.BUNDLED_EXTENSION
154     conf.env.BUNDLED_EXTENSION_EXCEPTION = Options.options.BUNDLED_EXTENSION_EXCEPTION.split(',')
155
156     conf.env.CROSS_COMPILE = Options.options.CROSS_COMPILE
157     conf.env.CROSS_EXECUTE = Options.options.CROSS_EXECUTE
158     conf.env.CROSS_ANSWERS = Options.options.CROSS_ANSWERS
159     conf.env.HOSTCC        = Options.options.HOSTCC
160
161     conf.env.AUTOCONF_BUILD = Options.options.AUTOCONF_BUILD
162     conf.env.AUTOCONF_HOST  = Options.options.AUTOCONF_HOST
163     conf.env.AUTOCONF_PROGRAM_PREFIX = Options.options.AUTOCONF_PROGRAM_PREFIX
164
165     if conf.env.AUTOCONF_BUILD != conf.env.AUTOCONF_HOST:
166         Logs.error('ERROR: Mismatch between --build and --host. Please use --cross-compile instead')
167         sys.exit(1)
168     if conf.env.AUTOCONF_PROGRAM_PREFIX:
169         Logs.error('ERROR: --program-prefix not supported')
170         sys.exit(1)
171
172     # enable ABI checking for developers
173     conf.env.ABI_CHECK = Options.options.ABI_CHECK or Options.options.developer
174     if Options.options.ABI_CHECK_DISABLE:
175         conf.env.ABI_CHECK = False
176
177     conf.CHECK_COMMAND(['uname', '-a'],
178                        msg='Checking build system',
179                        define='BUILD_SYSTEM',
180                        on_target=False)
181     conf.CHECK_UNAME()
182
183     # see if we can compile and run a simple C program
184     conf.CHECK_CODE('printf("hello world")',
185                     define='HAVE_SIMPLE_C_PROG',
186                     mandatory=True,
187                     execute=True,
188                     headers='stdio.h',
189                     msg='Checking simple C program')
190
191     # see if we can build shared libs
192     if not conf.CHECK_LIBRARY_SUPPORT():
193         conf.env.DISABLE_SHARED = True
194
195     # check for rpath
196     if not conf.env.DISABLE_SHARED and conf.CHECK_LIBRARY_SUPPORT(rpath=True):
197         conf.env.RPATH_ON_BUILD   = not Options.options.disable_rpath_build
198         conf.env.RPATH_ON_INSTALL = (conf.env.RPATH_ON_BUILD and
199                                      not Options.options.disable_rpath_install)
200     else:
201         conf.env.RPATH_ON_INSTALL = False
202         conf.env.RPATH_ON_BUILD   = False
203
204     # we should use the PIC options in waf instead
205     conf.ADD_CFLAGS('-fPIC', testflags=True)
206
207     # check for pkgconfig
208     conf.check_cfg(atleast_pkgconfig_version='0.0.0')
209
210     conf.DEFINE('_GNU_SOURCE', 1, add_to_cflags=True)
211     conf.DEFINE('_XOPEN_SOURCE_EXTENDED', 1, add_to_cflags=True)
212
213     # get the base headers we'll use for the rest of the tests
214     conf.CHECK_HEADERS('stdio.h sys/types.h sys/stat.h stdlib.h stddef.h memory.h string.h',
215                        add_headers=True)
216     conf.CHECK_HEADERS('strings.h inttypes.h stdint.h unistd.h minix/config.h', add_headers=True)
217     conf.CHECK_HEADERS('ctype.h standards.h stdbool.h stdint.h stdarg.h vararg.h', add_headers=True)
218     conf.CHECK_HEADERS('limits.h assert.h')
219
220     # see if we need special largefile flags
221     conf.CHECK_LARGEFILE()
222
223     if 'HAVE_STDDEF_H' in conf.env and 'HAVE_STDLIB_H' in conf.env:
224         conf.DEFINE('STDC_HEADERS', 1)
225
226     conf.CHECK_HEADERS('sys/time.h time.h', together=True)
227
228     if 'HAVE_SYS_TIME_H' in conf.env and 'HAVE_TIME_H' in conf.env:
229         conf.DEFINE('TIME_WITH_SYS_TIME', 1)
230
231     conf.define('SHLIBEXT', "so", quote=True)
232
233     conf.CHECK_CODE('long one = 1; return ((char *)(&one))[0]',
234                     execute=True,
235                     define='WORDS_BIGENDIAN')
236
237     # check if signal() takes a void function
238     if conf.CHECK_CODE('return *(signal (0, 0)) (0) == 1',
239                        define='RETSIGTYPE_INT',
240                        execute=False,
241                        headers='signal.h',
242                        msg='Checking if signal handlers return int'):
243         conf.DEFINE('RETSIGTYPE', 'int')
244     else:
245         conf.DEFINE('RETSIGTYPE', 'void')
246
247     conf.CHECK_VARIABLE('__FUNCTION__', define='HAVE_FUNCTION_MACRO')
248
249     conf.CHECK_CODE('va_list ap1,ap2; va_copy(ap1,ap2)',
250                     define="HAVE_VA_COPY",
251                     msg="Checking for va_copy")
252
253     conf.CHECK_CODE('''
254                     #define eprintf(...) fprintf(stderr, __VA_ARGS__)
255                     eprintf("bla", "bar")
256                     ''', define='HAVE__VA_ARGS__MACRO')
257
258     conf.SAMBA_BUILD_ENV()
259
260
261 def build(bld):
262     bld.CHECK_MAKEFLAGS()
263     bld.SETUP_BUILD_GROUPS()
264     bld.ENFORCE_GROUP_ORDERING()
265     bld.CHECK_PROJECT_RULES()