source: mainline/configure.sh@ 4dd3912

Last change on this file since 4dd3912 was 8fd0675f, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 3 years ago

Update files with /bin/sh shebang and an extra space

  • Property mode set to 100755
File size: 4.3 KB
RevLine 
[18b1643]1#!/bin/sh
[c21d4d6]2#
[8fd0675f]3# SPDX-FileCopyrightText: 2019 Jiří Zárevúcky
[c21d4d6]4#
[8fd0675f]5# SPDX-License-Identifier: BSD-3-Clause
[c21d4d6]6#
7
[18b1643]8# Find out the path to the script.
9SOURCE_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
13SOURCE_DIR=`dirname -- "$SOURCE_DIR"`
14SOURCE_DIR=`cd $SOURCE_DIR && echo $PWD`
15
16CONFIG_RULES="${SOURCE_DIR}/HelenOS.config"
17CONFIG_DEFAULTS="${SOURCE_DIR}/defaults"
18
19test "$#" -eq 1 && { test "$1" = "-h" || test "$1" = "--help"; }
20want_help="$?"
21
22if [ "$#" -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
[e3737eda]38 echo
[18b1643]39
40 exit "$want_help"
41fi
42
43if [ "$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
48fi
49
50ninja_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
56if [ -f build.ninja ]; then
57 echo "This build directory was already configured."
58 echo
59 ninja_help
60 exit 0
61fi
62
[f3a7b0d]63if ! which meson >/dev/null 2>/dev/null; then
[08c851ce]64 echo "Your system does not have Meson installed."
65 echo 'Please use `pip3 install meson`'
[1c39d33b]66 exit 1
[08c851ce]67fi
68
[f3a7b0d]69if ! which ninja >/dev/null 2>/dev/null; then
[08c851ce]70 echo "Your system does not have ninja installed."
71 echo 'Please use `pip3 install ninja`'
[1c39d33b]72 exit 1
[08c851ce]73fi
74
[2db5c83]75# Link tools directory for convenience.
[f3a7b0d]76if [ ! -e tools ]; then
77 ln -s "${SOURCE_DIR}/tools" tools
78fi
[2db5c83]79
[18b1643]80# Run HelenOS config tool.
81if [ "$#" -eq 1 ]; then
82 "${SOURCE_DIR}/tools/config.py" "${CONFIG_RULES}" "${CONFIG_DEFAULTS}" hands-off "$1" || exit 1
83else
84 "${SOURCE_DIR}/tools/config.py" "${CONFIG_RULES}" "${CONFIG_DEFAULTS}" || exit 1
85fi
86
87PLATFORM=`sed -n '/^PLATFORM\b/p' Makefile.config | sed 's:[^=]*= ::'`
88MACHINE=`sed -n '/^MACHINE\b/p' Makefile.config | sed 's:[^=]*= ::'`
89
90cross_target="$PLATFORM"
91if [ "$PLATFORM" = 'abs32le' ]; then
92 cross_target='ia32'
93fi
94if [ "$MACHINE" = 'bmalta' ]; then
95 cross_target='mips32eb'
96fi
97
[a42be38]98cross_def="${SOURCE_DIR}/meson/cross/${cross_target}"
99cc_arch=`sed -n "s:cc_arch = '\(.*\)':\1:p" "$cross_def"`
100
101compname="$cc_arch-helenos-gcc"
[f3a7b0d]102unset compprefix
[a42be38]103
[f3a7b0d]104if which "$compname" >/dev/null 2>/dev/null; then
[a42be38]105 # Compiler is in PATH
106 compprefix="$cc_arch-helenos-"
107
108elif [ -n "$CROSS_PREFIX" ]; then
[f3a7b0d]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
[a42be38]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
118else
[f3a7b0d]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"
[a42be38]136 echo "Run tools/toolchain.sh to build cross-compiling toolchain."
137 exit 1
138 fi
139fi
140
141sed "s:@COMPPREFIX@:$compprefix:g" "$cross_def" > crossfile || exit 1
142
143meson "${SOURCE_DIR}" '.' --cross-file crossfile || exit 1
[18b1643]144
145echo
146echo "Configuration for platform $PLATFORM finished."
147echo
148ninja_help
Note: See TracBrowser for help on using the repository browser.