build: Split-out build-source-lib.sh from build-lib.sh.
[mes.git] / build-aux / build.sh.in
1 #! /bin/sh
2
3 # GNU Mes --- Maxwell Equations of Software
4 # Copyright © 2018,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
23 if test "$1" = "help"; then
24     cat <<EOF
25 Run:
26   ./build.sh      to build mes
27   ./check.sh      to check mes
28   ./install.sh    to install mes
29 EOF
30     exit 0
31 fi
32
33 if test "$V" = 2; then
34     set -x
35 fi
36
37 set -u
38 . ./config.sh
39
40 if $courageous; then
41     echo "Applying courage"
42     set +e
43 fi
44
45 ${SHELL} ${srcdest}build-aux/build-scaffold.sh
46
47 if test -n "$GUILE" -a "$GUILE" != true; then
48     ${SHELL} ${srcdest}build-aux/build-guile.sh
49 fi
50
51 debug=
52 #debug=-g
53
54 CFLAGS="
55 -static
56 $debug
57 "
58
59 if test $mes_libc = mes; then
60     CFLAGS="$CFLAGS
61 -nostdinc
62 -nostdlib
63 -fno-builtin
64 "
65 fi
66
67 CPPFLAGS="
68 -D HAVE_CONFIG_H=1
69 -I ../include
70 -I ${srcdir}/../include
71 -I ${srcdir}/../include/$mes_kernel/$mes_cpu
72 "
73
74 LDFLAGS="
75 $debug
76 -L .
77 "
78 if test $mes_libc = mes; then
79     LDFLAGS="$LDFLAGS
80 -nostdlib
81 "
82 fi
83 LIBS=-lc
84
85 export CFLAGS
86 export CPPFLAGS
87 export LDFLAGS
88 export LIBS
89
90 (
91     mkdir -p gcc-lib
92     cp config.sh gcc-lib
93     cd gcc-lib
94     if test -z "$srcdest"; then
95         srcdest=../
96         srcdir=../
97     fi
98     if test $compiler = gcc; then
99         CPPFLAGS="
100 -D HAVE_CONFIG_H=1
101 -I include
102 -I ${srcdest}include
103 -I ${srcdest}include/$mes_kernel/$mes_cpu
104 "
105         ${SHELL} ${srcdest}build-aux/build-lib.sh
106         cp crt1.o ..
107     fi
108     compiler=gcc ${SHELL} ${srcdest}build-aux/build-source-lib.sh
109 )
110
111 (
112     if test $compiler = gcc; then
113         LDFLAGS="$LDFLAGS
114 -L gcc-lib
115 "
116     fi
117
118     CPPFLAGS="
119 -D HAVE_CONFIG_H=1
120 -I include
121 -I ${srcdest}include
122 -I ${srcdest}include/$mes_kernel/$mes_cpu
123 "
124     ${SHELL} ${srcdest}build-aux/build-mes.sh
125 )
126
127 (
128     mkdir -p mescc-lib
129     cp config.sh mescc-lib
130     cd mescc-lib
131     sed -i s,mes_libc=system,mes_libc=mes, config.sh
132     mkdir -p include/mes
133     cp -p ../include/mes/config.h include/mes/config.h
134     sed -i 's,#define SYSTEM_LIBC 1,#undef SYSTEM_LIBC,' include/mes/config.h
135     if test -z "$srcdest"; then
136         srcdest=../
137         srcdir=../
138     fi
139         CPPFLAGS="
140 -D HAVE_CONFIG_H=1
141 -I include
142 -I ${srcdest}include
143 -I ${srcdest}include/$mes_kernel/$mes_cpu
144 "
145     compiler=mescc
146     AR="${srcdest}pre-inst-env mesar"
147     CC="${srcdest}pre-inst-env mescc -m $mes_bits"
148     ${SHELL} ${srcdest}build-aux/build-lib.sh
149     ${SHELL} ${srcdest}build-aux/build-source-lib.sh
150 )