distcheck.lua 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. -- This LUA script losely mimics the 'make distcheck' used on Linux
  2. -- to build a source code package. In many ways it's quite different,
  3. -- though. It expects all tools as ready-made executables and instead
  4. -- builds Nut/OS binaries for all supported targets.
  5. --
  6. -- The result will be an executable Windows installation file. Any
  7. -- build errors are logged in the ERROR_LOG.
  8. --
  9. -- The script works on my machine and requires a number of external
  10. -- software, like NSIS, Doxygen, AVR and ARM compilers etc. It may
  11. -- not work for you.
  12. --
  13. -- Written by Harald Kipp
  14. --
  15. -- I'm a lousy LUA programmer and will be happy to receive your
  16. -- suggestions and comments.
  17. --
  18. -- Released to the Public Domain
  19. --
  20. require("lfs")
  21. PKG_VERSION = "5.2.1"
  22. ARC_NAME = "ethernut-"..PKG_VERSION
  23. TOP_DIR = "."
  24. PS = "\\"
  25. SRC_DIR = TOP_DIR..PS.."nut-trunk"
  26. WORK_DIR = TOP_DIR..PS..ARC_NAME
  27. REDIR = " >>build.log 2>&1"
  28. ERROR_LOG = "errors-"..PKG_VERSION..".log"
  29. BASE_PATH = "e:\\apps\\bin;%SystemRoot%\\system32;%SystemRoot%;%SystemRoot%\\System32\\Wbem;"
  30. TOOL_PATH = "e:\\ethernut\\nut-trunk\\nut\\tools\\win32;"
  31. -- GCCAVR_PATH = "C:\\Program Files (x86)\\MHV AVR Tools\\bin;"
  32. GCCAVR_PATH = "e:\\WinAVR\\bin;e:\\WinAVR\\utils\\bin;"
  33. -- GCCAVR_PATH = "E:\\AVRToolchain\\bin;"
  34. -- GCCAVR32_PATH = "%ProgramFiles(x86)%\\Atmel\\AVR Tools\\AVR32 Toolchain\\bin;"
  35. GCCAVR32_PATH = "E:\\AVRToolchain\\bin;"
  36. GCCARM_PATH = "%ProgramFiles(x86)%\\GNU Tools ARM Embedded\\4.7 2013q2\\bin;"
  37. -- GCCARM_PATH = "e:\\yagarto\\bin;"
  38. -- GCCARM_PATH = "%ProgramFiles(x86)%\\yagarto\\bin;"
  39. -- GCCARM_PATH = "E:\\ARMGCCToolchain\\bin;"
  40. ICCAVR7_PATH = "e:\\iccv719avr\\bin;"
  41. NSIS_PATH = "%ProgramFiles(x86)%\\NSIS;"
  42. DOXY_PATH = "C:\\Program Files\\doxygen\\bin;%ProgramFiles(x86)%\\Graphviz2.27\\bin;%ProgramFiles(x86)%\\HTML Help Workshop;"
  43. avr_targets = {
  44. { name = "arthernet1", mcu = "atmega128" },
  45. { name = "charon2", mcu = "atmega128" },
  46. { name = "ethernut103", mcu = "atmega103" },
  47. { name = "ethernut13f", mcu = "atmega128" },
  48. { name = "ethernut13g", mcu = "atmega128" },
  49. { name = "ethernut13h", mcu = "atmega128" },
  50. { name = "ethernut13h-256gcc", mcu = "atmega2561" },
  51. { name = "ethernut20a", mcu = "atmega128" },
  52. { name = "ethernut21b", mcu = "atmega128" },
  53. { name = "ethernut21b-256gcc", mcu = "atmega2561" },
  54. { name = "mmnet01", mcu = "atmega128" },
  55. { name = "mmnet02_03_04", mcu = "atmega128" },
  56. { name = "mmnet101", mcu = "atmega128" },
  57. { name = "mmnet102_103_104", mcu = "atmega128" },
  58. { name = "stk501", mcu = "atmega128" },
  59. { name = "xnut-100", mcu = "atmega128" },
  60. { name = "xnut-105c", mcu = "at90can128" },
  61. { name = "xnut-105d", mcu = "at90can128" },
  62. }
  63. avr32_targets = {
  64. { name = "evk1100-extram", mcu = "uc3a0512" },
  65. { name = "evk1100-intram", mcu = "uc3a0512" },
  66. { name = "evk1101", mcu = "uc3b0256" },
  67. { name = "evk1104-extram", mcu = "uc3a3256" },
  68. { name = "evk1104-intram", mcu = "uc3a3256" },
  69. { name = "evk1105-extram", mcu = "uc3a0512" },
  70. { name = "evk1105-intram", mcu = "uc3a0512" }
  71. }
  72. arm_targets = {
  73. { name = "at91eb40a", mcu = "arm7tdmi" },
  74. { name = "at91sam7s", mcu = "arm7tdmi" },
  75. { name = "at91sam7se-ek", mcu = "arm7tdmi" },
  76. { name = "at91sam7x-ek", mcu = "arm7tdmi" },
  77. { name = "at91sam9260-ek", mcu = "arm9" },
  78. { name = "at91sam9g45-ek", mcu = "arm9" },
  79. { name = "eir10c", mcu = "arm7tdmi" },
  80. { name = "enet-sam7x", mcu="arm7tdmi" },
  81. { name = "ethernut30d", mcu = "arm7tdmi" },
  82. { name = "ethernut30e", mcu = "arm7tdmi" },
  83. { name = "ethernut31d", mcu = "arm7tdmi" },
  84. { name = "ethernut50f", mcu = "arm9" },
  85. { name = "gbaxport2", mcu = "arm7tdmi" },
  86. { name = "morphoq11a", mcu = "arm7tdmi" },
  87. { name = "olimex-sam7-ex256", mcu = "arm7tdmi" },
  88. }
  89. thumb_targets = {
  90. }
  91. cortex_targets = {
  92. { name = "flecx10a", mcu = "cortex-m3" },
  93. { name = "ksk-lpc17xx-sk", mcu = "cortex-m3" },
  94. { name = "lisa", mcu = "cortex-m3" },
  95. { name = "mbed_npx_lpc1768", mcu = "cortex-m3" },
  96. { name = "stm32-comStick", mcu = "cortex-m3" },
  97. { name = "stm32_can", mcu = "cortex-m3" },
  98. { name = "stm32_vl_discovery", mcu = "cortex-m3" },
  99. { name = "stm3210c-eval", mcu = "cortex-m3" },
  100. { name = "stm3210e-eval", mcu = "cortex-m3" },
  101. { name = "usps_f107c", mcu = "cortex-m3" },
  102. { name = "usps_f205c", mcu = "cortex-m3" },
  103. { name = "usps_f405g", mcu = "cortex-m4" },
  104. { name = "usps_l151b", mcu = "cortex-m3" },
  105. }
  106. asm_sources = {
  107. { p = ".S$", m = ".S", r = true },
  108. { p = ".s$", m = ".s", r = true },
  109. }
  110. app_specials = {
  111. { p = ".asp$", m = ".asp", r = true },
  112. { p = ".class$", m = ".class", r = true },
  113. { p = ".gif$", m = ".gif", r = true },
  114. { p = ".png$", m = ".png", r = true },
  115. { p = ".html$", m = ".html", r = true },
  116. { p = ".isp$", m = ".isp", r = true },
  117. { p = ".inc$", m = ".inc", r = true },
  118. { p = ".java$", m = ".java", r = true },
  119. { p = ".js$", m = ".js", r = true },
  120. { p = ".mp3$", m = ".mp3", r = true },
  121. { p = ".shtml$", m = ".shtml", r = true },
  122. { p = ".swf$", m = ".swf", r = true },
  123. { p = ".xml$", m = ".xml", r = true },
  124. }
  125. c_sources = {
  126. { p = ".c$", m = ".c", r = true },
  127. { p = ".h$", m = ".h", r = true },
  128. { p = ".txt$", m = ".txt", r = true },
  129. }
  130. boot_specials = {
  131. { p = ".jom$", m = ".jom", r = true },
  132. }
  133. cpp_sources = {
  134. { p = ".cc$", m = ".cc", r = true },
  135. { p = ".cpp$", m = ".cpp", r = true },
  136. { p = ".h$", m = ".h", r = true },
  137. { p = ".hpp$", m = ".hpp", r = true },
  138. { p = ".pri$", m = ".pri", r = true },
  139. { p = ".pro$", m = ".pro", r = true },
  140. { p = ".qrc$", m = ".qrc", r = true },
  141. { p = ".rc$", m = ".rc", r = true },
  142. { p = ".ui$", m = ".ui", r = true },
  143. { p = ".xpm$", m = ".xpm", r = true },
  144. { p = ".bmp$", m = ".bmp", r = true },
  145. { p = ".ico$", m = ".ico", r = true },
  146. { p = ".png$", m = ".png", r = true },
  147. }
  148. doxy_files = {
  149. { p = ".css$", m = ".css", r = true },
  150. { p = ".cfg$", m = ".cfg", r = true },
  151. { p = ".gif$", m = ".gif", r = true },
  152. { p = ".html$", m = ".html", r = true },
  153. { p = ".in$", m = ".in", r = true },
  154. { p = ".txt$", m = ".txt", r = true },
  155. { p = ".odt$", m = ".odt", r = true },
  156. }
  157. make_files = {
  158. { p = "^Makefile.am", m = "Makefile.am", r = false },
  159. { p = "^Makefile", m = "Makefile", r = true },
  160. { p = "^Makedefs", m = "Makedefs", r = true },
  161. { p = "^Makevars", m = "Makevars", r = true },
  162. { p = "^Makerules", m = "Makerules", r = true },
  163. { p = "^Makeburn", m = "Makeburn", r = true },
  164. }
  165. nsis_files = {
  166. { p = ".bmp$", m = ".bmp", r = true },
  167. { p = ".nsi$", m = ".nsi", r = true },
  168. { p = ".txt$", m = ".txt", r = true },
  169. { p = ".ico$", m = ".ico", r = true },
  170. { p = "^ChangeLog", m = "ChangeLog", r = true },
  171. }
  172. icc_projects = {
  173. { p = ".prj$", m = ".prj", r = true },
  174. { p = ".SRC$", m = ".SRC", r = true },
  175. }
  176. top_files = {
  177. { p = "^ChangeLog", m = "ChangeLog", r = true },
  178. { p = "^AUTHORS", m = "AUTHORS", r = true },
  179. { p = "^COPYING", m = "COPYING", r = true },
  180. { p = "^INSTALL", m = "INSTALL", r = true },
  181. { p = "^NEWS", m = "NEWS", r = true },
  182. { p = "^README", m = "README", r = true },
  183. { p = "^nutsetup", m = "nutsetup", r = true },
  184. }
  185. win32_files = {
  186. { p = ".exe$", m = ".exe", r = true },
  187. { p = ".dll$", m = ".dll", r = true },
  188. { p = ".cfg$", m = ".cfg", r = true },
  189. { p = ".conf$", m = ".conf", r = true },
  190. { p = ".ini$", m = ".ini", r = true },
  191. { p = ".bat$", m = ".bat", r = true },
  192. { p = ".sys$", m = ".sys", r = true },
  193. { p = ".jom$", m = ".jom", r = true },
  194. { p = ".tcl$", m = ".tcl", r = true },
  195. { p = ".bin$", m = ".bin", r = true },
  196. { p = ".manifest$", m = ".manifest", r = true },
  197. }
  198. tool_files = {
  199. { p = "^Makefile", m = "Makefile", r = true },
  200. { p = ".script$", m = ".script", r = true },
  201. { p = ".vcxproj$", m = ".vcxproj", r = true },
  202. { p = ".filters$", m = ".filters", r = true },
  203. { p = ".user$", m = ".user", r = true },
  204. { p = ".cfg$", m = ".cfg", r = true },
  205. { p = ".ini$", m = ".ini", r = true },
  206. { p = ".lua$", m = ".lua", r = true },
  207. }
  208. lua_files = {
  209. { p = "^COPYRIGHT", m = "COPYRIGHT", r = true },
  210. { p = "^HISTORY", m = "HISTORY", r = true },
  211. { p = "^INSTALL", m = "INSTALL", r = true },
  212. { p = ".pri$", m = ".pri", r = true },
  213. { p = ".pc$", m = ".pc", r = true },
  214. { p = ".bat$", m = ".bat", r = true },
  215. { p = ".lua$", m = ".lua", r = true },
  216. }
  217. linker_scripts = {
  218. { p = ".ld$", m = ".ld", r = true },
  219. }
  220. config_files = {
  221. { p = ".conf$", m = ".conf", r = true },
  222. { p = ".nut$", m = ".nut", r = true },
  223. }
  224. text_files = {
  225. { p = ".txt$", m = ".txt", r = true },
  226. }
  227. function check_filter(name, filter)
  228. local basename = string.gsub(name, ".+/", "")
  229. for i,v in ipairs(filter) do
  230. for idx,val in ipairs(v) do
  231. if basename:match(val.p) == val.m then
  232. return val.r
  233. end
  234. end
  235. end
  236. return false
  237. end
  238. function copy_files(source, dest, filter)
  239. local attr = lfs.attributes(source);
  240. if attr == nil then
  241. print("Missing "..source)
  242. error(e)
  243. elseif attr.mode == "directory" then
  244. lfs.mkdir(dest)
  245. for child in lfs.dir(source) do
  246. if child ~= "." and child ~= ".." then
  247. copy_files(source.."/"..child, dest.."/"..child, filter)
  248. end
  249. end
  250. elseif check_filter(source, filter) then
  251. local f = io.open(source, "rb")
  252. local data = f:read("*all*")
  253. f:close()
  254. f,e = io.open(dest, "wb")
  255. if e then
  256. print("Failed to open "..dest)
  257. error(e)
  258. end
  259. f:write(data)
  260. f:close()
  261. lfs.touch(dest, attr.access, attr.modification)
  262. end
  263. end
  264. function update_config(filename, key, value)
  265. local replaced = false
  266. local line
  267. local k
  268. local f = io.open(filename)
  269. local data = f:read("*all*")
  270. f:close()
  271. f,e = io.open(filename..".bak", "w")
  272. if e then
  273. print(filename..".bak")
  274. error(e)
  275. end
  276. f:write(data)
  277. f:close()
  278. f = io.open(filename, "w")
  279. for line in io.lines(filename..".bak") do
  280. if string.len(line) > 1 and string.sub(line, 1, 2) ~= "--" then
  281. k = string.match(line, "([%w_]+)");
  282. if replaced == false and k == key then
  283. if value == nil then
  284. line = "-- "..line
  285. else
  286. line = key.." = "..value
  287. end
  288. replaced = true
  289. end
  290. end
  291. f:write(line.."\n")
  292. end
  293. if replaced == false then
  294. f:write(key.." = "..value.."\n")
  295. end
  296. io.close(f)
  297. end
  298. function append_log_tail(f, log, num)
  299. local count = 0
  300. for line in io.lines(log) do
  301. count = count + 1
  302. end
  303. local skip = 0
  304. if count > num then
  305. skip = count - num
  306. end
  307. for line in io.lines(log) do
  308. if skip > 0 then
  309. skip = skip - 1
  310. else
  311. f:write(line)
  312. f:write("\n")
  313. end
  314. end
  315. end
  316. function log_build_error(target, cmd, result)
  317. build_result:write(string.rep("-", 72).."\n")
  318. build_result:write("Target : "..target.."\n")
  319. build_result:write("Command: "..cmd.."\n")
  320. build_result:write("Error : "..result.."\n")
  321. build_result:write(string.rep("-", 72).."\n")
  322. append_log_tail(build_result, "build.log", 10)
  323. build_result:write("\n\n")
  324. build_result:flush()
  325. end
  326. function create_readme(path, content)
  327. local f
  328. local e
  329. f,e = io.open(path..PS.."README", "w")
  330. if e then
  331. print("Failed to create "..path..PS.."README")
  332. else
  333. f:write(content)
  334. f:close()
  335. end
  336. return e
  337. end
  338. function create_target_readme(path, board, platform)
  339. local content
  340. content = "Board : "..board.."\n"
  341. content = content.."Compiler: "..platform.."\n"
  342. return create_readme(path, content)
  343. end
  344. function build_libs(board, platform, path)
  345. print(board..": Building "..platform.." libraries")
  346. local target = board.."-"..platform.."-bld"
  347. local cmd = "..\\nutconfigure.exe -b"..target.." -cnut/conf/"..board..".conf -l"..target.."/lib -m"..platform.." create-buildtree"
  348. local result = os.execute(cmd..REDIR)
  349. if result ~= 0 then
  350. log_build_error(target, cmd, result)
  351. else
  352. lfs.chdir(target)
  353. cmd = "SET PATH="..path.."&make clean all install"
  354. result = os.execute(cmd..REDIR)
  355. if result ~= 0 then
  356. log_build_error(target, cmd, result)
  357. lfs.chdir("..")
  358. else
  359. lfs.chdir("..")
  360. cmd = "xcopy "..target..PS.."lib nut"..PS.."lib"..PS.."boards"..PS..board..PS..platform.."\\ /S /R /Y"
  361. if os.execute(cmd..REDIR) ~= 0 then
  362. log_build_error(target, cmd, result)
  363. end
  364. create_target_readme("nut"..PS.."lib"..PS.."boards"..PS..board..PS..platform, board, platform)
  365. end
  366. end
  367. return result
  368. end
  369. function build_apps(board, mcu, platform, path)
  370. print(board..": Building "..platform.." samples")
  371. local target = board.."-"..platform
  372. local cmd = "..\\nutconfigure.exe -a"..target.."-app -b"..target.."-bld -cnut/conf/"..board..".conf -l"..target.."-bld/lib -m"..platform.." create-apptree"
  373. local result = os.execute(cmd..REDIR)
  374. if result ~= 0 then
  375. log_build_error(target.."-app", cmd, result)
  376. else
  377. os.execute("mkdir nut"..PS.."bin"..PS..mcu..REDIR)
  378. create_readme("nut"..PS.."bin"..PS..mcu, "When running 'make install' binaries for "..mcu.." will be placed in this directory.\n")
  379. os.execute("rmdir /S /Q nut"..PS.."bin"..PS..board..REDIR)
  380. lfs.chdir(target.."-app")
  381. cmd = "SET PATH="..path.."&make clean all install"
  382. result = os.execute(cmd..REDIR)
  383. if result ~= 0 then
  384. log_build_error(target.."-app", cmd, result)
  385. lfs.chdir("..")
  386. else
  387. lfs.chdir("..")
  388. cmd = "xcopy nut"..PS.."bin"..PS..mcu.."\\*.hex nut"..PS.."bin"..PS.."boards"..PS..board..PS..platform.."\\ /S /R /Y"
  389. os.execute(cmd..REDIR)
  390. cmd = "del nut"..PS.."bin"..PS..mcu.."\\*.hex /F /Q"
  391. os.execute(cmd..REDIR)
  392. cmd = "xcopy nut"..PS.."bin"..PS..mcu.."\\*.bin nut"..PS.."bin"..PS.."boards"..PS..board..PS..platform.."\\ /S /R /Y"
  393. os.execute(cmd..REDIR)
  394. cmd = "del nut"..PS.."bin"..PS..mcu.."\\*.bin /F /Q"
  395. os.execute(cmd..REDIR)
  396. create_target_readme("nut"..PS.."bin"..PS.."boards"..PS..board..PS..platform, board, platform)
  397. end
  398. end
  399. return result
  400. end
  401. function build_docs(path)
  402. local f
  403. local e
  404. local line
  405. print("Building dox")
  406. f,e = io.open("chm_en.cfg", "w")
  407. if e then
  408. print("chm_en.cfg")
  409. error(e)
  410. end
  411. for line in io.lines("chm_en.cfg.in") do
  412. line = string.gsub(line, "@PACKAGE_VERSION@", PKG_VERSION)
  413. line = string.gsub(line, "@top_srcdir@", "/ethernut/nut-trunk")
  414. line = string.gsub(line, "@top_builddir@", "/ethernut/ethernut-"..PKG_VERSION)
  415. line = string.gsub(line, "@srcdir@", ".")
  416. f:write(line.."\n")
  417. end
  418. f:close()
  419. f,e = io.open("nut_en.cfg", "w")
  420. if e then
  421. print("nut_en.cfg")
  422. error(e)
  423. end
  424. for line in io.lines("nut_en.cfg.in") do
  425. line = string.gsub(line, "@PACKAGE_VERSION@", PKG_VERSION)
  426. line = string.gsub(line, "@top_srcdir@", "/ethernut/nut-trunk")
  427. line = string.gsub(line, "@top_builddir@", "/ethernut/ethernut-"..PKG_VERSION)
  428. line = string.gsub(line, "@srcdir@", ".")
  429. f:write(line.."\n")
  430. end
  431. f:close()
  432. local cmd = "SET PATH="..path.."&doxygen chm_en.cfg&doxygen nut_en.cfg"
  433. local result = os.execute(cmd..REDIR)
  434. if result ~= 0 then
  435. log_build_error("docs", cmd, result)
  436. end
  437. end
  438. function build_winhelp(path)
  439. print("Building Windows help file")
  440. local cmd = "SET PATH="..path.."&hhc index.hhp"
  441. local result = os.execute(cmd..REDIR)
  442. if result ~= 0 then
  443. log_build_error("winhelp", cmd, result)
  444. end
  445. end
  446. function build_winstaller(path)
  447. print("Building Windows installer")
  448. local cmd = "SET PATH="..path.."&makensis ethernut.nsi"
  449. local result = os.execute(cmd..REDIR)
  450. if result ~= 0 then
  451. log_build_error("wininstaller", cmd, result)
  452. end
  453. end
  454. build_result = io.open(ERROR_LOG, "w")
  455. --
  456. -- Copy all files from source to work directory
  457. --
  458. print("Creating work directory")
  459. copy_files(SRC_DIR, WORK_DIR, { asm_sources, c_sources, cpp_sources, make_files, linker_scripts, top_files } )
  460. copy_files(SRC_DIR..PS.."nut"..PS.."boot", WORK_DIR..PS.."nut"..PS.."boot", { boot_specials } )
  461. copy_files(SRC_DIR..PS.."nut"..PS.."conf", WORK_DIR..PS.."nut"..PS.."conf", { config_files } )
  462. copy_files(SRC_DIR..PS.."nut"..PS.."app", WORK_DIR..PS.."nut"..PS.."app", { app_specials } )
  463. copy_files(SRC_DIR..PS.."nut"..PS.."hwtest", WORK_DIR..PS.."nut"..PS.."hwtest", { app_specials } )
  464. copy_files(SRC_DIR..PS.."nut"..PS.."appicc", WORK_DIR..PS.."nut"..PS.."appicc", { icc_projects } )
  465. copy_files(SRC_DIR..PS.."nut"..PS.."doc", WORK_DIR..PS.."nut"..PS.."doc", { doxy_files } )
  466. copy_files(SRC_DIR..PS.."nut"..PS.."tools"..PS.."packaging"..PS.."nsis", WORK_DIR..PS.."nut"..PS.."tools"..PS.."packaging"..PS.."nsis", { nsis_files } )
  467. copy_files(SRC_DIR..PS.."nut"..PS.."tools", WORK_DIR..PS.."nut"..PS.."tools", { tool_files } )
  468. copy_files(SRC_DIR..PS.."nut"..PS.."tools"..PS.."qnutconf"..PS.."src"..PS.."lua", WORK_DIR..PS.."nut"..PS.."tools"..PS.."qnutconf"..PS.."src"..PS.."lua", { lua_files } )
  469. copy_files(SRC_DIR..PS.."nut"..PS.."tools"..PS.."win32", WORK_DIR..PS.."nut"..PS.."tools"..PS.."win32", { win32_files } )
  470. lfs.chdir(WORK_DIR)
  471. --
  472. -- Build ARM Thumb GCC libs and apps
  473. --
  474. path_env = TOOL_PATH..GCCARM_PATH..BASE_PATH
  475. -- if os.execute("SET PATH="..path_env.."&arm-elf-gcc -v"..REDIR) == 0 then
  476. if os.execute("SET PATH="..path_env.."&arm-none-eabi-gcc -v"..REDIR) == 0 then
  477. for t_index, t_board in ipairs(thumb_targets) do
  478. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_MCD_ST_LIBERTY", '""')
  479. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_ST_GUIDANCE_ONLY", '""')
  480. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_LUMINARY_ANTI_VIRAL", '""')
  481. if build_libs(t_board.name, "arm-thumb-gcc", path_env) == 0 then
  482. build_apps(t_board.name, t_board.mcu, "arm-thumb-gcc", path_env)
  483. end
  484. if build_libs(t_board.name, "arm-thumb-gccdbg", path_env) == 0 then
  485. build_apps(t_board.name, t_board.mcu, "arm-thumb-gccdbg", path_env)
  486. end
  487. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_MCD_ST_LIBERTY", nil)
  488. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_ST_GUIDANCE_ONLY", nil)
  489. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_LUMINARY_ANTI_VIRAL", nil)
  490. end
  491. else
  492. build_result:write("GCC for ARM not available\n\n")
  493. print("ARM Thumb GCC build skipped")
  494. end
  495. --
  496. -- Build ARM Cortex GCC libs and apps
  497. --
  498. path_env = TOOL_PATH..GCCARM_PATH..BASE_PATH
  499. -- if os.execute("SET PATH="..path_env.."&arm-elf-gcc -v"..REDIR) == 0 then
  500. if os.execute("SET PATH="..path_env.."&arm-none-eabi-gcc -v"..REDIR) == 0 then
  501. for t_index, t_board in ipairs(cortex_targets) do
  502. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_MCD_ST_LIBERTY", '""')
  503. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_ST_GUIDANCE_ONLY", '""')
  504. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_LUMINARY_ANTI_VIRAL", '""')
  505. if build_libs(t_board.name, "cm3-gcc", path_env) == 0 then
  506. build_apps(t_board.name, t_board.mcu, "cm3-gcc", path_env)
  507. end
  508. if build_libs(t_board.name, "cm3-gccdbg", path_env) == 0 then
  509. build_apps(t_board.name, t_board.mcu, "cm3-gccdbg", path_env)
  510. end
  511. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_MCD_ST_LIBERTY", nil)
  512. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_ST_GUIDANCE_ONLY", nil)
  513. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_LUMINARY_ANTI_VIRAL", nil)
  514. end
  515. else
  516. build_result:write("GCC for ARM not available\n\n")
  517. print("ARM CM3 GCC build skipped")
  518. end
  519. --
  520. -- Build AVR GCC libs and apps
  521. --
  522. path_env = TOOL_PATH..GCCAVR_PATH..BASE_PATH
  523. if os.execute("SET PATH="..path_env.."&avr-gcc -v"..REDIR) == 0 then
  524. for t_index, t_board in ipairs(avr_targets) do
  525. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_MCD_ST_LIBERTY", '""')
  526. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_ST_GUIDANCE_ONLY", '""')
  527. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_LUMINARY_ANTI_VIRAL", '""')
  528. if build_libs(t_board.name, "avr-gcc", path_env) == 0 then
  529. if build_apps(t_board.name, t_board.mcu, "avr-gcc", path_env) == 0 then
  530. if build_libs(t_board.name, "avr-gccdbg", path_env) == 0 then
  531. -- Exclude debug apps from targets with less than 256k flash
  532. if t_board.mcu == "atmega2561" then
  533. build_apps(t_board.name, t_board.mcu, "avr-gccdbg", path_env)
  534. end
  535. end
  536. end
  537. end
  538. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_MCD_ST_LIBERTY", nil)
  539. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_ST_GUIDANCE_ONLY", nil)
  540. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_LUMINARY_ANTI_VIRAL", nil)
  541. end
  542. else
  543. build_result:write("GCC for AVR not available\n\n")
  544. print("AVR GCC build skipped")
  545. end
  546. --
  547. -- Build ARM GCC libs and apps
  548. --
  549. path_env = TOOL_PATH..GCCARM_PATH..BASE_PATH
  550. -- if os.execute("SET PATH="..path_env.."&arm-elf-gcc -v"..REDIR) == 0 then
  551. if os.execute("SET PATH="..path_env.."&arm-none-eabi-gcc -v"..REDIR) == 0 then
  552. for t_index, t_board in ipairs(arm_targets) do
  553. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_MCD_ST_LIBERTY", '""')
  554. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_ST_GUIDANCE_ONLY", '""')
  555. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_LUMINARY_ANTI_VIRAL", '""')
  556. -- update_config("nut/conf/"..t_board.name..".conf", "CRT_UNSETENV_POSIX", '""')
  557. -- update_config("nut/conf/"..t_board.name..".conf", "ARMEABI", '""')
  558. if build_libs(t_board.name, "arm-gcc", path_env) == 0 then
  559. build_apps(t_board.name, t_board.mcu, "arm-gcc", path_env)
  560. end
  561. if build_libs(t_board.name, "arm-gccdbg", path_env) == 0 then
  562. -- Exclude debug apps from AT91EB40A because of lack of sufficient RAM
  563. if t_board.name ~= "at91eb40a" then
  564. build_apps(t_board.name, t_board.mcu, "arm-gccdbg", path_env)
  565. end
  566. end
  567. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_MCD_ST_LIBERTY", nil)
  568. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_ST_GUIDANCE_ONLY", nil)
  569. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_LUMINARY_ANTI_VIRAL", nil)
  570. end
  571. else
  572. build_result:write("GCC for ARM not available\n\n")
  573. print("ARM GCC build skipped")
  574. end
  575. --
  576. -- Build AVR32 GCC libs and apps
  577. --
  578. path_env = TOOL_PATH..GCCAVR32_PATH..BASE_PATH
  579. if os.execute("SET PATH="..path_env.."&avr32-gcc -v"..REDIR) == 0 then
  580. for t_index, t_board in ipairs(avr32_targets) do
  581. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_MCD_ST_LIBERTY", '""')
  582. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_ST_GUIDANCE_ONLY", '""')
  583. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_LUMINARY_ANTI_VIRAL", '""')
  584. if build_libs(t_board.name, "avr32-gcc", path_env) == 0 then
  585. build_apps(t_board.name, t_board.mcu, "avr32-gcc", path_env)
  586. end
  587. if build_libs(t_board.name, "avr32-gccdbg", path_env) == 0 then
  588. build_apps(t_board.name, t_board.mcu, "avr32-gccdbg", path_env)
  589. end
  590. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_MCD_ST_LIBERTY", nil)
  591. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_ST_GUIDANCE_ONLY", nil)
  592. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_LUMINARY_ANTI_VIRAL", nil)
  593. end
  594. else
  595. build_result:write("SET PATH="..path_env.."&avr32-gcc -v\n")
  596. build_result:write("GCC for AVR32 not available\n\n")
  597. end
  598. --
  599. -- Build ICCAVR7 libs and apps
  600. --
  601. path_env = TOOL_PATH..ICCAVR7_PATH..BASE_PATH
  602. if os.execute("SET PATH="..path_env.."&iccavr -v"..REDIR) == 0 then
  603. for t_index, t_board in ipairs(avr_targets) do
  604. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_MCD_ST_LIBERTY", '""')
  605. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_ST_GUIDANCE_ONLY", '""')
  606. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_LUMINARY_ANTI_VIRAL", '""')
  607. update_config("nut/conf/"..t_board.name..".conf", "AVR_GCC", nil)
  608. update_config("nut/conf/"..t_board.name..".conf", "ICCAVR", '""')
  609. update_config("nut/conf/"..t_board.name..".conf", "ICCAVR_STARTUP", '"crtenutram"')
  610. if t_board.mcu == "atmega128" then
  611. if build_libs(t_board.name, "avr-icc7", path_env) == 0 then
  612. build_apps(t_board.name, "enhanced", "avr-icc7", path_env)
  613. end
  614. elseif t_board.mcu == "atmega2561" then
  615. if build_libs(t_board.name, "avrext-icc7", path_env) == 0 then
  616. build_apps(t_board.name, "extended", "avrext-icc7", path_env)
  617. end
  618. end
  619. update_config("nut/conf/"..t_board.name..".conf", "AVR_GCC", '""')
  620. update_config("nut/conf/"..t_board.name..".conf", "ICCAVR", nil)
  621. update_config("nut/conf/"..t_board.name..".conf", "ICCAVR_STARTUP", nil)
  622. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_MCD_ST_LIBERTY", nil)
  623. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_ST_GUIDANCE_ONLY", nil)
  624. update_config("nut/conf/"..t_board.name..".conf", "LICENSE_LUMINARY_ANTI_VIRAL", nil)
  625. end
  626. else
  627. build_result:write("ICC7 for AVR not available\n\n")
  628. print("ICC AVR build skipped")
  629. end
  630. --
  631. -- Generate API documentation
  632. --
  633. path_env = DOXY_PATH..BASE_PATH
  634. lfs.chdir("nut\\doc\\gen")
  635. build_docs(path_env)
  636. lfs.chdir("..\\..\\..")
  637. lfs.chdir("nut\\doc\\en\\chm")
  638. build_winhelp(path_env)
  639. lfs.chdir("..\\..\\..\\..")
  640. --
  641. -- Generate Windows installer executable
  642. --
  643. path_env = NSIS_PATH..BASE_PATH
  644. lfs.chdir("nut\\tools\\packaging\\nsis")
  645. build_winstaller(path_env)
  646. lfs.chdir("..\\..\\..\\..")
  647. lfs.chdir("..")
  648. io.close(build_result)