SCsub 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. #!/usr/bin/env python
  2. Import('env')
  3. env.editor_sources = []
  4. import os
  5. from compat import encode_utf8, byte_to_str, open_utf8, escape_string
  6. def make_certs_header(target, source, env):
  7. src = source[0].srcnode().abspath
  8. dst = target[0].srcnode().abspath
  9. f = open(src, "rb")
  10. g = open_utf8(dst, "w")
  11. buf = f.read()
  12. decomp_size = len(buf)
  13. import zlib
  14. buf = zlib.compress(buf)
  15. g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
  16. g.write("#ifndef _CERTS_RAW_H\n")
  17. g.write("#define _CERTS_RAW_H\n")
  18. g.write("static const int _certs_compressed_size=" + str(len(buf)) + ";\n")
  19. g.write("static const int _certs_uncompressed_size=" + str(decomp_size) + ";\n")
  20. g.write("static const unsigned char _certs_compressed[]={\n")
  21. for i in range(len(buf)):
  22. g.write(byte_to_str(buf[i]) + ",\n")
  23. g.write("};\n")
  24. g.write("#endif")
  25. def make_doc_header(target, source, env):
  26. dst = target[0].srcnode().abspath
  27. g = open_utf8(dst, "w")
  28. buf = ""
  29. docbegin = ""
  30. docend = ""
  31. for s in source:
  32. src = s.srcnode().abspath
  33. if not src.endswith(".xml"):
  34. continue
  35. f = open_utf8(src, "r")
  36. content = f.read()
  37. buf+=content
  38. buf = encode_utf8(docbegin + buf + docend)
  39. decomp_size = len(buf)
  40. import zlib
  41. buf = zlib.compress(buf)
  42. g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
  43. g.write("#ifndef _DOC_DATA_RAW_H\n")
  44. g.write("#define _DOC_DATA_RAW_H\n")
  45. g.write("static const int _doc_data_compressed_size=" + str(len(buf)) + ";\n")
  46. g.write("static const int _doc_data_uncompressed_size=" + str(decomp_size) + ";\n")
  47. g.write("static const unsigned char _doc_data_compressed[]={\n")
  48. for i in range(len(buf)):
  49. g.write(byte_to_str(buf[i]) + ",\n")
  50. g.write("};\n")
  51. g.write("#endif")
  52. def make_fonts_header(target, source, env):
  53. dst = target[0].srcnode().abspath
  54. g = open_utf8(dst, "w")
  55. g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
  56. g.write("#ifndef _EDITOR_FONTS_H\n")
  57. g.write("#define _EDITOR_FONTS_H\n")
  58. # saving uncompressed, since freetype will reference from memory pointer
  59. xl_names = []
  60. for i in range(len(source)):
  61. f = open(source[i].srcnode().abspath, "rb")
  62. buf = f.read()
  63. import os.path
  64. name = os.path.splitext(os.path.basename(source[i].srcnode().abspath))[0]
  65. g.write("static const int _font_" + name + "_size=" + str(len(buf)) + ";\n")
  66. g.write("static const unsigned char _font_" + name + "[]={\n")
  67. for i in range(len(buf)):
  68. g.write(byte_to_str(buf[i]) + ",\n")
  69. g.write("};\n")
  70. g.write("#endif")
  71. def make_translations_header(target, source, env):
  72. dst = target[0].srcnode().abspath
  73. g = open_utf8(dst, "w")
  74. g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
  75. g.write("#ifndef _EDITOR_TRANSLATIONS_H\n")
  76. g.write("#define _EDITOR_TRANSLATIONS_H\n")
  77. import zlib
  78. import os.path
  79. paths = [node.srcnode().abspath for node in source]
  80. sorted_paths = sorted(paths, key=lambda path: os.path.splitext(os.path.basename(path))[0])
  81. xl_names = []
  82. for i in range(len(sorted_paths)):
  83. f = open(sorted_paths[i], "rb")
  84. buf = f.read()
  85. decomp_size = len(buf)
  86. buf = zlib.compress(buf)
  87. name = os.path.splitext(os.path.basename(sorted_paths[i]))[0]
  88. #g.write("static const int _translation_"+name+"_compressed_size="+str(len(buf))+";\n")
  89. #g.write("static const int _translation_"+name+"_uncompressed_size="+str(decomp_size)+";\n")
  90. g.write("static const unsigned char _translation_" + name + "_compressed[]={\n")
  91. for i in range(len(buf)):
  92. g.write(byte_to_str(buf[i]) + ",\n")
  93. g.write("};\n")
  94. xl_names.append([name, len(buf), str(decomp_size)])
  95. g.write("struct EditorTranslationList {\n")
  96. g.write("\tconst char* lang;\n")
  97. g.write("\tint comp_size;\n")
  98. g.write("\tint uncomp_size;\n")
  99. g.write("\tconst unsigned char* data;\n")
  100. g.write("};\n\n")
  101. g.write("static EditorTranslationList _editor_translations[]={\n")
  102. for x in xl_names:
  103. g.write("\t{ \"" + x[0] + "\", " + str(x[1]) + ", " + str(x[2]) + ",_translation_" + x[0] + "_compressed},\n")
  104. g.write("\t{NULL,0,0,NULL}\n")
  105. g.write("};\n")
  106. g.write("#endif")
  107. def make_authors_header(target, source, env):
  108. sections = ["Project Founders", "Lead Developer", "Project Manager", "Developers"]
  109. sections_id = ["dev_founders", "dev_lead", "dev_manager", "dev_names"]
  110. src = source[0].srcnode().abspath
  111. dst = target[0].srcnode().abspath
  112. f = open_utf8(src, "r")
  113. g = open_utf8(dst, "w")
  114. g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
  115. g.write("#ifndef _EDITOR_AUTHORS_H\n")
  116. g.write("#define _EDITOR_AUTHORS_H\n")
  117. current_section = ""
  118. reading = False
  119. def close_section():
  120. g.write("\t0\n")
  121. g.write("};\n")
  122. for line in f:
  123. if reading:
  124. if line.startswith(" "):
  125. g.write("\t\"" + escape_string(line.strip()) + "\",\n")
  126. continue
  127. if line.startswith("## "):
  128. if reading:
  129. close_section()
  130. reading = False
  131. for i in range(len(sections)):
  132. if line.strip().endswith(sections[i]):
  133. current_section = escape_string(sections_id[i])
  134. reading = True
  135. g.write("static const char *" + current_section + "[] = {\n")
  136. break
  137. if reading:
  138. close_section()
  139. g.write("#endif\n")
  140. def make_donors_header(target, source, env):
  141. sections = ["Platinum sponsors", "Gold sponsors", "Mini sponsors", "Gold donors", "Silver donors", "Bronze donors"]
  142. sections_id = ["donor_s_plat", "donor_s_gold", "donor_s_mini", "donor_gold", "donor_silver", "donor_bronze"]
  143. src = source[0].srcnode().abspath
  144. dst = target[0].srcnode().abspath
  145. f = open_utf8(src, "r")
  146. g = open_utf8(dst, "w")
  147. g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
  148. g.write("#ifndef _EDITOR_DONORS_H\n")
  149. g.write("#define _EDITOR_DONORS_H\n")
  150. current_section = ""
  151. reading = False
  152. def close_section():
  153. g.write("\t0\n")
  154. g.write("};\n")
  155. for line in f:
  156. if reading >= 0:
  157. if line.startswith(" "):
  158. g.write("\t\"" + escape_string(line.strip()) + "\",\n")
  159. continue
  160. if line.startswith("## "):
  161. if reading:
  162. close_section()
  163. reading = False
  164. for i in range(len(sections)):
  165. if line.strip().endswith(sections[i]):
  166. current_section = escape_string(sections_id[i])
  167. reading = True
  168. g.write("static const char *" + current_section + "[] = {\n")
  169. break
  170. if reading:
  171. close_section()
  172. g.write("#endif\n")
  173. def make_license_header(target, source, env):
  174. src_copyright = source[0].srcnode().abspath
  175. src_license = source[1].srcnode().abspath
  176. dst = target[0].srcnode().abspath
  177. f = open_utf8(src_license, "r")
  178. fc = open_utf8(src_copyright, "r")
  179. g = open_utf8(dst, "w")
  180. g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
  181. g.write("#ifndef _EDITOR_LICENSE_H\n")
  182. g.write("#define _EDITOR_LICENSE_H\n")
  183. g.write("static const char *about_license =")
  184. for line in f:
  185. escaped_string = escape_string(line.strip())
  186. g.write("\n\t\"" + escaped_string + "\\n\"")
  187. g.write(";\n")
  188. tp_current = 0
  189. tp_file = ""
  190. tp_comment = ""
  191. tp_copyright = ""
  192. tp_license = ""
  193. tp_licensename = ""
  194. tp_licensebody = ""
  195. tp = []
  196. tp_licensetext = []
  197. for line in fc:
  198. if line.startswith("#"):
  199. continue
  200. if line.startswith("Files:"):
  201. tp_file = line[6:].strip()
  202. tp_current = 1
  203. elif line.startswith("Comment:"):
  204. tp_comment = line[8:].strip()
  205. tp_current = 2
  206. elif line.startswith("Copyright:"):
  207. tp_copyright = line[10:].strip()
  208. tp_current = 3
  209. elif line.startswith("License:"):
  210. if tp_current != 0:
  211. tp_license = line[8:].strip()
  212. tp_current = 4
  213. else:
  214. tp_licensename = line[8:].strip()
  215. tp_current = 5
  216. elif line.startswith(" "):
  217. if tp_current == 1:
  218. tp_file += "\n" + line.strip()
  219. elif tp_current == 3:
  220. tp_copyright += "\n" + line.strip()
  221. elif tp_current == 5:
  222. if line.strip() == ".":
  223. tp_licensebody += "\n"
  224. else:
  225. tp_licensebody += line[1:]
  226. else:
  227. if tp_current != 0:
  228. if tp_current == 5:
  229. tp_licensetext.append([tp_licensename, tp_licensebody])
  230. tp_licensename = ""
  231. tp_licensebody = ""
  232. else:
  233. added = False
  234. for i in tp:
  235. if i[0] == tp_comment:
  236. i[1].append([tp_file, tp_copyright, tp_license])
  237. added = True
  238. break
  239. if not added:
  240. tp.append([tp_comment,[[tp_file, tp_copyright, tp_license]]])
  241. tp_file = []
  242. tp_comment = ""
  243. tp_copyright = []
  244. tp_license = ""
  245. tp_current = 0
  246. tp_licensetext.append([tp_licensename, tp_licensebody])
  247. about_thirdparty = ""
  248. about_tp_copyright_count = ""
  249. about_tp_license = ""
  250. about_tp_copyright = ""
  251. about_tp_file = ""
  252. for i in tp:
  253. about_thirdparty += "\t\"" + i[0] + "\",\n"
  254. about_tp_copyright_count += str(len(i[1])) + ", "
  255. for j in i[1]:
  256. file_body = ""
  257. copyright_body = ""
  258. for k in j[0].split("\n"):
  259. if file_body != "":
  260. file_body += "\\n\"\n"
  261. escaped_string = escape_string(k.strip())
  262. file_body += "\t\"" + escaped_string
  263. for k in j[1].split("\n"):
  264. if copyright_body != "":
  265. copyright_body += "\\n\"\n"
  266. escaped_string = escape_string(k.strip())
  267. copyright_body += "\t\"" + escaped_string
  268. about_tp_file += "\t" + file_body + "\",\n"
  269. about_tp_copyright += "\t" + copyright_body + "\",\n"
  270. about_tp_license += "\t\"" + j[2] + "\",\n"
  271. about_license_name = ""
  272. about_license_body = ""
  273. for i in tp_licensetext:
  274. body = ""
  275. for j in i[1].split("\n"):
  276. if body != "":
  277. body += "\\n\"\n"
  278. escaped_string = escape_string(j.strip())
  279. body += "\t\"" + escaped_string
  280. about_license_name += "\t\"" + i[0] + "\",\n"
  281. about_license_body += "\t" + body + "\",\n"
  282. g.write("static const char *about_thirdparty[] = {\n")
  283. g.write(about_thirdparty)
  284. g.write("\t0\n")
  285. g.write("};\n")
  286. g.write("#define THIRDPARTY_COUNT " + str(len(tp)) + "\n")
  287. g.write("static const int about_tp_copyright_count[] = {\n\t")
  288. g.write(about_tp_copyright_count)
  289. g.write("0\n};\n")
  290. g.write("static const char *about_tp_file[] = {\n")
  291. g.write(about_tp_file)
  292. g.write("\t0\n")
  293. g.write("};\n")
  294. g.write("static const char *about_tp_copyright[] = {\n")
  295. g.write(about_tp_copyright)
  296. g.write("\t0\n")
  297. g.write("};\n")
  298. g.write("static const char *about_tp_license[] = {\n")
  299. g.write(about_tp_license)
  300. g.write("\t0\n")
  301. g.write("};\n")
  302. g.write("static const char *about_license_name[] = {\n")
  303. g.write(about_license_name)
  304. g.write("\t0\n")
  305. g.write("};\n")
  306. g.write("#define LICENSE_COUNT " + str(len(tp_licensetext)) + "\n")
  307. g.write("static const char *about_license_body[] = {\n")
  308. g.write(about_license_body)
  309. g.write("\t0\n")
  310. g.write("};\n")
  311. g.write("#endif\n")
  312. def _make_doc_data_class_path(to_path):
  313. g = open_utf8(os.path.join(to_path,"doc_data_class_path.gen.h"), "w")
  314. g.write("static const int _doc_data_class_path_count="+str(len(env.doc_class_path))+";\n")
  315. g.write("struct _DocDataClassPath { const char* name; const char* path; };\n")
  316. g.write("static const _DocDataClassPath _doc_data_class_paths["+str(len(env.doc_class_path)+1)+"]={\n");
  317. for c in env.doc_class_path:
  318. g.write("{\""+c+"\",\""+env.doc_class_path[c]+"\"},\n")
  319. g.write("{NULL,NULL}\n")
  320. g.write("};\n")
  321. if env['tools']:
  322. # Register exporters
  323. reg_exporters_inc = '#include "register_exporters.h"\n'
  324. reg_exporters = 'void register_exporters() {\n'
  325. for e in env.platform_exporters:
  326. env.editor_sources.append("#platform/" + e + "/export/export.cpp")
  327. reg_exporters += '\tregister_' + e + '_exporter();\n'
  328. reg_exporters_inc += '#include "platform/' + e + '/export/export.h"\n'
  329. reg_exporters += '}\n'
  330. f = open_utf8("register_exporters.gen.cpp", "w")
  331. f.write(reg_exporters_inc)
  332. f.write(reg_exporters)
  333. f.close()
  334. # API documentation
  335. docs = []
  336. for f in os.listdir(os.path.join(env.Dir('#').abspath, "doc/classes")):
  337. docs.append("#doc/classes/" + f)
  338. _make_doc_data_class_path(os.path.join(env.Dir('#').abspath, "editor/doc"))
  339. env.Depends("#editor/doc_data_compressed.gen.h", docs)
  340. env.Command("#editor/doc_data_compressed.gen.h", docs, make_doc_header)
  341. # Certificates
  342. env.Depends("#editor/certs_compressed.gen.h", "#thirdparty/certs/ca-certificates.crt")
  343. env.Command("#editor/certs_compressed.gen.h", "#thirdparty/certs/ca-certificates.crt", make_certs_header)
  344. import glob
  345. path = env.Dir('.').abspath
  346. # Translations
  347. tlist = glob.glob(path + "/translations/*.po")
  348. env.Depends('#editor/translations.gen.h', tlist)
  349. env.Command('#editor/translations.gen.h', tlist, make_translations_header)
  350. # Fonts
  351. flist = glob.glob(path + "/../thirdparty/fonts/*.ttf")
  352. flist.append(glob.glob(path + "/../thirdparty/fonts/*.otf"))
  353. env.Depends('#editor/builtin_fonts.gen.h', flist)
  354. env.Command('#editor/builtin_fonts.gen.h', flist, make_fonts_header)
  355. # Authors
  356. env.Depends('#editor/authors.gen.h', "../AUTHORS.md")
  357. env.Command('#editor/authors.gen.h', "../AUTHORS.md", make_authors_header)
  358. # Donors
  359. env.Depends('#editor/donors.gen.h', "../DONORS.md")
  360. env.Command('#editor/donors.gen.h', "../DONORS.md", make_donors_header)
  361. # License
  362. env.Depends('#editor/license.gen.h', ["../COPYRIGHT.txt", "../LICENSE.txt"])
  363. env.Command('#editor/license.gen.h', ["../COPYRIGHT.txt", "../LICENSE.txt"], make_license_header)
  364. env.add_source_files(env.editor_sources, "*.cpp")
  365. SConscript('collada/SCsub')
  366. SConscript('doc/SCsub')
  367. SConscript('fileserver/SCsub')
  368. SConscript('icons/SCsub')
  369. SConscript('import/SCsub')
  370. SConscript('plugins/SCsub')
  371. lib = env.Library("editor", env.editor_sources)
  372. env.Prepend(LIBS=[lib])
  373. Export('env')