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/>.
22 # Show help via option
23 if test "$1" = -h -o "$1" = --help
25 echo "Deploy static cross-compilers for easy distribution."
27 echo "Usage: $PROGRAM [TARGET]..."
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."
35 # Exit immediately on any error
38 # Override locale settings
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
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
77 for BTCXX
in ${phase_one}/cross
/*/bin
/*-g++
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
107 lzip
-9 ${output}/${tarname}-${target}.log
111 rm -f ${tarname}-${target}.tar ${tarname}-${target}.
tar.lz
114 tar -H ustar
-c .
/cross | lzip
-9vv \
115 > ${output}/${tarname}-${target}.
tar.lz
117 # Create the checksum
119 sha256sum
${tarname}-${target}.
tar.lz \
120 > ${tarname}-${target}.
tar.lz.sha256
122 # Back to the current working directory