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