PageRenderTime 59ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/buildtools/wafsamba/samba_patterns.py

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