build: added support for controlling library types
[metze/samba/wip.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=("list of bundled libraries. Can be 'NONE' or 'ALL' [auto]"),
16                    action="store", dest='BUNDLED_LIBS', default='')
17     opt.add_option('--bundled-library-extension',
18                    help=("name extension for bundled libraries [auto]"),
19                    action="store", dest='BUNDLED_EXTENSION', default=None)
20     opt.add_option('--builtin-libraries',
21                    help=("list of libraries to build directly into binaries [none]"),
22                    action="store", dest='BUILTIN_LIBRARIES', default='')
23
24     opt.add_option('--libdir',
25                    help=("object code libraries [PREFIX/lib]"),
26                    action="store", dest='LIBDIR', default='${PREFIX}/lib')
27     opt.add_option('--bindir',
28                    help=("user executables [PREFIX/bin]"),
29                    action="store", dest='BINDIR', default='${PREFIX}/bin')
30     opt.add_option('--sbindir',
31                    help=("system admin executables [PREFIX/sbin]"),
32                    action="store", dest='SBINDIR', default='${PREFIX}/sbin')
33     opt.add_option('--with-modulesdir',
34                    help=("modules directory [PREFIX/modules]"),
35                    action="store", dest='MODULESDIR', default='${PREFIX}/modules')
36     opt.add_option('--disable-shared',
37                    help=("Disable all use of shared libraries"),
38                    action="store_true", dest='disable_shared', default=False)
39     opt.add_option('--disable-rpath',
40                    help=("Disable use of rpath for build binaries"),
41                    action="store_true", dest='disable_rpath_build', default=False)
42     opt.add_option('--disable-rpath-install',
43                    help=("Disable use of rpath for installed binaries"),
44                    action="store_true", dest='disable_rpath_install', default=False)
45     opt.add_option('--enable-developer',
46                    help=("Turn on developer warnings and debugging"),
47                    action="store_true", dest='developer', default=False)
48     opt.add_option('--enable-gccdeps',
49                    help=("Enable use gcc -MD dependency module"),
50                    action="store_true", dest='enable_gccdeps', default=False)
51     opt.add_option('--timestamp-dependencies',
52                    help=("use file timestamps instead of content for build dependencies (BROKEN)"),
53                    action="store_true", dest='timestamp_dependencies', default=False)
54     opt.add_option('-C',
55                    help='enable configure cacheing',
56                    action='store_true', dest='enable_configure_cache')
57     opt.add_option('--pedantic',
58                    help=("Enable even more compiler warnings"),
59                    action='store_true', dest='pedantic', default=False)
60
61 @wafsamba.runonce
62 def configure(conf):
63     conf.env.hlist = []
64     conf.env.srcdir = conf.srcdir
65
66     if Options.options.timestamp_dependencies:
67         conf.ENABLE_TIMESTAMP_DEPENDENCIES()
68
69     conf.SETUP_CONFIGURE_CACHE(Options.options.enable_configure_cache)
70
71     # load our local waf extensions
72     conf.check_tool('gnu_dirs')
73     conf.check_tool('wafsamba')
74
75     conf.CHECK_CC_ENV()
76
77     conf.check_tool('compiler_cc')
78
79     if Options.options.enable_gccdeps:
80         # don't enable gccdeps by default as it needs a very recent version gcc
81         conf.check_tool('gccdeps', tooldir=conf.srcdir + "/buildtools/wafsamba")
82
83     # make the install paths available in environment
84     conf.env.LIBDIR = Options.options.LIBDIR
85     conf.env.BINDIR = Options.options.BINDIR
86     conf.env.SBINDIR = Options.options.SBINDIR
87     conf.env.MODULESDIR = Options.options.MODULESDIR
88     conf.env.BUNDLED_LIBS = Options.options.BUNDLED_LIBS.split(',')
89     conf.env.BUILTIN_LIBRARIES = Options.options.BUILTIN_LIBRARIES.split(',')
90
91     conf.env.DISABLE_SHARED = Options.options.disable_shared
92
93     if Options.options.BUNDLED_EXTENSION:
94         conf.env.BUNDLED_EXTENSION = Options.options.BUNDLED_EXTENSION
95
96     # see if we can compile and run a simple C program
97     conf.CHECK_CODE('printf("hello world\\n")',
98                     define='HAVE_SIMPLE_C_PROG',
99                     mandatory=True,
100                     execute=True,
101                     headers='stdio.h',
102                     msg='Checking simple C program')
103
104     # check for rpath
105     if not conf.env.DISABLE_SHARED and conf.CHECK_RPATH_SUPPORT():
106         conf.env.RPATH_ON_BUILD   = not Options.options.disable_rpath_build
107         conf.env.RPATH_ON_INSTALL = (conf.env.RPATH_ON_BUILD and
108                                      not Options.options.disable_rpath_install)
109     else:
110         conf.env.RPATH_ON_INSTALL = False
111         conf.env.RPATH_ON_BUILD   = False
112
113     # we should use the PIC options in waf instead
114     conf.ADD_CFLAGS('-fPIC')
115
116     # check for pkgconfig
117     conf.check_cfg(atleast_pkgconfig_version='0.0.0')
118
119     conf.DEFINE('_GNU_SOURCE', 1, add_to_cflags=True)
120     conf.DEFINE('_XOPEN_SOURCE_EXTENDED', 1, add_to_cflags=True)
121
122     # get the base headers we'll use for the rest of the tests
123     conf.CHECK_HEADERS('stdio.h sys/types.h sys/stat.h stdlib.h stddef.h memory.h string.h',
124                        add_headers=True)
125     conf.CHECK_HEADERS('strings.h inttypes.h stdint.h unistd.h minix/config.h', add_headers=True)
126     conf.CHECK_HEADERS('ctype.h standards.h stdbool.h stdint.h stdarg.h vararg.h', add_headers=True)
127
128     # see if we need special largefile flags
129     conf.CHECK_LARGEFILE()
130
131     if 'HAVE_STDDEF_H' in conf.env and 'HAVE_STDLIB_H' in conf.env:
132         conf.DEFINE('STDC_HEADERS', 1)
133
134     conf.CHECK_HEADERS('sys/time.h time.h', together=True)
135
136     if 'HAVE_SYS_TIME_H' in conf.env and 'HAVE_TIME_H' in conf.env:
137         conf.DEFINE('TIME_WITH_SYS_TIME', 1)
138
139     conf.define('SHLIBEXT', "so", quote=True)
140
141     conf.CHECK_CODE('long one = 1; return ((char *)(&one))[0]',
142                     execute=True,
143                     define='WORDS_BIGENDIAN')
144
145     # check if signal() takes a void function
146     if conf.CHECK_CODE('return *(signal (0, 0)) (0) == 1',
147                        define='RETSIGTYPE_INT',
148                        execute=False,
149                        headers='signal.h',
150                        msg='Checking if signal handlers return int'):
151         conf.DEFINE('RETSIGTYPE', 'int')
152     else:
153         conf.DEFINE('RETSIGTYPE', 'void')
154
155     conf.CHECK_VARIABLE('__FUNCTION__', define='HAVE_FUNCTION_MACRO')
156
157     conf.CHECK_CODE('va_list ap1,ap2; va_copy(ap1,ap2)',
158                     define="HAVE_VA_COPY",
159                     msg="Checking for va_copy")
160
161     conf.CHECK_CODE('''
162                     #define eprintf(...) fprintf(stderr, __VA_ARGS__)
163                     eprintf("bla", "bar")
164                     ''', define='HAVE__VA_ARGS__MACRO')
165
166     conf.SAMBA_BUILD_ENV()
167
168
169 def build(bld):
170     bld.SETUP_BUILD_GROUPS()
171     bld.ENFORCE_GROUP_ORDERING()
172     bld.CHECK_PROJECT_RULES()