forked from z88dk/z88dk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·217 lines (182 loc) · 5.8 KB
/
build.sh
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
213
214
215
216
217
#!/bin/sh
#
#
# Build z88dk on unix systems
#
show_help_and_exit()
{
if [ -n $1 ]; then rc=$1; else rc=0; fi
echo ""
echo "Usage: $0 [-b][-c][-C][-e][-h][-k][-l][-p][-t][-z]"
echo ""
echo " -b Don't build binaries"
echo " -c Clean build environment"
echo " -C Clean build environment and binaries (including bin/*)"
echo " Chosing this option makes a manual rebuild of zsdcc and"
echo " szdcpp necessary in the win32 environment"
echo " -e Build examples"
echo " -h This help information"
echo " -k Keep building ignoring errors"
echo " -l Don't build libraries"
echo " -p TARGET Build specified targets"
echo " -i PATH Final installation directory"
echo " -t Run tests"
echo " -z Skip the z80asm tests"
echo " -v Be verbose"
echo ""
echo "Default is to build binaries and libraries"
echo ""
exit $rc
}
set -e # -e: exit on error; -u: exit on undefined variable
# -e can be overidden by -k option
case `uname -s` in # Insert default values for MAKE and INSTALL following used OS
SunOS)
MAKE="gmake"
INSTALL="ginstall"
export INSTALL
;;
OpenBSD|NetBSD|FreeBSD)
MAKE="gmake"
INSTALL="install"
export INSTALL
if [ -z "$CC" ]; then # Insert default value for CC if CC is empty
CC="cc"
export CC
fi
;;
Darwin)
if ! command -v gmake &> /dev/null
then
MAKE="make"
echo "Using gmake is recommended on MacOS"
else
MAKE="gmake"
fi
INSTALL="install"
export INSTALL
;;
*)
MAKE="make"
INSTALL="install"
export INSTALL
;;
esac
do_build=1 # Set initial (default) values (build binaries and libraries)
do_clean=0
do_clean_bin=0
do_examples=0
do_libbuild=1
do_tests=0
skip_z80asm_tests=0
DESTDIR=/usr/local
builddir=$(pwd)
ZCCCFG=$builddir/lib/config
PATH="$builddir/bin:$PATH"
export ZCCCFG
export PATH
while getopts "bcCehkltzp:i:v" arg; do # Handle all given arguments
case "$arg" in
b) do_build=0 ;; # Don't build
c) do_clean=1 ;; # clean except bin/*
C) do_clean_bin=1 ;; # Clean including bin/*
e) do_examples=1 ;; # Build examples as well
k) set +e ;; # keep building ignoring errors
l) do_libbuild=0 ;; # Don't build libraries
p) TARGETS=$OPTARG ;;
i) DESTDIR=$OPTARG ;;
t) do_tests=1 ;; # Run tests as well
z) skip_z80asm_tests=1 ;; # Skip z80asm tests
v) export Q= ;; # verbose makefiles
h | *) show_help_and_exit 0 ;; # Show help on demand
esac
done
# If there will be no action at all with the given parameters, then show help and exit with error
if [ $do_clean != 1 ] \
&& [ $do_clean_bin != 1 ] \
&& [ $do_build != 1 ] \
&& [ $do_libbuild != 1 ] \
&& [ $do_tests != 1 ] \
&& [ $do_examples != 1 ]; then
show_help_and_exit 1
fi
# check that all module dependencies are downloaded
MODULE_PATH=./ext
MODULES="optparse regex Unity UNIXem uthash"
echo "Checking if submodule dependencies are met..."
MOD_ERRORS=0
for mod in $MODULES; do
if [ "$( ls -1 "$MODULE_PATH/$mod/" | wc -l )" -eq 0 ]; then
echo "** Error: $GIT submodule '$mod' missing"
MOD_ERRORS=$(( MOD_ERRORS + 1 ))
fi
done
if [ "$MOD_ERRORS" -gt 0 ]; then
cat <<EOF
Dependencies missing! It is likely you downloaded an autogenerated archive of the source,
or cloned from Github without the --recursive option.
Either:
Download the complete archive from: https://github.com/z88dk/z88dk/releases/download/v2.2/z88dk-src-2.2.tgz
or
Re-clone from Github using: git clone --recursive git@github.com:z88dk/z88dk.git
EOF
exit 1
else
echo "Module dependencies are present"
fi
if [ $do_clean = 1 -o $do_clean_bin = 1 ]; then # Dont remove bin, as zsdcc and szdcpp must be built by hand in win32
$MAKE clean
fi
if [ $do_clean_bin = 1 ]; then # Remove bin => zsdcc and zdcpp must be built again by hand in win32
echo "rm -rf bin"
rm -rf bin
fi
# If there was only cleaning to do then don't change paths, global variables, ...
if [ $do_build != 1 ] \
&& [ $do_libbuild != 1 ] \
&& [ $do_tests != 1 ] \
&& [ $do_examples != 1 ]; then
exit 0
fi
if [ -z "$CC" ]; then # Insert default value for CC if CC is empty
CC="gcc"
export CC
fi
if [ -z "$CFLAGS" ]; then # Insert default value for CFLAGS if CFLAGS is empty
CFLAGS="-g -O2"
export CFLAGS
fi
path=`pwd`/bin # Add bin directory to path if it's not already there
mkdir -p $path # Guarantee that the directory exists
if [ "$PATH" != *$path* ]; then
PATH="$path:$PATH"
export PATH
fi
ZCCCFG=`pwd`/lib/config/ # Set ZCCCFG to the lib config directory
mkdir -p $ZCCCFG # Guarantee that the directory exists
export ZCCCFG
if [ $do_build = 1 ]; then # Build binaries or not...
$MAKE DESTDIR=$DESTDIR
fi
if [ $do_libbuild = 1 ]; then # Build libraries or not...
if [ $TARGETS ]; then
MAKEARG="TARGETS=$TARGETS"
else
MAKEARG=""
fi
$MAKE -C libsrc $MAKE_CONCURRENCY $MAKEARG
$MAKE -C libsrc install
$MAKE -C libsrc/_DEVELOPMENT $TARGETS $MAKE_CONCURRENCY
$MAKE -C include/_DEVELOPMENT
fi
if [ $do_tests = 1 ]; then # Build tests or not...
$MAKE -C testsuite
if [ $skip_z80asm_tests = 1 ]; then
$MAKE -C test suites feature
else
$MAKE -C test
fi
fi
if [ $do_examples = 1 ]; then # Build examples or not...
$MAKE -C examples
fi