1 | #!/bin/sh
|
---|
2 | #
|
---|
3 | # SPDX-FileCopyrightText: 2019 Jiří Zárevúcky
|
---|
4 | #
|
---|
5 | # SPDX-License-Identifier: BSD-3-Clause
|
---|
6 | #
|
---|
7 |
|
---|
8 | # Find out the path to the script.
|
---|
9 | SOURCE_DIR=`which -- "$0" 2>/dev/null`
|
---|
10 | # Maybe we are running bash.
|
---|
11 | [ -z "$SOURCE_DIR" ] && SOURCE_DIR=`which -- "$BASH_SOURCE"`
|
---|
12 | [ -z "$SOURCE_DIR" ] && exit 1
|
---|
13 | SOURCE_DIR=`dirname -- "$SOURCE_DIR"`
|
---|
14 | SOURCE_DIR=`cd $SOURCE_DIR && echo $PWD`
|
---|
15 |
|
---|
16 | CONFIG_RULES="${SOURCE_DIR}/HelenOS.config"
|
---|
17 | CONFIG_DEFAULTS="${SOURCE_DIR}/defaults"
|
---|
18 |
|
---|
19 | test "$#" -eq 1 && { test "$1" = "-h" || test "$1" = "--help"; }
|
---|
20 | want_help="$?"
|
---|
21 |
|
---|
22 | if [ "$#" -gt 1 ] || [ "$want_help" -eq 0 ]; then
|
---|
23 |
|
---|
24 | # Find all the leaf subdirectories in the defaults directory.
|
---|
25 | PROFILES=`find ${CONFIG_DEFAULTS} -type d -links 2 -printf "%P\n" | sort`
|
---|
26 |
|
---|
27 | echo "Configures the current working directory as a HelenOS build directory."
|
---|
28 | echo "In-tree build is not supported, you must create a separate directory for build."
|
---|
29 | echo
|
---|
30 | echo "Usage:"
|
---|
31 | echo " $0 -h|--help"
|
---|
32 | echo " $0 [PROFILE]"
|
---|
33 | echo
|
---|
34 | echo "If profile is not specified, a graphical configuration utility is launched."
|
---|
35 | echo
|
---|
36 | echo "Possible profiles:"
|
---|
37 | printf "\t%s\n" $PROFILES
|
---|
38 | echo
|
---|
39 |
|
---|
40 | exit "$want_help"
|
---|
41 | fi
|
---|
42 |
|
---|
43 | if [ "$PWD" = "$SOURCE_DIR" ]; then
|
---|
44 | echo "We don't support in-tree build."
|
---|
45 | echo "Please create a build directory, cd into it, and run this script from there."
|
---|
46 | echo "Or run \`$0 --help\` to see usage."
|
---|
47 | exit 1
|
---|
48 | fi
|
---|
49 |
|
---|
50 | ninja_help() {
|
---|
51 | echo 'Run `ninja config` to adjust configuration.'
|
---|
52 | echo 'Run `ninja` to build all program and library binaries, but not bootable image.'
|
---|
53 | echo 'Run `ninja image_path` to build boot image. The file image_path will contain path to the boot image file.'
|
---|
54 | }
|
---|
55 |
|
---|
56 | if [ -f build.ninja ]; then
|
---|
57 | echo "This build directory was already configured."
|
---|
58 | echo
|
---|
59 | ninja_help
|
---|
60 | exit 0
|
---|
61 | fi
|
---|
62 |
|
---|
63 | if ! which meson >/dev/null 2>/dev/null; then
|
---|
64 | echo "Your system does not have Meson installed."
|
---|
65 | echo 'Please use `pip3 install meson`'
|
---|
66 | exit 1
|
---|
67 | fi
|
---|
68 |
|
---|
69 | if ! which ninja >/dev/null 2>/dev/null; then
|
---|
70 | echo "Your system does not have ninja installed."
|
---|
71 | echo 'Please use `pip3 install ninja`'
|
---|
72 | exit 1
|
---|
73 | fi
|
---|
74 |
|
---|
75 | # Link tools directory for convenience.
|
---|
76 | if [ ! -e tools ]; then
|
---|
77 | ln -s "${SOURCE_DIR}/tools" tools
|
---|
78 | fi
|
---|
79 |
|
---|
80 | # Run HelenOS config tool.
|
---|
81 | if [ "$#" -eq 1 ]; then
|
---|
82 | "${SOURCE_DIR}/tools/config.py" "${CONFIG_RULES}" "${CONFIG_DEFAULTS}" hands-off "$1" || exit 1
|
---|
83 | else
|
---|
84 | "${SOURCE_DIR}/tools/config.py" "${CONFIG_RULES}" "${CONFIG_DEFAULTS}" || exit 1
|
---|
85 | fi
|
---|
86 |
|
---|
87 | PLATFORM=`sed -n '/^PLATFORM\b/p' Makefile.config | sed 's:[^=]*= ::'`
|
---|
88 | MACHINE=`sed -n '/^MACHINE\b/p' Makefile.config | sed 's:[^=]*= ::'`
|
---|
89 |
|
---|
90 | cross_target="$PLATFORM"
|
---|
91 | if [ "$PLATFORM" = 'abs32le' ]; then
|
---|
92 | cross_target='ia32'
|
---|
93 | fi
|
---|
94 | if [ "$MACHINE" = 'bmalta' ]; then
|
---|
95 | cross_target='mips32eb'
|
---|
96 | fi
|
---|
97 |
|
---|
98 | cross_def="${SOURCE_DIR}/meson/cross/${cross_target}"
|
---|
99 | cc_arch=`sed -n "s:cc_arch = '\(.*\)':\1:p" "$cross_def"`
|
---|
100 |
|
---|
101 | compname="$cc_arch-helenos-gcc"
|
---|
102 | unset compprefix
|
---|
103 |
|
---|
104 | if which "$compname" >/dev/null 2>/dev/null; then
|
---|
105 | # Compiler is in PATH
|
---|
106 | compprefix="$cc_arch-helenos-"
|
---|
107 |
|
---|
108 | elif [ -n "$CROSS_PREFIX" ]; then
|
---|
109 | if which "$CROSS_PREFIX/bin/$compname" >/dev/null 2>/dev/null; then
|
---|
110 | compprefix="$CROSS_PREFIX/bin/$cc_arch-helenos-"
|
---|
111 | fi
|
---|
112 |
|
---|
113 | if [ -z "$compprefix" ]; then
|
---|
114 | echo "ERROR: \$CROSS_PREFIX defined but $compname is not present in $CROSS_PREFIX/bin."
|
---|
115 | echo "Run tools/toolchain.sh to build cross-compiling toolchain."
|
---|
116 | exit 1
|
---|
117 | fi
|
---|
118 | else
|
---|
119 | if [ -z "$XDG_DATA_HOME" ]; then
|
---|
120 | XDG_DATA_HOME="$HOME/.local/share"
|
---|
121 | fi
|
---|
122 |
|
---|
123 | if which "$XDG_DATA_HOME/HelenOS/cross/bin/$compname" >/dev/null 2>/dev/null; then
|
---|
124 | compprefix="$XDG_DATA_HOME/HelenOS/cross/bin/$cc_arch-helenos-"
|
---|
125 | elif which "/opt/HelenOS/cross/bin/$compname" >/dev/null 2>/dev/null; then
|
---|
126 | compprefix="/opt/HelenOS/cross/bin/$cc_arch-helenos-"
|
---|
127 | elif which "/usr/local/cross/bin/$compname" >/dev/null 2>/dev/null; then
|
---|
128 | compprefix="/usr/local/cross/bin/$cc_arch-helenos-"
|
---|
129 | fi
|
---|
130 |
|
---|
131 | if [ -z "$compprefix" ]; then
|
---|
132 | echo "ERROR: \$CROSS_PREFIX is not defined and $compname is not present in any of the following standard locations."
|
---|
133 | echo " * $XDG_DATA_HOME/HelenOS/cross/bin"
|
---|
134 | echo " * /opt/HelenOS/cross/bin"
|
---|
135 | echo " * /usr/local/cross/bin"
|
---|
136 | echo "Run tools/toolchain.sh to build cross-compiling toolchain."
|
---|
137 | exit 1
|
---|
138 | fi
|
---|
139 | fi
|
---|
140 |
|
---|
141 | sed "s:@COMPPREFIX@:$compprefix:g" "$cross_def" > crossfile || exit 1
|
---|
142 |
|
---|
143 | meson "${SOURCE_DIR}" '.' --cross-file crossfile || exit 1
|
---|
144 |
|
---|
145 | echo
|
---|
146 | echo "Configuration for platform $PLATFORM finished."
|
---|
147 | echo
|
---|
148 | ninja_help
|
---|