build: Improve --with-system-libc support.
[mes.git] / build-aux / build-lib.sh
1 #! /bin/sh
2
3 # GNU Mes --- Maxwell Equations of Software
4 # Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
5 #
6 # This file is part of GNU Mes.
7 #
8 # GNU Mes is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or (at
11 # your option) any later version.
12 #
13 # GNU Mes is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with GNU Mes.  If not, see <http://www.gnu.org/licenses/>.
20
21 set -e
22 set -u
23
24 V=${V-1}
25
26 if [ "$V" = 2 ]; then
27     set -x
28 fi
29
30 . ./config.sh
31 . ${srcdest}build-aux/trace.sh
32 . ${srcdest}build-aux/cc.sh
33
34 trap 'test -f .log && cat .log' EXIT
35
36 srcdest=${srcdest-}
37
38 libc_mini_SOURCES="
39 lib/mes/eputs.c
40 lib/mes/oputs.c
41 "
42
43 if test $mes_libc = mes; then
44     libc_mini_SOURCES="$libc_mini_SOURCES
45 lib/posix/write.c
46 lib/string/strlen.c
47 lib/stdlib/puts.c
48 lib/stdlib/exit.c
49 lib/$mes_kernel/$mes_cpu-mes-$compiler/mini.c
50 "
51 fi
52
53 libmes_SOURCES="
54 $libc_mini_SOURCES
55 lib/ctype/isnumber.c
56 lib/mes/abtol.c
57 lib/mes/itoa.c
58 lib/mes/ltoa.c
59 lib/mes/ltoab.c
60 lib/mes/ultoa.c
61 lib/mes/utoa.c
62 lib/mes/eputc.c
63 lib/mes/fdgetc.c
64 lib/mes/fdputc.c
65 lib/mes/fdputs.c
66 lib/mes/fdungetc.c
67 lib/mes/mes_open.c
68 lib/mes/ntoab.c
69 lib/mes/oputc.c
70 "
71
72 if test $mes_libc = mes; then
73     libmes_SOURCES="$libmes_SOURCES
74 lib/stdlib/atoi.c
75 lib/ctype/isdigit.c
76 lib/ctype/isspace.c
77 lib/ctype/isxdigit.c
78 "
79 else
80     libmes_SOURCES="$libmes_SOURCES
81 "
82 fi
83
84 libc_SOURCES="
85 $libmes_SOURCES
86 lib/mes/__assert_fail.c
87 lib/mes/__mes_debug.c
88 lib/posix/execv.c
89 lib/posix/getenv.c
90 lib/posix/isatty.c
91 lib/posix/setenv.c
92 lib/posix/wait.c
93 lib/stdio/fgetc.c
94 lib/stdio/fputc.c
95 lib/stdio/fputs.c
96 lib/stdio/getc.c
97 lib/stdio/getchar.c
98 lib/stdio/putc.c
99 lib/stdio/putchar.c
100 lib/stdio/ungetc.c
101 lib/stdlib/free.c
102 lib/stdlib/malloc.c
103 lib/stdlib/realloc.c
104 lib/string/memchr.c
105 lib/string/memcmp.c
106 lib/string/memcpy.c
107 lib/string/memset.c
108 lib/string/strcmp.c
109 lib/string/strcpy.c
110 lib/string/strncmp.c
111 "
112
113 if test $mes_kernel = linux; then
114     libc_SOURCES="$libc_SOURCES
115 lib/linux/access.c
116 lib/linux/brk.c
117 lib/linux/chmod.c
118 lib/linux/clock_gettime.c
119 lib/linux/dup.c
120 lib/linux/dup2.c
121 lib/linux/execve.c
122 lib/linux/fork.c
123 lib/linux/fsync.c
124 lib/linux/getcwd.c
125 lib/linux/gettimeofday.c
126 lib/linux/ioctl.c
127 lib/linux/open.c
128 lib/linux/read.c
129 lib/linux/time.c
130 lib/linux/unlink.c
131 lib/linux/waitpid.c
132 lib/linux/$mes_cpu-mes-$compiler/syscall.c
133 "
134 fi
135
136 libtcc1_SOURCES="
137 lib/libtcc1.c
138 "
139
140 libc_tcc_SOURCES="
141 $libc_SOURCES
142 lib/ctype/islower.c
143 lib/ctype/isupper.c
144 lib/ctype/tolower.c
145 lib/ctype/toupper.c
146 lib/mes/search-path.c
147 lib/posix/execvp.c
148 lib/stdio/fclose.c
149 lib/stdio/fdopen.c
150 lib/stdio/ferror.c
151 lib/stdio/fflush.c
152 lib/stdio/fopen.c
153 lib/stdio/fprintf.c
154 lib/stdio/fread.c
155 lib/stdio/fseek.c
156 lib/stdio/ftell.c
157 lib/stdio/fwrite.c
158 lib/stdio/printf.c
159 lib/stdio/remove.c
160 lib/stdio/snprintf.c
161 lib/stdio/sprintf.c
162 lib/stdio/sscanf.c
163 lib/stdio/vfprintf.c
164 lib/stdio/vprintf.c
165 lib/stdio/vsnprintf.c
166 lib/stdio/vsprintf.c
167 lib/stdio/vsscanf.c
168 lib/stdlib/calloc.c
169 lib/stdlib/qsort.c
170 lib/stdlib/strtof.c
171 lib/stdlib/strtol.c
172 lib/stdlib/strtold.c
173 lib/stdlib/strtoll.c
174 lib/stdlib/strtoul.c
175 lib/stdlib/strtoull.c
176 lib/string/memmem.c
177 lib/string/memmove.c
178 lib/string/strcat.c
179 lib/string/strchr.c
180 lib/string/strlwr.c
181 lib/string/strncpy.c
182 lib/string/strrchr.c
183 lib/string/strstr.c
184 lib/string/strupr.c
185 lib/stub/sigaction.c
186 lib/stub/ldexp.c
187 lib/stub/mprotect.c
188 lib/stub/localtime.c
189 lib/stub/sigemptyset.c
190 lib/stub/strtod.c
191 lib/$mes_cpu-mes-$compiler/setjmp.c
192 "
193
194 if test $mes_kernel = linux; then
195     libc_tcc_SOURCES="$libc_tcc_SOURCES
196 lib/linux/close.c
197 lib/linux/lseek.c
198 lib/linux/rmdir.c
199 lib/linux/stat.c
200 "
201 fi
202
203 libc_gnu_SOURCES="
204 $libc_tcc_SOURCES
205 lib/ctype/isalnum.c
206 lib/ctype/isalpha.c
207 lib/ctype/isascii.c
208 lib/ctype/iscntrl.c
209 lib/ctype/isprint.c
210 lib/ctype/ispunct.c
211 lib/dirent/__getdirentries.c
212 lib/dirent/closedir.c
213 lib/dirent/opendir.c
214 lib/dirent/readdir.c
215 lib/math/fabs.c
216 lib/mes/fdgets.c
217 lib/posix/alarm.c
218 lib/posix/execl.c
219 lib/posix/mktemp.c
220 lib/posix/raise.c
221 lib/posix/sbrk.c
222 lib/posix/sleep.c
223 lib/posix/unsetenv.c
224 lib/stdio/clearerr.c
225 lib/stdio/feof.c
226 lib/stdio/fgets.c
227 lib/stdio/fileno.c
228 lib/stdio/freopen.c
229 lib/stdio/perror.c
230 lib/stdlib/__exit.c
231 lib/stdlib/abort.c
232 lib/stdlib/abs.c
233 lib/stdlib/alloca.c
234 lib/stdlib/atexit.c
235 lib/stdlib/atol.c
236 lib/stdlib/mbstowcs.c
237 lib/string/bcmp.c
238 lib/string/bcopy.c
239 lib/string/bzero.c
240 lib/string/index.c
241 lib/string/rindex.c
242 lib/string/strcspn.c
243 lib/string/strdup.c
244 lib/string/strerror.c
245 lib/string/strncat.c
246 lib/string/strpbrk.c
247 lib/string/strspn.c
248 lib/stub/__cleanup.c
249 lib/stub/bsearch.c
250 lib/stub/chown.c
251 lib/stub/ctime.c
252 lib/stub/fpurge.c
253 lib/stub/freadahead.c
254 lib/stub/frexp.c
255 lib/stub/getlogin.c
256 lib/stub/getpwnam.c
257 lib/stub/getpwuid.c
258 lib/stub/gmtime.c
259 lib/stub/pclose.c
260 lib/stub/popen.c
261 lib/stub/rand.c
262 lib/stub/setbuf.c
263 lib/stub/setlocale.c
264 lib/stub/setvbuf.c
265 lib/stub/sigaddset.c
266 lib/stub/sigblock.c
267 lib/stub/sigdelset.c
268 lib/stub/sigsetmask.c
269 lib/stub/strftime.c
270 lib/stub/sys_siglist.c
271 lib/stub/system.c
272 lib/stub/times.c
273 lib/stub/ttyname.c
274 lib/stub/umask.c
275 lib/stub/utime.c
276 "
277
278 if test $mes_kernel = linux; then
279     libc_gnu_SOURCES="$libc_gnu_SOURCES
280 lib/linux/chdir.c
281 lib/linux/fcntl.c
282 lib/linux/fstat.c
283 lib/linux/getdents.c
284 lib/linux/getegid.c
285 lib/linux/geteuid.c
286 lib/linux/getgid.c
287 lib/linux/getpid.c
288 lib/linux/getppid.c
289 lib/linux/getrusage.c
290 lib/linux/getuid.c
291 lib/linux/kill.c
292 lib/linux/link.c
293 lib/linux/lstat.c
294 lib/linux/mkdir.c
295 lib/linux/nanosleep.c
296 lib/linux/pipe.c
297 lib/linux/rename.c
298 lib/linux/setgid.c
299 lib/linux/settimer.c
300 lib/linux/setuid.c
301 lib/linux/signal.c
302 lib/linux/sigprogmask.c
303 "
304 fi
305
306 mkdir -p $mes_cpu-mes
307 compile lib/$mes_kernel/$mes_cpu-mes-$compiler/crt1.c
308 cp crt1.o $mes_cpu-mes
309 if test -e crt1.s; then
310     cp crt1.s $mes_cpu-mes
311 fi
312
313 archive libc-mini.a $libc_mini_SOURCES
314 cp libc-mini.a $mes_cpu-mes
315 if test -e libc-mini.s; then
316     cp libc-mini.s $mes_cpu-mes
317 fi
318
319 archive libmes.a $libmes_SOURCES
320 cp libmes.a $mes_cpu-mes
321 if test -e libmes.s; then
322     cp libmes.s $mes_cpu-mes
323 fi
324
325 if test $mes_libc = mes; then
326     archive libc.a $libc_SOURCES
327     cp libc.a $mes_cpu-mes
328     if test -e libc.s; then
329         cp libc.s $mes_cpu-mes
330     fi
331 fi
332
333 archive libc+tcc.a $libc_tcc_SOURCES
334 cp libc+tcc.a $mes_cpu-mes
335 if test -e libc+tcc.s; then
336     cp libc+tcc.s $mes_cpu-mes
337 fi
338
339 if $courageous; then
340     exit 0
341 fi
342
343 archive libc+gnu.a $libc_gnu_SOURCES
344 cp libc+gnu.a $mes_cpu-mes
345 if test -e libc+gnu.s; then
346     cp libc+gnu.s $mes_cpu-mes
347 fi
348
349 archive libtcc1.a $libtcc1_SOURCES
350 cp libtcc1.a $mes_cpu-mes
351 if test -e libtcc1.s; then
352     cp libtcc1.s $mes_cpu-mes
353 fi
354
355 archive libgetopt.a lib/posix/getopt.c
356 cp libgetopt.a $mes_cpu-mes
357 if test -e libgetopt.s; then
358     cp libgetopt.s $mes_cpu-mes
359 fi