s3: drop build_env
[samba.git] / buildtools / wafsamba / samba_patterns.py
1 # a waf tool to add extension based build patterns for Samba
2
3 import Build
4 from wafsamba import samba_version_file
5
6 def write_version_header(task):
7     '''print version.h contents'''
8     src = task.inputs[0].srcpath(task.env)
9
10     version = samba_version_file(src, task.env.srcdir, env=task.env, is_install=task.generator.bld.is_install)
11     string = str(version)
12
13     task.outputs[0].write(string)
14     return 0
15
16
17 def SAMBA_MKVERSION(bld, target, source='VERSION'):
18     '''generate the version.h header for Samba'''
19
20     # We only force waf to re-generate this file if we are installing,
21     # because only then is information not included in the deps (the
22     # git revision) included in the version.
23     t = bld.SAMBA_GENERATOR('VERSION',
24                             rule=write_version_header,
25                             source=source,
26                             target=target,
27                             always=bld.is_install)
28 Build.BuildContext.SAMBA_MKVERSION = SAMBA_MKVERSION
29
30
31 def write_build_options_header(fp):
32     '''write preamble for build_options.c'''
33     fp.write("/*\n")
34     fp.write("   Unix SMB/CIFS implementation.\n")
35     fp.write("   Build Options for Samba Suite\n")
36     fp.write("   Copyright (C) Vance Lankhaar <vlankhaar@linux.ca> 2003\n")
37     fp.write("   Copyright (C) Andrew Bartlett <abartlet@samba.org> 2001\n")
38     fp.write("\n")
39     fp.write("   This program is free software; you can redistribute it and/or modify\n")
40     fp.write("   it under the terms of the GNU General Public License as published by\n")
41     fp.write("   the Free Software Foundation; either version 3 of the License, or\n")
42     fp.write("   (at your option) any later version.\n")
43     fp.write("\n")
44     fp.write("   This program is distributed in the hope that it will be useful,\n")
45     fp.write("   but WITHOUT ANY WARRANTY; without even the implied warranty of\n")
46     fp.write("   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n")
47     fp.write("   GNU General Public License for more details.\n")
48     fp.write("\n")
49     fp.write("   You should have received a copy of the GNU General Public License\n")
50     fp.write("   along with this program; if not, see <http://www.gnu.org/licenses/>.\n")
51     fp.write("*/\n")
52     fp.write("\n")
53     fp.write("#include \"includes.h\"\n")
54     fp.write("#include \"dynconfig/dynconfig.h\"\n")
55     fp.write("#include \"lib/cluster_support.h\"\n")
56
57     fp.write("\n")
58     fp.write("static int output(bool screen, const char *format, ...) PRINTF_ATTRIBUTE(2,3);\n")
59     fp.write("void build_options(bool screen);\n")
60     fp.write("\n")
61     fp.write("\n")
62     fp.write("/****************************************************************************\n")
63     fp.write("helper function for build_options\n")
64     fp.write("****************************************************************************/\n")
65     fp.write("static int output(bool screen, const char *format, ...)\n")
66     fp.write("{\n")
67     fp.write("       char *ptr = NULL;\n")
68     fp.write("       int ret = 0;\n")
69     fp.write("       va_list ap;\n")
70     fp.write("       \n")
71     fp.write("       va_start(ap, format);\n")
72     fp.write("       ret = vasprintf(&ptr,format,ap);\n")
73     fp.write("       va_end(ap);\n")
74     fp.write("\n")
75     fp.write("       if (screen) {\n")
76     fp.write("              d_printf(\"%s\", ptr ? ptr : \"\");\n")
77     fp.write("       } else {\n")
78     fp.write("              DEBUG(4,(\"%s\", ptr ? ptr : \"\"));\n")
79     fp.write("       }\n")
80     fp.write("       \n")
81     fp.write("       SAFE_FREE(ptr);\n")
82     fp.write("       return ret;\n")
83     fp.write("}\n")
84     fp.write("\n")
85     fp.write("/****************************************************************************\n")
86     fp.write("options set at build time for the samba suite\n")
87     fp.write("****************************************************************************/\n")
88     fp.write("void build_options(bool screen)\n")
89     fp.write("{\n")
90     fp.write("       if ((DEBUGLEVEL < 4) && (!screen)) {\n")
91     fp.write("              return;\n")
92     fp.write("       }\n")
93     fp.write("\n")
94     fp.write("\n")
95     fp.write("       /* Output various paths to files and directories */\n")
96     fp.write("       output(screen,\"\\nPaths:\\n\");\n")
97     fp.write("       output(screen,\"   SBINDIR: %s\\n\", get_dyn_SBINDIR());\n")
98     fp.write("       output(screen,\"   BINDIR: %s\\n\", get_dyn_BINDIR());\n")
99     fp.write("       output(screen,\"   CONFIGFILE: %s\\n\", get_dyn_CONFIGFILE());\n")
100     fp.write("       output(screen,\"   LOGFILEBASE: %s\\n\", get_dyn_LOGFILEBASE());\n")
101     fp.write("       output(screen,\"   LMHOSTSFILE: %s\\n\",get_dyn_LMHOSTSFILE());\n")
102     fp.write("       output(screen,\"   LIBDIR: %s\\n\",get_dyn_LIBDIR());\n")
103     fp.write("       output(screen,\"   MODULESDIR: %s\\n\",get_dyn_MODULESDIR());\n")
104     fp.write("       output(screen,\"   SHLIBEXT: %s\\n\",get_dyn_SHLIBEXT());\n")
105     fp.write("       output(screen,\"   LOCKDIR: %s\\n\",get_dyn_LOCKDIR());\n")
106     fp.write("       output(screen,\"   STATEDIR: %s\\n\",get_dyn_STATEDIR());\n")
107     fp.write("       output(screen,\"   CACHEDIR: %s\\n\",get_dyn_CACHEDIR());\n")
108     fp.write("       output(screen,\"   PIDDIR: %s\\n\", get_dyn_PIDDIR());\n")
109     fp.write("       output(screen,\"   SMB_PASSWD_FILE: %s\\n\",get_dyn_SMB_PASSWD_FILE());\n")
110     fp.write("       output(screen,\"   PRIVATE_DIR: %s\\n\",get_dyn_PRIVATE_DIR());\n")
111     fp.write("\n")
112
113 def write_build_options_footer(fp):
114     fp.write("       /* Output the sizes of the various cluster features */\n")
115     fp.write("       output(screen, \"\\n%s\", cluster_support_features());\n")
116     fp.write("\n")
117     fp.write("       /* Output the sizes of the various types */\n")
118     fp.write("       output(screen, \"\\nType sizes:\\n\");\n")
119     fp.write("       output(screen, \"   sizeof(char):         %lu\\n\",(unsigned long)sizeof(char));\n")
120     fp.write("       output(screen, \"   sizeof(int):          %lu\\n\",(unsigned long)sizeof(int));\n")
121     fp.write("       output(screen, \"   sizeof(long):         %lu\\n\",(unsigned long)sizeof(long));\n")
122     fp.write("       output(screen, \"   sizeof(long long):    %lu\\n\",(unsigned long)sizeof(long long));\n")
123     fp.write("       output(screen, \"   sizeof(uint8_t):      %lu\\n\",(unsigned long)sizeof(uint8_t));\n")
124     fp.write("       output(screen, \"   sizeof(uint16_t):     %lu\\n\",(unsigned long)sizeof(uint16_t));\n")
125     fp.write("       output(screen, \"   sizeof(uint32_t):     %lu\\n\",(unsigned long)sizeof(uint32_t));\n")
126     fp.write("       output(screen, \"   sizeof(short):        %lu\\n\",(unsigned long)sizeof(short));\n")
127     fp.write("       output(screen, \"   sizeof(void*):        %lu\\n\",(unsigned long)sizeof(void*));\n")
128     fp.write("       output(screen, \"   sizeof(size_t):       %lu\\n\",(unsigned long)sizeof(size_t));\n")
129     fp.write("       output(screen, \"   sizeof(off_t):        %lu\\n\",(unsigned long)sizeof(off_t));\n")
130     fp.write("       output(screen, \"   sizeof(ino_t):        %lu\\n\",(unsigned long)sizeof(ino_t));\n")
131     fp.write("       output(screen, \"   sizeof(dev_t):        %lu\\n\",(unsigned long)sizeof(dev_t));\n")
132     fp.write("\n")
133     fp.write("       output(screen, \"\\nBuiltin modules:\\n\");\n")
134     fp.write("       output(screen, \"   %s\\n\", STRING_STATIC_MODULES);\n")
135     fp.write("}\n")
136
137 def write_build_options_section(fp, keys, section):
138     fp.write("\n\t/* Show %s */\n" % section)
139     fp.write("       output(screen, \"\\n%s:\\n\");\n\n" % section)
140
141     for k in sorted(keys):
142         fp.write("#ifdef %s\n" % k)
143         fp.write("       output(screen, \"   %s\\n\");\n" % k)
144         fp.write("#endif\n")
145     fp.write("\n")
146
147 def write_build_options(task):
148     tbl = task.env['defines']
149     keys_option_with = []
150     keys_option_utmp = []
151     keys_option_have = []
152     keys_header_sys = []
153     keys_header_other = []
154     keys_misc = []
155     for key in tbl:
156         if key.startswith("HAVE_UT_UT_") or key.find("UTMP") >= 0:
157             keys_option_utmp.append(key)
158         elif key.startswith("WITH_"):
159             keys_option_with.append(key)
160         elif key.startswith("HAVE_SYS_"):
161             keys_header_sys.append(key)
162         elif key.startswith("HAVE_"):
163             if key.endswith("_H"):
164                 keys_header_other.append(key)
165             else:
166                 keys_option_have.append(key)
167         elif key.startswith("static_init_"):
168             l = key.split("(")
169             keys_misc.append(l[0])
170         else:
171             keys_misc.append(key)
172
173     tgt = task.outputs[0].bldpath(task.env)
174     f = open(tgt, 'w')
175     write_build_options_header(f)
176     write_build_options_section(f, keys_header_sys, "System Headers")
177     write_build_options_section(f, keys_header_other, "Headers")
178     write_build_options_section(f, keys_option_utmp, "UTMP Options")
179     write_build_options_section(f, keys_option_have, "HAVE_* Defines")
180     write_build_options_section(f, keys_option_with, "--with Options")
181     write_build_options_section(f, keys_misc, "Build Options")
182     write_build_options_footer(f)
183     f.close()
184     return 0
185
186
187 def SAMBA_BLDOPTIONS(bld, target):
188     '''generate the bld_options.c for Samba'''
189     t = bld.SAMBA_GENERATOR(target,
190                             rule=write_build_options,
191                             dep_vars=['defines'],
192                             target=target)
193 Build.BuildContext.SAMBA_BLDOPTIONS = SAMBA_BLDOPTIONS