build: fixed a typo that prevented --bundled-libraries from working correctly
[samba.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
9 def set_options(opt):
10     opt.tool_options('compiler_cc')
11
12     opt.tool_options('gnu_dirs')
13
14     opt.add_option('--bundled-libraries',
15                    help=("comma separated list of bundled libraries. May include !LIBNAME to disable bundling a library. Can be 'NONE' or 'ALL' [auto]"),
16                    action="store", dest='BUNDLED_LIBS', default='')
17
18     extension_default = Options.options['BUNDLED_EXTENSION_DEFAULT']
19     opt.add_option('--bundled-library-extension',
20                    help=("name extension for bundled libraries [%s]" % extension_default),
21                    action="store", dest='BUNDLED_EXTENSION', default=extension_default)
22
23     extension_exception = Options.options['BUNDLED_EXTENSION_EXCEPTION']
24     opt.add_option('--bundled-extension-exception',
25                    help=("comman separated list of libraries to not apply extension to [%s]" % extension_exception),
26                    action="store", dest='BUNDLED_EXTENSION_EXCEPTION', default=extension_exception)
27
28     builtin_defauilt = Options.options['BUILTIN_LIBRARIES_DEFAULT']
29     opt.add_option('--builtin-libraries',
30                    help=("command separated list of libraries to build directly into binaries [%s]" % builtin_defauilt),
31                    action="store", dest='BUILTIN_LIBRARIES', default=builtin_defauilt)
32
33     opt.add_option('--minimum-library-version',
34                    help=("list of minimum system library versions (LIBNAME1:version,LIBNAME2:version)"),
35                    action="store", dest='MINIMUM_LIBRARY_VERSION', default='')
36
37     opt.add_option('--with-modulesdir',
38                    help=("modules directory [PREFIX/modules]"),
39                    action="store", dest='MODULESDIR', default='${PREFIX}/modules')
40     opt.add_option('--disable-shared',
41                    help=("Disable all use of shared libraries"),
42                    action="store_true", dest='disable_shared', default=False)
43     opt.add_option('--disable-rpath',
44                    help=("Disable use of rpath for build binaries"),
45                    action="store_true", dest='disable_rpath_build', default=False)
46     opt.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     opt.add_option('--enable-developer',
50                    help=("Turn on developer warnings and debugging"),
51                    action="store_true", dest='developer', default=False)
52     opt.add_option('--picky-developer',
53                    help=("Treat all warnings as errors (enable -Werror)"),
54                    action="store_true", dest='picky_developer', default=False)
55     opt.add_option('--fatal-errors',
56                    help=("Stop compilation on first error (enable -Wfatal-errors)"),
57                    action="store_true", dest='fatal_errors', default=False)
58     opt.add_option('--enable-gccdeps',
59                    help=("Enable use gcc -MD dependency module"),
60                    action="store_true", dest='enable_gccdeps', default=False)
61     opt.add_option('--timestamp-dependencies',
62                    help=("use file timestamps instead of content for build dependencies (BROKEN)"),
63                    action="store_true", dest='timestamp_dependencies', default=False)
64     opt.add_option('-C',
65                    help='enable configure cacheing',
66                    action='store_true', dest='enable_configure_cache')
67     opt.add_option('--pedantic',
68                    help=("Enable even more compiler warnings"),
69                    action='store_true', dest='pedantic', default=False)
70
71     opt.add_option('--cross-compile',
72                    help=("configure for cross-compilation"),
73                    action='store_true', dest='CROSS_COMPILE', default=False)
74     opt.add_option('--cross-execute',
75                    help=("command prefix to use for cross-execution in configure"),
76                    action='store', dest='CROSS_EXECUTE', default='')
77     opt.add_option('--hostcc',
78                    help=("set host compiler when cross compiling"),
79                    action='store', dest='HOSTCC', default=False)
80
81
82 @wafsamba.runonce
83 def configure(conf):
84     conf.env.hlist = []
85     conf.env.srcdir = conf.srcdir
86
87     if Options.options.timestamp_dependencies:
88         conf.ENABLE_TIMESTAMP_DEPENDENCIES()
89
90     conf.SETUP_CONFIGURE_CACHE(Options.options.enable_configure_cache)
91
92     # load our local waf extensions
93     conf.check_tool('gnu_dirs')
94     conf.check_tool('wafsamba')
95
96     conf.CHECK_CC_ENV()
97
98     conf.check_tool('compiler_cc')
99
100     # we need git for 'waf dist'
101     conf.find_program('git', var='GIT')
102
103     if Options.options.enable_gccdeps:
104         # don't enable gccdeps by default as it needs a very recent version gcc
105         conf.check_tool('gccdeps', tooldir=conf.srcdir + "/buildtools/wafsamba")
106
107     # make the install paths available in environment
108     conf.env.LIBDIR = Options.options.LIBDIR or '${PREFIX}/lib'
109     conf.env.BINDIR = Options.options.BINDIR or '${PREFIX}/bin'
110     conf.env.SBINDIR = Options.options.SBINDIR or '${PREFIX}/sbin'
111     conf.env.MODULESDIR = Options.options.MODULESDIR
112     conf.env.BUNDLED_LIBS = Options.options.BUNDLED_LIBS.split(',')
113     conf.env.BUILTIN_LIBRARIES = Options.options.BUILTIN_LIBRARIES.split(',')
114     conf.env.DISABLE_SHARED = Options.options.disable_shared
115
116     conf.env.BUNDLED_EXTENSION = Options.options.BUNDLED_EXTENSION
117     conf.env.BUNDLED_EXTENSION_EXCEPTION = Options.options.BUNDLED_EXTENSION_EXCEPTION.split(',')
118
119     conf.env.CROSS_COMPILE = Options.options.CROSS_COMPILE
120     conf.env.CROSS_EXECUTE = Options.options.CROSS_EXECUTE
121     conf.env.HOSTCC        = Options.options.HOSTCC
122
123     # see if we can compile and run a simple C program
124     conf.CHECK_CODE('printf("hello world\\n")',
125                     define='HAVE_SIMPLE_C_PROG',
126                     mandatory=True,
127                     execute=True,
128                     headers='stdio.h',
129                     msg='Checking simple C program')
130
131     # see if we can build shared libs
132     if not conf.CHECK_LIBRARY_SUPPORT():
133         conf.env.DISABLE_SHARED = True
134
135     # check for rpath
136     if not conf.env.DISABLE_SHARED and conf.CHECK_LIBRARY_SUPPORT(rpath=True):
137         conf.env.RPATH_ON_BUILD   = not Options.options.disable_rpath_build
138         conf.env.RPATH_ON_INSTALL = (conf.env.RPATH_ON_BUILD and
139                                      not Options.options.disable_rpath_install)
140     else:
141         conf.env.RPATH_ON_INSTALL = False
142         conf.env.RPATH_ON_BUILD   = False
143
144     # we should use the PIC options in waf instead
145     conf.ADD_CFLAGS('-fPIC', testflags=True)
146
147     # check for pkgconfig
148     conf.check_cfg(atleast_pkgconfig_version='0.0.0')
149
150     conf.DEFINE('_GNU_SOURCE', 1, add_to_cflags=True)
151     conf.DEFINE('_XOPEN_SOURCE_EXTENDED', 1, add_to_cflags=True)
152
153     # get the base headers we'll use for the rest of the tests
154     conf.CHECK_HEADERS('stdio.h sys/types.h sys/stat.h stdlib.h stddef.h memory.h string.h',
155                        add_headers=True)
156     conf.CHECK_HEADERS('strings.h inttypes.h stdint.h unistd.h minix/config.h', add_headers=True)
157     conf.CHECK_HEADERS('ctype.h standards.h stdbool.h stdint.h stdarg.h vararg.h', add_headers=True)
158     conf.CHECK_HEADERS('limits.h assert.h')
159
160     # see if we need special largefile flags
161     conf.CHECK_LARGEFILE()
162
163     if 'HAVE_STDDEF_H' in conf.env and 'HAVE_STDLIB_H' in conf.env:
164         conf.DEFINE('STDC_HEADERS', 1)
165
166     conf.CHECK_HEADERS('sys/time.h time.h', together=True)
167
168     if 'HAVE_SYS_TIME_H' in conf.env and 'HAVE_TIME_H' in conf.env:
169         conf.DEFINE('TIME_WITH_SYS_TIME', 1)
170
171     conf.define('SHLIBEXT', "so", quote=True)
172
173     conf.CHECK_CODE('long one = 1; return ((char *)(&one))[0]',
174                     execute=True,
175                     define='WORDS_BIGENDIAN')
176
177     # check if signal() takes a void function
178     if conf.CHECK_CODE('return *(signal (0, 0)) (0) == 1',
179                        define='RETSIGTYPE_INT',
180                        execute=False,
181                        headers='signal.h',
182                        msg='Checking if signal handlers return int'):
183         conf.DEFINE('RETSIGTYPE', 'int')
184     else:
185         conf.DEFINE('RETSIGTYPE', 'void')
186
187     conf.CHECK_VARIABLE('__FUNCTION__', define='HAVE_FUNCTION_MACRO')
188
189     conf.CHECK_CODE('va_list ap1,ap2; va_copy(ap1,ap2)',
190                     define="HAVE_VA_COPY",
191                     msg="Checking for va_copy")
192
193     conf.CHECK_CODE('''
194                     #define eprintf(...) fprintf(stderr, __VA_ARGS__)
195                     eprintf("bla", "bar")
196                     ''', define='HAVE__VA_ARGS__MACRO')
197
198     conf.SAMBA_BUILD_ENV()
199
200
201 def build(bld):
202     bld.SETUP_BUILD_GROUPS()
203     bld.ENFORCE_GROUP_ORDERING()
204     bld.CHECK_PROJECT_RULES()