forked from HelenOS/helenos
-
Notifications
You must be signed in to change notification settings - Fork 1
/
configure.sh
executable file
·171 lines (144 loc) · 5.6 KB
/
configure.sh
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/bin/sh
#
# Copyright (c) 2019 Jiří Zárevúcky
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# - Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# - Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# - The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Find out the path to the script.
SOURCE_DIR=`which -- "$0" 2>/dev/null`
# Maybe we are running bash.
[ -z "$SOURCE_DIR" ] && SOURCE_DIR=`which -- "$BASH_SOURCE"`
[ -z "$SOURCE_DIR" ] && exit 1
SOURCE_DIR=`dirname -- "$SOURCE_DIR"`
SOURCE_DIR=`cd $SOURCE_DIR && echo $PWD`
CONFIG_RULES="${SOURCE_DIR}/HelenOS.config"
CONFIG_DEFAULTS="${SOURCE_DIR}/defaults"
test "$#" -eq 1 && { test "$1" = "-h" || test "$1" = "--help"; }
want_help="$?"
if [ "$#" -gt 1 ] || [ "$want_help" -eq 0 ]; then
# Find all the leaf subdirectories in the defaults directory.
PROFILES=`find ${CONFIG_DEFAULTS} -type d -links 2 -printf "%P\n" | sort`
echo "Configures the current working directory as a HelenOS build directory."
echo "In-tree build is not supported, you must create a separate directory for build."
echo
echo "Usage:"
echo " $0 -h|--help"
echo " $0 [PROFILE]"
echo
echo "If profile is not specified, a graphical configuration utility is launched."
echo
echo "Possible profiles:"
printf "\t%s\n" $PROFILES
echo
exit "$want_help"
fi
if [ "$PWD" = "$SOURCE_DIR" ]; then
echo "We don't support in-tree build."
echo "Please create a build directory, cd into it, and run this script from there."
echo "Or run \`$0 --help\` to see usage."
exit 1
fi
ninja_help() {
echo 'Run `ninja config` to adjust configuration.'
echo 'Run `ninja` to build all program and library binaries, but not bootable image.'
echo 'Run `ninja image_path` to build boot image. The file image_path will contain path to the boot image file.'
}
if [ -f build.ninja ]; then
echo "This build directory was already configured."
echo
ninja_help
exit 0
fi
if ! which meson >/dev/null 2>/dev/null; then
echo "Your system does not have Meson installed."
echo 'Please use `pip3 install meson`'
exit 1
fi
if ! which ninja >/dev/null 2>/dev/null; then
echo "Your system does not have ninja installed."
echo 'Please use `pip3 install ninja`'
exit 1
fi
# Link tools directory for convenience.
if [ ! -e tools ]; then
ln -s "${SOURCE_DIR}/tools" tools
fi
# Run HelenOS config tool.
if [ "$#" -eq 1 ]; then
"${SOURCE_DIR}/tools/config.py" "${CONFIG_RULES}" "${CONFIG_DEFAULTS}" hands-off "$1" || exit 1
else
"${SOURCE_DIR}/tools/config.py" "${CONFIG_RULES}" "${CONFIG_DEFAULTS}" || exit 1
fi
PLATFORM=`sed -n '/^PLATFORM\b/p' Makefile.config | sed 's:[^=]*= ::'`
MACHINE=`sed -n '/^MACHINE\b/p' Makefile.config | sed 's:[^=]*= ::'`
cross_target="$PLATFORM"
if [ "$PLATFORM" = 'abs32le' ]; then
cross_target='ia32'
fi
if [ "$MACHINE" = 'bmalta' ]; then
cross_target='mips32eb'
fi
cross_def="${SOURCE_DIR}/meson/cross/${cross_target}"
cc_arch=`sed -n "s:cc_arch = '\(.*\)':\1:p" "$cross_def"`
compname="$cc_arch-helenos-gcc"
unset compprefix
if which "$compname" >/dev/null 2>/dev/null; then
# Compiler is in PATH
compprefix="$cc_arch-helenos-"
elif [ -n "$CROSS_PREFIX" ]; then
if which "$CROSS_PREFIX/bin/$compname" >/dev/null 2>/dev/null; then
compprefix="$CROSS_PREFIX/bin/$cc_arch-helenos-"
fi
if [ -z "$compprefix" ]; then
echo "ERROR: \$CROSS_PREFIX defined but $compname is not present in $CROSS_PREFIX/bin."
echo "Run tools/toolchain.sh to build cross-compiling toolchain."
exit 1
fi
else
if [ -z "$XDG_DATA_HOME" ]; then
XDG_DATA_HOME="$HOME/.local/share"
fi
if which "$XDG_DATA_HOME/HelenOS/cross/bin/$compname" >/dev/null 2>/dev/null; then
compprefix="$XDG_DATA_HOME/HelenOS/cross/bin/$cc_arch-helenos-"
elif which "/opt/HelenOS/cross/bin/$compname" >/dev/null 2>/dev/null; then
compprefix="/opt/HelenOS/cross/bin/$cc_arch-helenos-"
elif which "/usr/local/cross/bin/$compname" >/dev/null 2>/dev/null; then
compprefix="/usr/local/cross/bin/$cc_arch-helenos-"
fi
if [ -z "$compprefix" ]; then
echo "ERROR: \$CROSS_PREFIX is not defined and $compname is not present in any of the following standard locations."
echo " * $XDG_DATA_HOME/HelenOS/cross/bin"
echo " * /opt/HelenOS/cross/bin"
echo " * /usr/local/cross/bin"
echo "Run tools/toolchain.sh to build cross-compiling toolchain."
exit 1
fi
fi
sed "s:@COMPPREFIX@:$compprefix:g" "$cross_def" > crossfile || exit 1
meson setup "${SOURCE_DIR}" '.' --cross-file crossfile || exit 1
echo
echo "Configuration for platform $PLATFORM finished."
echo
ninja_help