-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·106 lines (97 loc) · 3.02 KB
/
configure
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
#!/bin/bash
# This file is part of the KoraOS project.
# Copyright (C) 2018 <Fabien Bavent>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# This build script is generic.
set -e
function HELP {
cat << EOF
Usage: configure [OPTIONS]
with options:
--target=TARGET Triplet of the destination platform
--prefix=PREFIX Destination of final delivery
--sysdir=SYSDIR Repository of installed tools dependencies
EOF
}
TOPDIR=$(readlink -f `dirname ${BASH_SOURCE[0]}`)
GENDIR=`pwd`
PREFIX='/usr/local'
SYSDIR=''
PREFACE=''
TARGET=`$TOPDIR/make/host.sh`
if [ "$TOPDIR" == "$GENDIR" ]; then
echo "This script doesn't allow to persist build parameters on source folder" >&2
echo "Please build on another directory" >&2
echo " or use proper make command (see make/README.md" >&2
exit 1
fi
while (( $# > 0 )); do
case $1 in
--target=*) TARGET=`$TOPDIR/make/host.sh ${1:9}` ;;
--prefix=*) PREFIX=`readlink -f ${1:9}` ;;
--sysdir=*) SYSDIR=`readlink -f ${1:9}` ;;
--preface=*) PREFACE=${1:10} ;;
*) HELP; exit 1 ;;
esac
shift
done
CROSS=''
CC='gcc'
LD='ld'
if [ "$TARGET" != "`$TOPDIR/make/host.sh`" ]; then
CROSS="$TARGET-"
IFS='-' read -ra THST <<< "$TARGET"
T_ARCH=${THST[0]}
T_OS=${THST[@]:2:${#THST[@]}}
echo "Cross build - Arch: $T_ARCH - Os: $T_OS"
# echo 'Try '"$CROSS$CC"
i=0
while [ -z `which "$CROSS$CC" 2> /dev/null || true` ]; do
case $i in
0) CROSS="$T_ARCH-$T_OS-"; CC='gcc'; ;;
1) CROSS="$SYSDIR/bin/$T_ARCH-$T_OS-"; CC='gcc'; ;;
2) CROSS="$SYSDIR/usr/bin/$T_ARCH-$T_OS-"; CC='gcc'; ;;
3) CROSS="$PREFIX/bin/$T_ARCH-$T_OS-"; CC='gcc'; ;;
4) CROSS="$PREFIX/usr/bin/$T_ARCH-$T_OS-"; CC='gcc'; ;;
5)
CROSS=''; CC='';
echo "Unable to find toolchain for target $TARGET" >&2
exit 1 ;;
esac
# echo 'Try '"$CROSS$CC"
i=`expr $i + 1`
done
fi
cat > Makefile << EOF
# Configure script for $TOPDIR
# ------------------
EOF
if [ -f "$PREFACE" ]; then
cat "$PREFACE" >> Makefile
echo "# ------------------" >> Makefile
fi
cat >> Makefile << EOF
topdir:=$TOPDIR
gendir:=$GENDIR
prefix:=$PREFIX
target:=$TARGET
sysdir:=$SYSDIR
CROSS:=$CROSS
CC:=$CROSS$CC
LD:=$CROSS$LD
LDC:=$CROSS$CC
include \${topdir}/Makefile
EOF