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