blob: f69745eb0850673d15987a395d07f457cd46020d (
plain)
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
|
#!/bin/sh
# a poor man's universal driver (but stay tuned...)
error_msg()
{
echo $@ >&2
}
mb_source_dir=
mb_project_dir=
# one: args
for arg ; do
case "$arg" in
--help) usage
;;
--source-dir=*)
mb_source_dir=${arg#*=}
;;
--project-dir=*)
mb_project_dir=${arg#*=}
;;
*)
error_msg ${arg#}: "unsupported config argument."
exit 2
;;
esac
done
if [ -z "$mb_source_dir" ] || [ -z "$mb_project_dir" ]; then
usage
fi
# two: clean
make -s clean || exit 1
# three: init
echo '@echo on'
echo '@dir . > nul'
echo
echo
echo 'REM override variables either here or from the shell'
echo 'set source_dir=%source_dir%'
echo 'set sysroot=%sysroot%'
echo
echo
# four: build tree
cmd_abort_on_error='@if %errorlevel% neq 0 exit /b %errorlevel%'
sysroot_include_arg='-I%sysroot%/include'
dirs=`make dirs.tag tree.tag \
| grep -v 'make\[1\]:' \
| grep -v 'touch dirs.tag' \
| grep -v 'touch tree.tag' \
| sed \
-e 's/mkdir -p//g' \
-e 's@/@\\\\@g'`
for d in $dirs; do
printf 'if not exist %-20smkdir %s\n' "$d" "$d"
done
echo
echo "$cmd_abort_on_error"
echo
# five: build objects
make shared-objs static-objs app-objs \
| grep -v 'make\[1\]:' \
| grep -v "$mb_project_dir/sysinfo/host" \
| grep -v 'touch dirs.tag' \
| grep -v 'touch host.tag' \
| grep -v 'touch version.tag' \
| grep -v 'touch app.tag' \
| sed \
-e 's@cc @cl /nologo @' \
-e 's@ '"$mb_source_dir"'@ %source_dir%@' \
-e 's@-I'"$mb_source_dir"'@-I%source_dir%@g' \
-e 's@-ffreestanding@/X@g' \
-e 's@-o @/Fo:@g' \
-e 's@-std=c99 @@g' \
-e 's@-fPIC@@g' \
-e 's@-fpic@@g' \
-e 's@-g @/Zi @g' \
-e 's@-g0 @/Zi @g' \
-e 's@-g1 @/Zi @g' \
-e 's@-g2 @/Zi @g' \
-e 's@-g3 @/Zi @g' \
-e 's@-O @/O2 @g' \
-e 's@-Os @/O1 @g' \
-e 's@-O0 @/Od @g' \
-e 's@-O1 @/O2 @g' \
-e 's@-O2 @/O2 @g' \
-e 's@-O3 @/O2 @g' \
-e 's@-Wall @/Wall @g' \
-e 's@-Werror @/WX @g' \
-e 's@-Wextra @@g' \
-e 's@-Wundef @/Wall @g' \
-e 's,$, -I%sysroot%/include\n\n'"$cmd_abort_on_error"'\n,g'
echo
echo '@echo.'
echo '@echo clbuild: successfully built: shared-objs static-objs app-objs.'
echo '@echo.'
echo
# six: create static archive
make static \
| grep -v 'make\[1\]:' \
| grep -v "rm -f " \
| sed \
-e 's@ar rcs @lib /out:@' \
-e 's,$, /nologo\n,g'
echo
echo '@echo.'
echo '@echo clbuild: successfully created: static archive.'
echo '@echo.'
echo
# seven: link shared library
make LDFLAGS_IMPLIB= LDFLAGS_SONAME= shared-lib \
| grep -v 'make\[1\]:' \
| sed \
-e 's@cc -shared @link /dll /nologo @' \
-e 's@-o @/out:@g' \
-e 's@ -L@/libpath:@g' \
-e 's@-nostdlib @/nodefaultlib @g' \
-e 's@-Wl,--subsystem=@/subsystem:@g' \
-e 's@-Wl,--entry -Wl,@/entry:@g' \
-e 's@-Wl,--no-undefined@@g' \
-e 's@-Wl,--exclude-all-symbols@@g' \
echo
echo '@echo.'
echo '@echo clbuild: successfully linked: shared library.'
echo '@echo.'
echo
echo
echo '@echo.'
echo '@echo yay.'
echo '@echo.'
echo
# all done
exit 0
|