-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcprj.nim
38 lines (30 loc) · 1.02 KB
/
cprj.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import std/strutils
import std/os
const
make_tpl = staticRead("./templates/c/make_tpl")
makef_tpl = staticRead("./templates/c/make_flash_tpl")
cmake_tpl = staticRead("./templates/c/cmake_tpl")
cmakef_tpl = staticRead("./templates/c/cmake_flash_tpl")
git_tpl = staticRead("./templates/c/gitignore")
main_tpl = staticRead("./templates/c/main_tpl")
proc generate_project*(mcu, fcpu, prog, proj: string, cmake: bool) =
if dirExists(proj):
stdout.writeLine "a directory with the current project name already exists"
quit(1)
createDir(proj)
setCurrentDir(proj)
if cmake:
if prog == "":
writeFile("CMakeLists.txt", cmake_tpl % [mcu, fcpu])
else:
writeFile("CMakeLists.txt", cmakef_tpl % [mcu, fcpu, prog])
else:
if prog == "":
writeFile("Makefile", make_tpl % [mcu, fcpu])
else:
writeFile("Makefile", makef_tpl % [mcu, fcpu, prog])
writeFile(".gitignore", git_tpl)
createDir("inc")
createDir("src")
setCurrentDir("./src")
writeFile("main.c", main_tpl)