recipes: tools/gptfdisk: Fix build issues
[dragora.git] / darkcrusade
blobb038e9a2be3ee4d1cd189ba4bb14fc01d1ed7a25
1 #! /bin/sh -
3 # Deploy static cross-compilers for easy distribution
5 # Copyright (c) 2016-2021 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.
19 # Exit immediately on any error
20 set -e
22 PROGRAM="${0##*/}"
24 # Show help via option
25 if test "$1" = -h || test "$1" = --help
26 then
27 echo "Usage: $PROGRAM [TARGET]..."
28 echo "Deploy static cross-compilers for easy distribution."
29 echo ""
30 echo "Where TARGET is any target found at the targets/ directory."
31 echo "If no target name is passed, all available targets will be built."
32 echo ""
33 exit 0;
36 # Override locale settings
37 LC_ALL=C
38 export LC_ALL
40 umask 022
42 ### Default values
44 # Get physical working directory (absolute path)
45 CWD="$(CDPATH='' cd -P -- "$(dirname -- "$0")" && pwd -P)"
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 yearNumber+monthName+dayNumber
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)-$(date +%Y-%m-%d.%H%M%S)-$$"
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/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##*/}"
99 phase_two="${output}/phase2-${target}-$(date +%Y-%m-%d.%H%M%S)-$$"
101 # Build target against native compiler, logging its output
103 echo "darkcrusade: Making target $target ..."
104 rm -f "${output}/bootstrapfailed"
107 "${CWD}"/bootstrap -s0 -a "$target" -o "$phase_two" || touch "${output}/bootstrapfailed"
108 } 2>&1 | tee "${output}/${tarname}-${target}.log"
110 if test -f "${output}/bootstrapfailed"
111 then
112 echo "${PROGRAM}: An error occurred while processing the target: $target" 1>&2
113 echo " Please check the log file ${output}/${tarname}-${target}.log" 1>&2
114 exit 99;
117 # Provide log file, tarball and checkum
119 lzip -9 "${output}/${tarname}-${target}.log" &
122 cd -- "$phase_two" && \
123 tarlz --solid -9 -cvf - -- cross/ \
124 > "${output}/${tarname}-${target}.tar.lz"
127 cd -- "$output" && \
128 sha256sum "${tarname}-${target}.tar.lz" \
129 > "${tarname}-${target}.tar.lz.sha256"
131 done