3 # Deploy static cross-compilers for easy distribution
5 # Copyright (c) 2016-2020 Matias Fonzo, <selk@dragora.org>.
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
21 # Show help via option
22 if test "$1" = -h -o "$1" = --help
24 echo "Deploy static cross-compilers for easy distribution."
26 echo "Usage: $PROGRAM [TARGET]..."
28 echo "Where TARGET is any target found in the directory \"targets\"."
29 echo "If no target names are passed, all available targets will be built."
34 # Exit immediately on any error
37 # Override locale settings
43 # Get physical working directory (absolute path)
44 CWD
="$(CDPATH='' cd -P -- "$
(dirname -- "$0")" && pwd -P)"
46 # Output directory for tarballs
47 output
="${CWD}/OUTPUT.darkcrusade"
49 # Set temporary directory for compilation, exporting it
50 TMPDIR
=${output}/sources
53 # Compose tag for tarball names using year+month+day
54 tarname
=darkcrusade_
"$(date +%Y%b)"
56 # Prepare to start the cross compiler process in the phase 1
58 phase_one
=${output}/phase1-native-
"$(uname -m)".$$
60 echo "${PROGRAM}: Creating native cross compiler on $phase_one ..."
61 "${CWD}"/bootstrap
-s0 -o "$phase_one"
63 # Now will start the preparatives to use the recent native cross compiler
65 echo "${PROGRAM}: Using (existing) compiler from $phase_one ..."
67 # Set flags according to the generated compiler
68 for BTCC
in "${phase_one}"/cross
/*/bin
/*-gcc
76 for BTCXX
in "${phase_one}"/cross
/*/bin
/*-g++
85 # Set and compose flags to be used as CC/CXX
87 BTCC
="$BTCC -static -Wl,-Bstatic -static-libgcc"
88 BTCXX
="$BTCXX -static -Wl,-Bstatic -static-libgcc"
90 IS_DARKCRUSADE
=IS_DARKCRUSADE
92 export BTCC BTCXX IS_DARKCRUSADE
94 # Loop for create the targets, phase 2
95 for target
in ${CWD}/targets
/${@:-*}
97 target
="${target##*/}"
98 phase_two
=${output}/phase2-
${target}.$$
100 echo "darkcrusade: Making target $target ..."
101 "${CWD}"/bootstrap
-s0 -a "$target" -o "$phase_two" 2>&1 | \
102 tee "${output}/${tarname}-${target}.log"
104 # Provide log file, tarball plus checkum
106 lzip
-9 "${output}/${tarname}-${target}.log" &
107 rm -f "${output}/${tarname}-${target}.tar" \
108 "${output}/${tarname}-${target}.tar.lz"
111 ( umask 022 ; tarlz
--solid -9 -cvf - -- cross
/ ) \
112 > "${output}/${tarname}-${target}.tar.lz"
116 sha256sum
"${tarname}-${target}.tar.lz" \
117 > "${tarname}-${target}.tar.lz.sha256"
120 # Back to the current working directory