-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile.io
138 lines (131 loc) · 4.45 KB
/
compile.io
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env io
PRO := "cgraph"
DIR := "."
INC := Directory clone setPath("#{DIR}/include" interpolate)
SRC := Directory clone setPath("#{DIR}/src" interpolate)
SRC_TYPE := Directory clone setPath("#{SRC}/type" interpolate)
TST := Directory clone setPath("#{DIR}/tests" interpolate)
LIB := Directory clone setPath("#{DIR}/lib" interpolate)
CC := "cc"
CFLAGS := "-std=c89 -Wall -pedantic -fPIC"
CSFLAGS := "-shared"
MODE := "debug"
if(MODE == "debug") then(
CFLAGS := CFLAGS .. " -g -DDEBUG -O0"
) elseif(MODE == "release") then(
CFLAGS := CFLAGS .. "-O2"
)
# package shared library
AR := "ar"
ARFLAGS := "-rcs"
LIBSHARED := nil
LIBSTATIC := nil
TSTFILE := nil
TSTTARGET := nil
if(System platform == "windows") then(
# target files
LIBSHARED := File clone setPath("#{LIB}/lib#{PRO}.dll" interpolate)
LIBSTATIC := File clone setPath("#{LIB}/lib#{PRO}.lib" interpolate)
# test files
TSTFILE := File clone setPath("#{TST}/#{PRO}.c" interpolate)
TSTTARGET := File clone setPath("#{TST}/#{PRO}.exe" interpolate)
) else(
# target files
LIBSHARED := File clone setPath("#{LIB}/lib#{PRO}.so" interpolate)
LIBSTATIC := File clone setPath("#{LIB}/lib#{PRO}.a" interpolate)
# test files
TSTFILE := File clone setPath("#{TST}/#{PRO}.c" interpolate)
TSTTARGET := File clone setPath("#{TST}/#{PRO}" interpolate)
)
CFILES := SRC recursiveFilesOfTypes(".c")
args := System args
if(args size == 1) then(
LIB create
OFILES := List clone
CFILES foreach(file,
file := file path
obj := file asMutable replaceSeq(".c", ".o")
dep := file asMutable replaceSeq(".c", ".d")
"compile #{file} to #{obj}" interpolate println
System system("#{CC} #{CFLAGS} -I#{INC path} -I#{SRC_TYPE path} -c #{file} -o #{obj} -MD -MF #{dep}" interpolate )
OFILES append(obj)
)
OFILES := OFILES join(" ")
"compile #{LIBSHARED name}" interpolate println
System system("#{CC} #{CSFLAGS} -o #{LIBSHARED name} #{OFILES}" interpolate)
"compile #{LIBSTATIC name}" interpolate println
System system("#{AR} #{ARFLAGS} #{LIBSTATIC name} #{OFILES}" interpolate)
) elseif(args at(1) == "test") then(
"compile #{TSTFILE name} to #{TSTTARGET name}" interpolate println
System system("#{CC} #{CFLAGS} -I#{INC path} -o #{TSTTARGET name} #{TSTFILE name} -L#{LIB path} -static -l#{PRO} -lm" interpolate)
tst_path := File clone setPath("#{TST}/elements.csv" interpolate)
"test #{TSTTARGET name} with #{tst_path name}" interpolate println
System system("#{TSTTARGET name} #{tst_path name}" interpolate)
) elseif(args at(1) == "clean") then(
CFILES foreach(file,
file := file path
obj := file asMutable replaceSeq(".c", ".o")
"clean #{obj}" interpolate println
if(obj asFile exists) then(
obj asFile remove
)
dep := file asMutable replaceSeq(".c", ".d")
"clean #{dep}" interpolate println
if(dep asFile exists) then(
dep asFile remove
)
)
"clean #{LIBSTATIC name}" interpolate println
if(LIBSTATIC exists) then(
LIBSTATIC remove
)
"clean #{LIBSHARED name}" interpolate println
if(LIBSHARED exists) then(
LIBSHARED remove
)
"clean #{TSTTARGET name}" interpolate println
if(TSTTARGET exists) then(
TSTTARGET remove
)
) elseif(args at(1) == "distclean") then(
CFILES foreach(file,
file := file path
obj := file asMutable replaceSeq(".c", ".o")
"clean #{obj}" interpolate println
if(obj asFile exists) then(
obj asFile remove
)
dep := file asMutable replaceSeq(".c", ".d")
"clean #{dep}" interpolate println
if(dep asFile exists) then(
dep asFile remove
)
)
"clean #{LIBSTATIC name}" interpolate println
if(LIBSTATIC exists) then(
LIBSTATIC remove
)
"clean #{LIBSHARED name}" interpolate println
if(LIBSHARED exists) then(
LIBSHARED remove
)
"clean #{LIB path}" interpolate println
if(LIB exists) then(
LIB remove
)
"clean #{TSTTARGET name}" interpolate println
if(TSTTARGET exists) then(
TSTTARGET remove
)
) elseif(args at(1) == "help") then(
"#{args at(0)} <target>" interpolate println
"<target>: " println
" compile cgraph" println
" test test cgraph" println
" clean clean all the generated files" println
" distclean clean all the generated files and directories" println
" help commands to this program" println
) else(
"#{args at(1)} is an unsupported command" interpolate println
"use \"#{args at(0)} help\" to know all supported commands" interpolate println
)