-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.mb
212 lines (174 loc) · 5.4 KB
/
build.mb
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
; mb build file for mariebuild 0.4.0 or higher
; this file also serves as a lead example for how to use mariebuild.
sector config
section files
; Directories
str build_root 'build/'
str debug_dir '$(/config/files/build_root)debug/'
str release_dir '$(/config/files/build_root)release/'
str obj_dir 'obj/'
; Binaries
str binname 'mb'
; Sources
list str sources
'cptrlist',
'logging',
'stringutil',
'types',
'executor',
'c_rule',
'signals',
'target',
'build',
'main'
end
section tools
str cc 'clang'
str cflags '-std=c17 -pedantic-errors -Wall -Wextra -Werror -Wno-gnu-statement-expression'
end
section mariebuild
u8 default_log_level 2
; mariebuild now supports incremental building. In this mode, a compilation rule
; is only executed if a file it executes upon is
str build_type 'incremental'
; mcfg 2 has brought along a new list syntax, where each element is its own string
; and seperated by commas.
list str targets 'clean', 'debug', 'release'
str default 'debug'
end
end
; Mariebuild now works with targets defined in this sector.
; Each target can list other targets which it requires. Fields
; from the current target are accesible via %target%.
sector targets
section clean-debug
str exec '#!/bin/bash
if [ -d $(/config/files/debug_dir) ]; then
rm -rf $(/config/files/debug_dir)
fi
mkdir $(/config/files/debug_dir)
'
end
section clean-release
str exec '#!/bin/bash
if [ -d $(/config/files/release_dir) ]; then
rm -rf $(/config/files/release_dir)
fi
mkdir $(/config/files/release_dir)
'
end
section depends
str exec '#!/bin/bash
if [[ lib/libmcfg_2.a -ot ./setup.bash ]]; then
./setup.bash
fi
'
end
section debug
; Any field defined within a target of which the name if prefixed with
; target_ is registered as a dynfield with the exact same name.
; (So this field can be used using $(%target_cflags%)
str target_cflags '-ggdb -Iinclude/ -Isrc/'
str target_ldflags ''
str target_builddir '$(/config/files/debug_dir)'
str target_objdir '$(/config/files/debug_dir)$(/config/files/obj_dir)'
; Each target lists c_rules (or compilation rules) which are executed in order.
list str c_rules 'executable'
end
section release
str target_cflags '-Oz -Iinclude/ -Isrc/'
str target_ldflags ''
str target_builddir '$(/config/files/release_dir)'
str target_objdir '$(/config/files/release_dir)$(/config/files/obj_dir)'
list str required_targets 'clean-release', 'depends'
list str c_rules 'executable', 'strip-executable'
end
section static-release
str target_cflags '-Oz -Iinclude/ -Isrc/'
str target_ldflags '-static'
str target_builddir '$(/config/files/release_dir)'
str target_objdir '$(/config/files/release_dir)$(/config/files/obj_dir)'
list str required_targets 'clean', 'depends'
list str c_rules 'executable', 'strip-executable'
end
end
; Each compilation rule is defined within this sector. They can access Fields
; of the current target using %target%.
sector c_rules
section strip-executable
list str input ''
str input_format ''
str output_format ''
str exec '#!/bin/bash
STRIPFLAGS="--strip-all"
unameOut="\$(uname -s)"
case "${unameOut}" in
Darwin*) STRIPFLAGS="-S -X";;
esac
printf " strip $STRIPFLAGS ./mb\\n"
strip $STRIPFLAGS $(%target_builddir%)$(/config/files/binname)
'
end
section executable
; Compilation rules can list other compilation rules which they require
; These are executed in order.
list str c_rules 'main'
str binname 'mb'
str build_type 'full'
str exec_mode 'unify'
str input_src '/config/files/sources'
str input_format '$(%target_objdir%)$(%element%).o'
str output_format '$(%target_builddir%)$(/config/files/binname)'
str ldflags '$(%target_ldflags%) -Llib/ -lmcfg_2 -lm'
; The command which is specified in the exec field is executed for each member of
; the list specified in exec_on
str exec '#!/bin/bash
unameOut="\$(uname -s)"
case "${unameOut}" in
Darwin*)
if [ -d /opt/homebrew/lib/ ]; then
EXTRA_LDFLAGS="-L/opt/homebrew/lib -largp"
else
EXTRA_LDFLAGS="-L/usr/local/lib -largp"
fi
printf " -> Linking for Darwin, EXTRA_LDFLAGS=$EXTRA_LDFLAGS\\n";;
esac
COMMAND="$(/config/tools/cc) -o $(%output%) $(%input%) $(ldflags) $EXTRA_LDFLAGS"
printf " $COMMAND\\n"
$COMMAND
'
end
section main
; Run the 'exec' command for each input element.
str exec_mode 'singular'
bool parallel true
u8 max_procs 16
; Declare our set of input elements. If no output list is defined,
; the input list is used for that as well.
str input_src '/config/files/sources'
str output_src '/config/files/sources'
; The input and output_format fields are used to determine if a output file
; is out of date. They are also used to generate the input and output dynfields
str input_format 'src/$(%element%).c'
str output_format '$(%target_objdir%)$(%element%).o'
str exec '#!/bin/bash
if ! [ -d "\$(dirname $(%output%))" ]; then
COMMAND="mkdir -p \$(dirname $(%output%))"
echo " $COMMAND"
$COMMAND
fi
unameOut="\$(uname -s)"
case "${unameOut}" in
Darwin*)
if [ -d /opt/homebrew/include/ ]; then
EXTRA_CFLAGS="-I/opt/homebrew/include"
else
EXTRA_CFLAGS="-I/usr/local/include"
fi
esac
COMMAND="$(/config/tools/cc) $(/config/tools/cflags) $(%target_cflags%) $EXTRA_CFLAGS -c $(%input%) -o $(%output%)"
printf " $COMMAND\\n"
$COMMAND
'
end
end