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