musl has been upgraded to version 1.1.18
[dragora.git] / darkcrusade
blobe10ed09bdfe0cf789538e49d63159b917e11ce7b
1 #! /bin/sh -
3 # Deploy static cross-compilers for easy distribution
5 # Copyright (C) 2016, 2017 Matias Andres Fonzo <selk@dragora.org>
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 PROGRAM="${0##*/}"
22 # Show help via option
23 if test "$1" = -h -o "$1" = --help
24 then
25 echo "Deploy static cross-compilers for easy distribution."
26 echo ""
27 echo "Usage: $PROGRAM [TARGET]..."
28 echo ""
29 echo "Where TARGET is any target found in the directory \"targets\"."
30 echo "If no target names are passed, all available targets will be built."
31 echo ""
32 exit 0
35 # Exit immediately on any error
36 set -e
38 # Override locale settings
39 LC_ALL=C
40 export LC_ALL
42 #### Default values
44 # Get physical working directory, absolute path name
45 CWD=$(CDPATH= cd -P -- $(dirname -- "$0") && printf "$PWD")
47 # Output directory for tarballs
48 output="${CWD}/OUTPUT.darkcrusade"
50 # Set temporary directory for compilation, exporting it
51 TMPDIR=${output}/sources
52 export TMPDIR
54 # Compose tag for tarball names using year+month+day
55 tarname=darkcrusade_"$(date +%Y%b%d)"
57 # Prepare to start the cross compiler process in the phase 1
59 phase_one=${output}/phase1-native-"$(uname -m)".$$
61 echo "${PROGRAM}: Creating native cross compiler on $phase_one ..."
62 ${CWD}/bootstrap -s0 -o $phase_one
64 # Now will start the preparatives to use the recent native cross compiler
66 echo "${PROGRAM}: Using (existing) compiler from $phase_one ..."
68 # Set flags according to the generated compiler
69 for BTCC in ${phase_one}/cross/*/bin/*-gcc
71 if test -x "$BTCC"
72 then
73 BTCC="$BTCC"
74 break
76 done
77 for BTCXX in ${phase_one}/cross/*/bin/*-g++
79 if test -x "$BTCXX"
80 then
81 BTCXX="$BTCXX"
82 break
84 done
86 # Set and compose flags to be used as CC and CXX
88 BTCC="$BTCC -static -Wl,-Bstatic -static-libgcc"
89 BTCXX="$BTCXX -static -Wl,-Bstatic -static-libgcc"
91 IS_DARKCRUSADE=IS_DARKCRUSADE
93 export BTCC BTCXX IS_DARKCRUSADE
95 # Loop for create the targets, phase 2
96 for target in ${CWD}/targets/${@:-*}
98 target="${target##*/}"
100 phase_two=${output}/phase2-${target}.$$
102 echo "darkcrusade: Making target $target ..."
103 ${CWD}/bootstrap -s0 -a $target -o $phase_two 2>&1 | \
104 tee ${output}/${tarname}-${target}.log
106 # Compress log file
107 lzip -9 ${output}/${tarname}-${target}.log
109 # Prepare tarball
110 cd $output
111 rm -f ${tarname}-${target}.tar ${tarname}-${target}.tar.lz
113 cd $phase_two
114 tar -H ustar -c ./cross | lzip -9vv \
115 > ${output}/${tarname}-${target}.tar.lz
117 # Create the checksum
118 cd $output
119 sha256sum ${tarname}-${target}.tar.lz \
120 > ${tarname}-${target}.tar.lz.sha256
122 # Back to the current working directory
123 cd -- $CWD
124 done