1c8a0e2f4SThomas Veerman#! /usr/bin/env sh 2*0a6a1f1dSLionel Sambuc# $NetBSD: build.sh,v 1.308 2015/06/27 06:00:28 matt Exp $ 3c8a0e2f4SThomas Veerman# 4c8a0e2f4SThomas Veerman# Copyright (c) 2001-2011 The NetBSD Foundation, Inc. 5c8a0e2f4SThomas Veerman# All rights reserved. 6c8a0e2f4SThomas Veerman# 7c8a0e2f4SThomas Veerman# This code is derived from software contributed to The NetBSD Foundation 8c8a0e2f4SThomas Veerman# by Todd Vierling and Luke Mewburn. 9c8a0e2f4SThomas Veerman# 10c8a0e2f4SThomas Veerman# Redistribution and use in source and binary forms, with or without 11c8a0e2f4SThomas Veerman# modification, are permitted provided that the following conditions 12c8a0e2f4SThomas Veerman# are met: 13c8a0e2f4SThomas Veerman# 1. Redistributions of source code must retain the above copyright 14c8a0e2f4SThomas Veerman# notice, this list of conditions and the following disclaimer. 15c8a0e2f4SThomas Veerman# 2. Redistributions in binary form must reproduce the above copyright 16c8a0e2f4SThomas Veerman# notice, this list of conditions and the following disclaimer in the 17c8a0e2f4SThomas Veerman# documentation and/or other materials provided with the distribution. 18c8a0e2f4SThomas Veerman# 19c8a0e2f4SThomas Veerman# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20c8a0e2f4SThomas Veerman# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21c8a0e2f4SThomas Veerman# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22c8a0e2f4SThomas Veerman# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23c8a0e2f4SThomas Veerman# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24c8a0e2f4SThomas Veerman# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25c8a0e2f4SThomas Veerman# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26c8a0e2f4SThomas Veerman# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27c8a0e2f4SThomas Veerman# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28c8a0e2f4SThomas Veerman# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29c8a0e2f4SThomas Veerman# POSSIBILITY OF SUCH DAMAGE. 30c8a0e2f4SThomas Veerman# 31c8a0e2f4SThomas Veerman# 32c8a0e2f4SThomas Veerman# Top level build wrapper, to build or cross-build NetBSD. 33c8a0e2f4SThomas Veerman# 34c8a0e2f4SThomas Veerman 35c8a0e2f4SThomas Veerman# 36c8a0e2f4SThomas Veerman# {{{ Begin shell feature tests. 37c8a0e2f4SThomas Veerman# 38c8a0e2f4SThomas Veerman# We try to determine whether or not this script is being run under 39c8a0e2f4SThomas Veerman# a shell that supports the features that we use. If not, we try to 40c8a0e2f4SThomas Veerman# re-exec the script under another shell. If we can't find another 41c8a0e2f4SThomas Veerman# suitable shell, then we print a message and exit. 42c8a0e2f4SThomas Veerman# 43c8a0e2f4SThomas Veerman 44c8a0e2f4SThomas Veermanerrmsg='' # error message, if not empty 45c8a0e2f4SThomas Veermanshelltest=false # if true, exit after testing the shell 46c8a0e2f4SThomas Veermanre_exec_allowed=true # if true, we may exec under another shell 47c8a0e2f4SThomas Veerman 48c8a0e2f4SThomas Veerman# Parse special command line options in $1. These special options are 49c8a0e2f4SThomas Veerman# for internal use only, are not documented, and are not valid anywhere 50c8a0e2f4SThomas Veerman# other than $1. 51c8a0e2f4SThomas Veermancase "$1" in 52c8a0e2f4SThomas Veerman"--shelltest") 53c8a0e2f4SThomas Veerman shelltest=true 54c8a0e2f4SThomas Veerman re_exec_allowed=false 55c8a0e2f4SThomas Veerman shift 56c8a0e2f4SThomas Veerman ;; 57c8a0e2f4SThomas Veerman"--no-re-exec") 58c8a0e2f4SThomas Veerman re_exec_allowed=false 59c8a0e2f4SThomas Veerman shift 60c8a0e2f4SThomas Veerman ;; 61c8a0e2f4SThomas Veermanesac 62c8a0e2f4SThomas Veerman 63c8a0e2f4SThomas Veerman# Solaris /bin/sh, and other SVR4 shells, do not support "!". 64c8a0e2f4SThomas Veerman# This is the first feature that we test, because subsequent 65c8a0e2f4SThomas Veerman# tests use "!". 66c8a0e2f4SThomas Veerman# 67c8a0e2f4SThomas Veermanif test -z "$errmsg"; then 68c8a0e2f4SThomas Veerman if ( eval '! false' ) >/dev/null 2>&1 ; then 69c8a0e2f4SThomas Veerman : 70c8a0e2f4SThomas Veerman else 71c8a0e2f4SThomas Veerman errmsg='Shell does not support "!".' 72c8a0e2f4SThomas Veerman fi 73c8a0e2f4SThomas Veermanfi 74c8a0e2f4SThomas Veerman 75c8a0e2f4SThomas Veerman# Does the shell support functions? 76c8a0e2f4SThomas Veerman# 77c8a0e2f4SThomas Veermanif test -z "$errmsg"; then 78c8a0e2f4SThomas Veerman if ! ( 79c8a0e2f4SThomas Veerman eval 'somefunction() { : ; }' 80c8a0e2f4SThomas Veerman ) >/dev/null 2>&1 81c8a0e2f4SThomas Veerman then 82c8a0e2f4SThomas Veerman errmsg='Shell does not support functions.' 83c8a0e2f4SThomas Veerman fi 84c8a0e2f4SThomas Veermanfi 85c8a0e2f4SThomas Veerman 86c8a0e2f4SThomas Veerman# Does the shell support the "local" keyword for variables in functions? 87c8a0e2f4SThomas Veerman# 88c8a0e2f4SThomas Veerman# Local variables are not required by SUSv3, but some scripts run during 89c8a0e2f4SThomas Veerman# the NetBSD build use them. 90c8a0e2f4SThomas Veerman# 91c8a0e2f4SThomas Veerman# ksh93 fails this test; it uses an incompatible syntax involving the 92c8a0e2f4SThomas Veerman# keywords 'function' and 'typeset'. 93c8a0e2f4SThomas Veerman# 94c8a0e2f4SThomas Veermanif test -z "$errmsg"; then 95c8a0e2f4SThomas Veerman if ! ( 96c8a0e2f4SThomas Veerman eval 'f() { local v=2; }; v=1; f && test x"$v" = x"1"' 97c8a0e2f4SThomas Veerman ) >/dev/null 2>&1 98c8a0e2f4SThomas Veerman then 99c8a0e2f4SThomas Veerman errmsg='Shell does not support the "local" keyword in functions.' 100c8a0e2f4SThomas Veerman fi 101c8a0e2f4SThomas Veermanfi 102c8a0e2f4SThomas Veerman 103c8a0e2f4SThomas Veerman# Does the shell support ${var%suffix}, ${var#prefix}, and their variants? 104c8a0e2f4SThomas Veerman# 105c8a0e2f4SThomas Veerman# We don't bother testing for ${var+value}, ${var-value}, or their variants, 106c8a0e2f4SThomas Veerman# since shells without those are sure to fail other tests too. 107c8a0e2f4SThomas Veerman# 108c8a0e2f4SThomas Veermanif test -z "$errmsg"; then 109c8a0e2f4SThomas Veerman if ! ( 110c8a0e2f4SThomas Veerman eval 'var=a/b/c ; 111c8a0e2f4SThomas Veerman test x"${var#*/};${var##*/};${var%/*};${var%%/*}" = \ 112c8a0e2f4SThomas Veerman x"b/c;c;a/b;a" ;' 113c8a0e2f4SThomas Veerman ) >/dev/null 2>&1 114c8a0e2f4SThomas Veerman then 115c8a0e2f4SThomas Veerman errmsg='Shell does not support "${var%suffix}" or "${var#prefix}".' 116c8a0e2f4SThomas Veerman fi 117c8a0e2f4SThomas Veermanfi 118c8a0e2f4SThomas Veerman 119c8a0e2f4SThomas Veerman# Does the shell support IFS? 120c8a0e2f4SThomas Veerman# 121c8a0e2f4SThomas Veerman# zsh in normal mode (as opposed to "emulate sh" mode) fails this test. 122c8a0e2f4SThomas Veerman# 123c8a0e2f4SThomas Veermanif test -z "$errmsg"; then 124c8a0e2f4SThomas Veerman if ! ( 125c8a0e2f4SThomas Veerman eval 'IFS=: ; v=":a b::c" ; set -- $v ; IFS=+ ; 126c8a0e2f4SThomas Veerman test x"$#;$1,$2,$3,$4;$*" = x"4;,a b,,c;+a b++c"' 127c8a0e2f4SThomas Veerman ) >/dev/null 2>&1 128c8a0e2f4SThomas Veerman then 129c8a0e2f4SThomas Veerman errmsg='Shell does not support IFS word splitting.' 130c8a0e2f4SThomas Veerman fi 131c8a0e2f4SThomas Veermanfi 132c8a0e2f4SThomas Veerman 133c8a0e2f4SThomas Veerman# Does the shell support ${1+"$@"}? 134c8a0e2f4SThomas Veerman# 135c8a0e2f4SThomas Veerman# Some versions of zsh fail this test, even in "emulate sh" mode. 136c8a0e2f4SThomas Veerman# 137c8a0e2f4SThomas Veermanif test -z "$errmsg"; then 138c8a0e2f4SThomas Veerman if ! ( 139c8a0e2f4SThomas Veerman eval 'set -- "a a a" "b b b"; set -- ${1+"$@"}; 140c8a0e2f4SThomas Veerman test x"$#;$1;$2" = x"2;a a a;b b b";' 141c8a0e2f4SThomas Veerman ) >/dev/null 2>&1 142c8a0e2f4SThomas Veerman then 143c8a0e2f4SThomas Veerman errmsg='Shell does not support ${1+"$@"}.' 144c8a0e2f4SThomas Veerman fi 145c8a0e2f4SThomas Veermanfi 146c8a0e2f4SThomas Veerman 147c8a0e2f4SThomas Veerman# Does the shell support $(...) command substitution? 148c8a0e2f4SThomas Veerman# 149c8a0e2f4SThomas Veermanif test -z "$errmsg"; then 150c8a0e2f4SThomas Veerman if ! ( 151c8a0e2f4SThomas Veerman eval 'var=$(echo abc); test x"$var" = x"abc"' 152c8a0e2f4SThomas Veerman ) >/dev/null 2>&1 153c8a0e2f4SThomas Veerman then 154c8a0e2f4SThomas Veerman errmsg='Shell does not support "$(...)" command substitution.' 155c8a0e2f4SThomas Veerman fi 156c8a0e2f4SThomas Veermanfi 157c8a0e2f4SThomas Veerman 158c8a0e2f4SThomas Veerman# Does the shell support $(...) command substitution with 159c8a0e2f4SThomas Veerman# unbalanced parentheses? 160c8a0e2f4SThomas Veerman# 161c8a0e2f4SThomas Veerman# Some shells known to fail this test are: NetBSD /bin/ksh (as of 2009-12), 162c8a0e2f4SThomas Veerman# bash-3.1, pdksh-5.2.14, zsh-4.2.7 in "emulate sh" mode. 163c8a0e2f4SThomas Veerman# 164c8a0e2f4SThomas Veermanif test -z "$errmsg"; then 165c8a0e2f4SThomas Veerman if ! ( 166c8a0e2f4SThomas Veerman eval 'var=$(case x in x) echo abc;; esac); test x"$var" = x"abc"' 167c8a0e2f4SThomas Veerman ) >/dev/null 2>&1 168c8a0e2f4SThomas Veerman then 169c8a0e2f4SThomas Veerman # XXX: This test is ignored because so many shells fail it; instead, 170c8a0e2f4SThomas Veerman # the NetBSD build avoids using the problematic construct. 171c8a0e2f4SThomas Veerman : ignore 'Shell does not support "$(...)" with unbalanced ")".' 172c8a0e2f4SThomas Veerman fi 173c8a0e2f4SThomas Veermanfi 174c8a0e2f4SThomas Veerman 175c8a0e2f4SThomas Veerman# Does the shell support getopts or getopt? 176c8a0e2f4SThomas Veerman# 177c8a0e2f4SThomas Veermanif test -z "$errmsg"; then 178c8a0e2f4SThomas Veerman if ! ( 179c8a0e2f4SThomas Veerman eval 'type getopts || type getopt' 180c8a0e2f4SThomas Veerman ) >/dev/null 2>&1 181c8a0e2f4SThomas Veerman then 182c8a0e2f4SThomas Veerman errmsg='Shell does not support getopts or getopt.' 183c8a0e2f4SThomas Veerman fi 184c8a0e2f4SThomas Veermanfi 185c8a0e2f4SThomas Veerman 186c8a0e2f4SThomas Veerman# 187c8a0e2f4SThomas Veerman# If shelltest is true, exit now, reporting whether or not the shell is good. 188c8a0e2f4SThomas Veerman# 189c8a0e2f4SThomas Veermanif $shelltest; then 190c8a0e2f4SThomas Veerman if test -n "$errmsg"; then 191c8a0e2f4SThomas Veerman echo >&2 "$0: $errmsg" 192c8a0e2f4SThomas Veerman exit 1 193c8a0e2f4SThomas Veerman else 194c8a0e2f4SThomas Veerman exit 0 195c8a0e2f4SThomas Veerman fi 196c8a0e2f4SThomas Veermanfi 197c8a0e2f4SThomas Veerman 198c8a0e2f4SThomas Veerman# 199c8a0e2f4SThomas Veerman# If the shell was bad, try to exec a better shell, or report an error. 200c8a0e2f4SThomas Veerman# 201c8a0e2f4SThomas Veerman# Loops are broken by passing an extra "--no-re-exec" flag to the new 202c8a0e2f4SThomas Veerman# instance of this script. 203c8a0e2f4SThomas Veerman# 204c8a0e2f4SThomas Veermanif test -n "$errmsg"; then 205c8a0e2f4SThomas Veerman if $re_exec_allowed; then 206c8a0e2f4SThomas Veerman for othershell in \ 207*0a6a1f1dSLionel Sambuc "${HOST_SH}" /usr/xpg4/bin/sh ksh ksh88 mksh pdksh dash bash 208c8a0e2f4SThomas Veerman # NOTE: some shells known not to work are: 209c8a0e2f4SThomas Veerman # any shell using csh syntax; 210c8a0e2f4SThomas Veerman # Solaris /bin/sh (missing many modern features); 211c8a0e2f4SThomas Veerman # ksh93 (incompatible syntax for local variables); 212c8a0e2f4SThomas Veerman # zsh (many differences, unless run in compatibility mode). 213c8a0e2f4SThomas Veerman do 214c8a0e2f4SThomas Veerman test -n "$othershell" || continue 215c8a0e2f4SThomas Veerman if eval 'type "$othershell"' >/dev/null 2>&1 \ 216c8a0e2f4SThomas Veerman && "$othershell" "$0" --shelltest >/dev/null 2>&1 217c8a0e2f4SThomas Veerman then 218c8a0e2f4SThomas Veerman cat <<EOF 219c8a0e2f4SThomas Veerman$0: $errmsg 220c8a0e2f4SThomas Veerman$0: Retrying under $othershell 221c8a0e2f4SThomas VeermanEOF 222c8a0e2f4SThomas Veerman HOST_SH="$othershell" 223c8a0e2f4SThomas Veerman export HOST_SH 224c8a0e2f4SThomas Veerman exec $othershell "$0" --no-re-exec "$@" # avoid ${1+"$@"} 225c8a0e2f4SThomas Veerman fi 226c8a0e2f4SThomas Veerman # If HOST_SH was set, but failed the test above, 227c8a0e2f4SThomas Veerman # then give up without trying any other shells. 228c8a0e2f4SThomas Veerman test x"${othershell}" = x"${HOST_SH}" && break 229c8a0e2f4SThomas Veerman done 230c8a0e2f4SThomas Veerman fi 231c8a0e2f4SThomas Veerman 232c8a0e2f4SThomas Veerman # 233c8a0e2f4SThomas Veerman # If we get here, then the shell is bad, and we either could not 234c8a0e2f4SThomas Veerman # find a replacement, or were not allowed to try a replacement. 235c8a0e2f4SThomas Veerman # 236c8a0e2f4SThomas Veerman cat <<EOF 237c8a0e2f4SThomas Veerman$0: $errmsg 238c8a0e2f4SThomas Veerman 239c8a0e2f4SThomas VeermanThe NetBSD build system requires a shell that supports modern POSIX 240c8a0e2f4SThomas Veermanfeatures, as well as the "local" keyword in functions (which is a 241c8a0e2f4SThomas Veermanwidely-implemented but non-standardised feature). 242c8a0e2f4SThomas Veerman 243c8a0e2f4SThomas VeermanPlease re-run this script under a suitable shell. For example: 244c8a0e2f4SThomas Veerman 245c8a0e2f4SThomas Veerman /path/to/suitable/shell $0 ... 246c8a0e2f4SThomas Veerman 247c8a0e2f4SThomas VeermanThe above command will usually enable build.sh to automatically set 248c8a0e2f4SThomas VeermanHOST_SH=/path/to/suitable/shell, but if that fails, then you may also 249c8a0e2f4SThomas Veermanneed to explicitly set the HOST_SH environment variable, as follows: 250c8a0e2f4SThomas Veerman 251c8a0e2f4SThomas Veerman HOST_SH=/path/to/suitable/shell 252c8a0e2f4SThomas Veerman export HOST_SH 253c8a0e2f4SThomas Veerman \${HOST_SH} $0 ... 254c8a0e2f4SThomas VeermanEOF 255c8a0e2f4SThomas Veerman exit 1 256c8a0e2f4SThomas Veermanfi 257c8a0e2f4SThomas Veerman 258c8a0e2f4SThomas Veerman# 259c8a0e2f4SThomas Veerman# }}} End shell feature tests. 260c8a0e2f4SThomas Veerman# 261c8a0e2f4SThomas Veerman 262c8a0e2f4SThomas Veermanprogname=${0##*/} 263c8a0e2f4SThomas Veermantoppid=$$ 264c8a0e2f4SThomas Veermanresults=/dev/null 265c8a0e2f4SThomas Veermantab=' ' 26684d9c625SLionel Sambucnl=' 26784d9c625SLionel Sambuc' 268c8a0e2f4SThomas Veermantrap "exit 1" 1 2 3 15 269c8a0e2f4SThomas Veerman 270c8a0e2f4SThomas Veermanbomb() 271c8a0e2f4SThomas Veerman{ 272c8a0e2f4SThomas Veerman cat >&2 <<ERRORMESSAGE 273c8a0e2f4SThomas Veerman 274c8a0e2f4SThomas VeermanERROR: $@ 275c8a0e2f4SThomas Veerman*** BUILD ABORTED *** 276c8a0e2f4SThomas VeermanERRORMESSAGE 277c8a0e2f4SThomas Veerman kill ${toppid} # in case we were invoked from a subshell 278c8a0e2f4SThomas Veerman exit 1 279c8a0e2f4SThomas Veerman} 280c8a0e2f4SThomas Veerman 281*0a6a1f1dSLionel Sambuc# Quote args to make them safe in the shell. 282*0a6a1f1dSLionel Sambuc# Usage: quotedlist="$(shell_quote args...)" 283*0a6a1f1dSLionel Sambuc# 284*0a6a1f1dSLionel Sambuc# After building up a quoted list, use it by evaling it inside 285*0a6a1f1dSLionel Sambuc# double quotes, like this: 286*0a6a1f1dSLionel Sambuc# eval "set -- $quotedlist" 287*0a6a1f1dSLionel Sambuc# or like this: 288*0a6a1f1dSLionel Sambuc# eval "\$command $quotedlist \$filename" 289*0a6a1f1dSLionel Sambuc# 290*0a6a1f1dSLionel Sambucshell_quote() 291*0a6a1f1dSLionel Sambuc{( 292*0a6a1f1dSLionel Sambuc local result='' 293*0a6a1f1dSLionel Sambuc local arg qarg 294*0a6a1f1dSLionel Sambuc LC_COLLATE=C ; export LC_COLLATE # so [a-zA-Z0-9] works in ASCII 295*0a6a1f1dSLionel Sambuc for arg in "$@" ; do 296*0a6a1f1dSLionel Sambuc case "${arg}" in 297*0a6a1f1dSLionel Sambuc '') 298*0a6a1f1dSLionel Sambuc qarg="''" 299*0a6a1f1dSLionel Sambuc ;; 300*0a6a1f1dSLionel Sambuc *[!-./a-zA-Z0-9]*) 301*0a6a1f1dSLionel Sambuc # Convert each embedded ' to '\'', 302*0a6a1f1dSLionel Sambuc # then insert ' at the beginning of the first line, 303*0a6a1f1dSLionel Sambuc # and append ' at the end of the last line. 304*0a6a1f1dSLionel Sambuc # Finally, elide unnecessary '' pairs at the 305*0a6a1f1dSLionel Sambuc # beginning and end of the result and as part of 306*0a6a1f1dSLionel Sambuc # '\'''\'' sequences that result from multiple 307*0a6a1f1dSLionel Sambuc # adjacent quotes in he input. 308*0a6a1f1dSLionel Sambuc qarg="$(printf "%s\n" "$arg" | \ 309*0a6a1f1dSLionel Sambuc ${SED:-sed} -e "s/'/'\\\\''/g" \ 310*0a6a1f1dSLionel Sambuc -e "1s/^/'/" -e "\$s/\$/'/" \ 311*0a6a1f1dSLionel Sambuc -e "1s/^''//" -e "\$s/''\$//" \ 312*0a6a1f1dSLionel Sambuc -e "s/'''/'/g" 313*0a6a1f1dSLionel Sambuc )" 314*0a6a1f1dSLionel Sambuc ;; 315*0a6a1f1dSLionel Sambuc *) 316*0a6a1f1dSLionel Sambuc # Arg is not the empty string, and does not contain 317*0a6a1f1dSLionel Sambuc # any unsafe characters. Leave it unchanged for 318*0a6a1f1dSLionel Sambuc # readability. 319*0a6a1f1dSLionel Sambuc qarg="${arg}" 320*0a6a1f1dSLionel Sambuc ;; 321*0a6a1f1dSLionel Sambuc esac 322*0a6a1f1dSLionel Sambuc result="${result}${result:+ }${qarg}" 323*0a6a1f1dSLionel Sambuc done 324*0a6a1f1dSLionel Sambuc printf "%s\n" "$result" 325*0a6a1f1dSLionel Sambuc)} 326c8a0e2f4SThomas Veerman 327c8a0e2f4SThomas Veermanstatusmsg() 328c8a0e2f4SThomas Veerman{ 329c8a0e2f4SThomas Veerman ${runcmd} echo "===> $@" | tee -a "${results}" 330c8a0e2f4SThomas Veerman} 331c8a0e2f4SThomas Veerman 332c8a0e2f4SThomas Veermanstatusmsg2() 333c8a0e2f4SThomas Veerman{ 334c8a0e2f4SThomas Veerman local msg 335c8a0e2f4SThomas Veerman 336c8a0e2f4SThomas Veerman msg="${1}" 337c8a0e2f4SThomas Veerman shift 338c8a0e2f4SThomas Veerman case "${msg}" in 339c8a0e2f4SThomas Veerman ????????????????*) ;; 340c8a0e2f4SThomas Veerman ??????????*) msg="${msg} ";; 341c8a0e2f4SThomas Veerman ?????*) msg="${msg} ";; 342c8a0e2f4SThomas Veerman *) msg="${msg} ";; 343c8a0e2f4SThomas Veerman esac 344c8a0e2f4SThomas Veerman case "${msg}" in 345c8a0e2f4SThomas Veerman ?????????????????????*) ;; 346c8a0e2f4SThomas Veerman ????????????????????) msg="${msg} ";; 347c8a0e2f4SThomas Veerman ???????????????????) msg="${msg} ";; 348c8a0e2f4SThomas Veerman ??????????????????) msg="${msg} ";; 349c8a0e2f4SThomas Veerman ?????????????????) msg="${msg} ";; 350c8a0e2f4SThomas Veerman ????????????????) msg="${msg} ";; 351c8a0e2f4SThomas Veerman esac 352c8a0e2f4SThomas Veerman statusmsg "${msg}$*" 353c8a0e2f4SThomas Veerman} 354c8a0e2f4SThomas Veerman 355c8a0e2f4SThomas Veermanwarning() 356c8a0e2f4SThomas Veerman{ 357c8a0e2f4SThomas Veerman statusmsg "Warning: $@" 358c8a0e2f4SThomas Veerman} 359c8a0e2f4SThomas Veerman 360c8a0e2f4SThomas Veerman# Find a program in the PATH, and print the result. If not found, 361c8a0e2f4SThomas Veerman# print a default. If $2 is defined (even if it is an empty string), 362c8a0e2f4SThomas Veerman# then that is the default; otherwise, $1 is used as the default. 363c8a0e2f4SThomas Veermanfind_in_PATH() 364c8a0e2f4SThomas Veerman{ 365c8a0e2f4SThomas Veerman local prog="$1" 366c8a0e2f4SThomas Veerman local result="${2-"$1"}" 367c8a0e2f4SThomas Veerman local oldIFS="${IFS}" 368c8a0e2f4SThomas Veerman local dir 369c8a0e2f4SThomas Veerman IFS=":" 370c8a0e2f4SThomas Veerman for dir in ${PATH}; do 371c8a0e2f4SThomas Veerman if [ -x "${dir}/${prog}" ]; then 372c8a0e2f4SThomas Veerman result="${dir}/${prog}" 373c8a0e2f4SThomas Veerman break 374c8a0e2f4SThomas Veerman fi 375c8a0e2f4SThomas Veerman done 376c8a0e2f4SThomas Veerman IFS="${oldIFS}" 377c8a0e2f4SThomas Veerman echo "${result}" 378c8a0e2f4SThomas Veerman} 379c8a0e2f4SThomas Veerman 380c8a0e2f4SThomas Veerman# Try to find a working POSIX shell, and set HOST_SH to refer to it. 381c8a0e2f4SThomas Veerman# Assumes that uname_s, uname_m, and PWD have been set. 382c8a0e2f4SThomas Veermanset_HOST_SH() 383c8a0e2f4SThomas Veerman{ 384c8a0e2f4SThomas Veerman # Even if ${HOST_SH} is already defined, we still do the 385c8a0e2f4SThomas Veerman # sanity checks at the end. 386c8a0e2f4SThomas Veerman 387c8a0e2f4SThomas Veerman # Solaris has /usr/xpg4/bin/sh. 388c8a0e2f4SThomas Veerman # 389c8a0e2f4SThomas Veerman [ -z "${HOST_SH}" ] && [ x"${uname_s}" = x"SunOS" ] && \ 390c8a0e2f4SThomas Veerman [ -x /usr/xpg4/bin/sh ] && HOST_SH="/usr/xpg4/bin/sh" 391c8a0e2f4SThomas Veerman 392c8a0e2f4SThomas Veerman # Try to get the name of the shell that's running this script, 393c8a0e2f4SThomas Veerman # by parsing the output from "ps". We assume that, if the host 394c8a0e2f4SThomas Veerman # system's ps command supports -o comm at all, it will do so 395c8a0e2f4SThomas Veerman # in the usual way: a one-line header followed by a one-line 396c8a0e2f4SThomas Veerman # result, possibly including trailing white space. And if the 397c8a0e2f4SThomas Veerman # host system's ps command doesn't support -o comm, we assume 398c8a0e2f4SThomas Veerman # that we'll get an error message on stderr and nothing on 399c8a0e2f4SThomas Veerman # stdout. (We don't try to use ps -o 'comm=' to suppress the 400c8a0e2f4SThomas Veerman # header line, because that is less widely supported.) 401c8a0e2f4SThomas Veerman # 402c8a0e2f4SThomas Veerman # If we get the wrong result here, the user can override it by 403c8a0e2f4SThomas Veerman # specifying HOST_SH in the environment. 404c8a0e2f4SThomas Veerman # 405c8a0e2f4SThomas Veerman [ -z "${HOST_SH}" ] && HOST_SH="$( 406c8a0e2f4SThomas Veerman (ps -p $$ -o comm | sed -ne "2s/[ ${tab}]*\$//p") 2>/dev/null )" 407c8a0e2f4SThomas Veerman 408c8a0e2f4SThomas Veerman # If nothing above worked, use "sh". We will later find the 409c8a0e2f4SThomas Veerman # first directory in the PATH that has a "sh" program. 410c8a0e2f4SThomas Veerman # 411c8a0e2f4SThomas Veerman [ -z "${HOST_SH}" ] && HOST_SH="sh" 412c8a0e2f4SThomas Veerman 413c8a0e2f4SThomas Veerman # If the result so far is not an absolute path, try to prepend 414c8a0e2f4SThomas Veerman # PWD or search the PATH. 415c8a0e2f4SThomas Veerman # 416c8a0e2f4SThomas Veerman case "${HOST_SH}" in 417c8a0e2f4SThomas Veerman /*) : 418c8a0e2f4SThomas Veerman ;; 419c8a0e2f4SThomas Veerman */*) HOST_SH="${PWD}/${HOST_SH}" 420c8a0e2f4SThomas Veerman ;; 421c8a0e2f4SThomas Veerman *) HOST_SH="$(find_in_PATH "${HOST_SH}")" 422c8a0e2f4SThomas Veerman ;; 423c8a0e2f4SThomas Veerman esac 424c8a0e2f4SThomas Veerman 425c8a0e2f4SThomas Veerman # If we don't have an absolute path by now, bomb. 426c8a0e2f4SThomas Veerman # 427c8a0e2f4SThomas Veerman case "${HOST_SH}" in 428c8a0e2f4SThomas Veerman /*) : 429c8a0e2f4SThomas Veerman ;; 430c8a0e2f4SThomas Veerman *) bomb "HOST_SH=\"${HOST_SH}\" is not an absolute path." 431c8a0e2f4SThomas Veerman ;; 432c8a0e2f4SThomas Veerman esac 433c8a0e2f4SThomas Veerman 434c8a0e2f4SThomas Veerman # If HOST_SH is not executable, bomb. 435c8a0e2f4SThomas Veerman # 436c8a0e2f4SThomas Veerman [ -x "${HOST_SH}" ] || 437c8a0e2f4SThomas Veerman bomb "HOST_SH=\"${HOST_SH}\" is not executable." 438c8a0e2f4SThomas Veerman 439c8a0e2f4SThomas Veerman # If HOST_SH fails tests, bomb. 440c8a0e2f4SThomas Veerman # ("$0" may be a path that is no longer valid, because we have 441c8a0e2f4SThomas Veerman # performed "cd $(dirname $0)", so don't use $0 here.) 442c8a0e2f4SThomas Veerman # 443c8a0e2f4SThomas Veerman "${HOST_SH}" build.sh --shelltest || 444c8a0e2f4SThomas Veerman bomb "HOST_SH=\"${HOST_SH}\" failed functionality tests." 445c8a0e2f4SThomas Veerman} 446c8a0e2f4SThomas Veerman 447c8a0e2f4SThomas Veerman# initdefaults -- 448c8a0e2f4SThomas Veerman# Set defaults before parsing command line options. 449c8a0e2f4SThomas Veerman# 450c8a0e2f4SThomas Veermaninitdefaults() 451c8a0e2f4SThomas Veerman{ 452c8a0e2f4SThomas Veerman makeenv= 453c8a0e2f4SThomas Veerman makewrapper= 454c8a0e2f4SThomas Veerman makewrappermachine= 455c8a0e2f4SThomas Veerman runcmd= 456c8a0e2f4SThomas Veerman operations= 457c8a0e2f4SThomas Veerman removedirs= 458c8a0e2f4SThomas Veerman 459c8a0e2f4SThomas Veerman [ -d usr.bin/make ] || cd "$(dirname $0)" 460c8a0e2f4SThomas Veerman [ -d usr.bin/make ] || 461c8a0e2f4SThomas Veerman bomb "build.sh must be run from the top source level" 462c8a0e2f4SThomas Veerman [ -f share/mk/bsd.own.mk ] || 463c8a0e2f4SThomas Veerman bomb "src/share/mk is missing; please re-fetch the source tree" 464c8a0e2f4SThomas Veerman 465c8a0e2f4SThomas Veerman # Set various environment variables to known defaults, 466c8a0e2f4SThomas Veerman # to minimize (cross-)build problems observed "in the field". 467c8a0e2f4SThomas Veerman # 468c8a0e2f4SThomas Veerman # LC_ALL=C must be set before we try to parse the output from 469c8a0e2f4SThomas Veerman # any command. Other variables are set (or unset) here, before 470c8a0e2f4SThomas Veerman # we parse command line arguments. 471c8a0e2f4SThomas Veerman # 472c8a0e2f4SThomas Veerman # These variables can be overridden via "-V var=value" if 473c8a0e2f4SThomas Veerman # you know what you are doing. 474c8a0e2f4SThomas Veerman # 475c8a0e2f4SThomas Veerman unsetmakeenv INFODIR 476c8a0e2f4SThomas Veerman unsetmakeenv LESSCHARSET 477c8a0e2f4SThomas Veerman unsetmakeenv MAKEFLAGS 47884d9c625SLionel Sambuc unsetmakeenv TERMINFO 479c8a0e2f4SThomas Veerman setmakeenv LC_ALL C 480c8a0e2f4SThomas Veerman 481c8a0e2f4SThomas Veerman # Find information about the build platform. This should be 482c8a0e2f4SThomas Veerman # kept in sync with _HOST_OSNAME, _HOST_OSREL, and _HOST_ARCH 483c8a0e2f4SThomas Veerman # variables in share/mk/bsd.sys.mk. 484c8a0e2f4SThomas Veerman # 485c8a0e2f4SThomas Veerman # Note that "uname -p" is not part of POSIX, but we want uname_p 486c8a0e2f4SThomas Veerman # to be set to the host MACHINE_ARCH, if possible. On systems 487c8a0e2f4SThomas Veerman # where "uname -p" fails, prints "unknown", or prints a string 488c8a0e2f4SThomas Veerman # that does not look like an identifier, fall back to using the 489c8a0e2f4SThomas Veerman # output from "uname -m" instead. 490c8a0e2f4SThomas Veerman # 491c8a0e2f4SThomas Veerman uname_s=$(uname -s 2>/dev/null) 492c8a0e2f4SThomas Veerman uname_r=$(uname -r 2>/dev/null) 493c8a0e2f4SThomas Veerman uname_m=$(uname -m 2>/dev/null) 494c8a0e2f4SThomas Veerman uname_p=$(uname -p 2>/dev/null || echo "unknown") 495c8a0e2f4SThomas Veerman case "${uname_p}" in 496c8a0e2f4SThomas Veerman ''|unknown|*[^-_A-Za-z0-9]*) uname_p="${uname_m}" ;; 497c8a0e2f4SThomas Veerman esac 498c8a0e2f4SThomas Veerman 499c8a0e2f4SThomas Veerman id_u=$(id -u 2>/dev/null || /usr/xpg4/bin/id -u 2>/dev/null) 500c8a0e2f4SThomas Veerman 501c8a0e2f4SThomas Veerman # If $PWD is a valid name of the current directory, POSIX mandates 502c8a0e2f4SThomas Veerman # that pwd return it by default which causes problems in the 503c8a0e2f4SThomas Veerman # presence of symlinks. Unsetting PWD is simpler than changing 504c8a0e2f4SThomas Veerman # every occurrence of pwd to use -P. 505c8a0e2f4SThomas Veerman # 506c8a0e2f4SThomas Veerman # XXX Except that doesn't work on Solaris. Or many Linuces. 507c8a0e2f4SThomas Veerman # 508c8a0e2f4SThomas Veerman unset PWD 509c8a0e2f4SThomas Veerman TOP=$(/bin/pwd -P 2>/dev/null || /bin/pwd 2>/dev/null) 510c8a0e2f4SThomas Veerman 511c8a0e2f4SThomas Veerman # The user can set HOST_SH in the environment, or we try to 512c8a0e2f4SThomas Veerman # guess an appropriate value. Then we set several other 513c8a0e2f4SThomas Veerman # variables from HOST_SH. 514c8a0e2f4SThomas Veerman # 515c8a0e2f4SThomas Veerman set_HOST_SH 516c8a0e2f4SThomas Veerman setmakeenv HOST_SH "${HOST_SH}" 517c8a0e2f4SThomas Veerman setmakeenv BSHELL "${HOST_SH}" 518c8a0e2f4SThomas Veerman setmakeenv CONFIG_SHELL "${HOST_SH}" 519c8a0e2f4SThomas Veerman 520c8a0e2f4SThomas Veerman # Set defaults. 521c8a0e2f4SThomas Veerman # 522c8a0e2f4SThomas Veerman toolprefix=nb 523c8a0e2f4SThomas Veerman 524c8a0e2f4SThomas Veerman # Some systems have a small ARG_MAX. -X prevents make(1) from 525c8a0e2f4SThomas Veerman # exporting variables in the environment redundantly. 526c8a0e2f4SThomas Veerman # 527c8a0e2f4SThomas Veerman case "${uname_s}" in 528c8a0e2f4SThomas Veerman Darwin | FreeBSD | CYGWIN*) 529c8a0e2f4SThomas Veerman MAKEFLAGS="-X ${MAKEFLAGS}" 530c8a0e2f4SThomas Veerman ;; 531c8a0e2f4SThomas Veerman esac 532c8a0e2f4SThomas Veerman 533c8a0e2f4SThomas Veerman # do_{operation}=true if given operation is requested. 534c8a0e2f4SThomas Veerman # 535c8a0e2f4SThomas Veerman do_expertmode=false 536c8a0e2f4SThomas Veerman do_rebuildmake=false 537c8a0e2f4SThomas Veerman do_removedirs=false 538c8a0e2f4SThomas Veerman do_tools=false 539c8a0e2f4SThomas Veerman do_cleandir=false 540c8a0e2f4SThomas Veerman do_obj=false 541c8a0e2f4SThomas Veerman do_build=false 542c8a0e2f4SThomas Veerman do_distribution=false 543c8a0e2f4SThomas Veerman do_release=false 544c8a0e2f4SThomas Veerman do_kernel=false 545c8a0e2f4SThomas Veerman do_releasekernel=false 546*0a6a1f1dSLionel Sambuc do_kernels=false 547c8a0e2f4SThomas Veerman do_modules=false 548c8a0e2f4SThomas Veerman do_installmodules=false 549c8a0e2f4SThomas Veerman do_install=false 550c8a0e2f4SThomas Veerman do_sets=false 551c8a0e2f4SThomas Veerman do_sourcesets=false 552c8a0e2f4SThomas Veerman do_syspkgs=false 553c8a0e2f4SThomas Veerman do_iso_image=false 554c8a0e2f4SThomas Veerman do_iso_image_source=false 555c8a0e2f4SThomas Veerman do_live_image=false 556c8a0e2f4SThomas Veerman do_install_image=false 55784d9c625SLionel Sambuc do_disk_image=false 55884d9c625SLionel Sambuc do_show_params=false 559c8a0e2f4SThomas Veerman do_rump=false 560c8a0e2f4SThomas Veerman 561c8a0e2f4SThomas Veerman # done_{operation}=true if given operation has been done. 562c8a0e2f4SThomas Veerman # 563c8a0e2f4SThomas Veerman done_rebuildmake=false 564c8a0e2f4SThomas Veerman 565c8a0e2f4SThomas Veerman # Create scratch directory 566c8a0e2f4SThomas Veerman # 567c8a0e2f4SThomas Veerman tmpdir="${TMPDIR-/tmp}/nbbuild$$" 568c8a0e2f4SThomas Veerman mkdir "${tmpdir}" || bomb "Cannot mkdir: ${tmpdir}" 569c8a0e2f4SThomas Veerman trap "cd /; rm -r -f \"${tmpdir}\"" 0 570c8a0e2f4SThomas Veerman results="${tmpdir}/build.sh.results" 571c8a0e2f4SThomas Veerman 572c8a0e2f4SThomas Veerman # Set source directories 573c8a0e2f4SThomas Veerman # 574c8a0e2f4SThomas Veerman setmakeenv NETBSDSRCDIR "${TOP}" 575c8a0e2f4SThomas Veerman 576c8a0e2f4SThomas Veerman # Make sure KERNOBJDIR is an absolute path if defined 577c8a0e2f4SThomas Veerman # 578c8a0e2f4SThomas Veerman case "${KERNOBJDIR}" in 579c8a0e2f4SThomas Veerman ''|/*) ;; 580c8a0e2f4SThomas Veerman *) KERNOBJDIR="${TOP}/${KERNOBJDIR}" 581c8a0e2f4SThomas Veerman setmakeenv KERNOBJDIR "${KERNOBJDIR}" 582c8a0e2f4SThomas Veerman ;; 583c8a0e2f4SThomas Veerman esac 584c8a0e2f4SThomas Veerman 585c8a0e2f4SThomas Veerman # Find the version of NetBSD 586c8a0e2f4SThomas Veerman # 587c8a0e2f4SThomas Veerman DISTRIBVER="$(${HOST_SH} ${TOP}/sys/conf/osrelease.sh)" 588c8a0e2f4SThomas Veerman 589c8a0e2f4SThomas Veerman # Set the BUILDSEED to NetBSD-"N" 590c8a0e2f4SThomas Veerman # 591c8a0e2f4SThomas Veerman setmakeenv BUILDSEED "MINIX-$(${HOST_SH} ${TOP}/sys/conf/osrelease.sh -m)" 592c8a0e2f4SThomas Veerman 593c8a0e2f4SThomas Veerman # Set MKARZERO to "yes" 594c8a0e2f4SThomas Veerman # 59513c63491SLionel Sambuc setmakeenv MKARZERO "yes" 596c8a0e2f4SThomas Veerman 597c8a0e2f4SThomas Veerman} 598c8a0e2f4SThomas Veerman 59984d9c625SLionel Sambuc# valid_MACHINE_ARCH -- A multi-line string, listing all valid 60084d9c625SLionel Sambuc# MACHINE/MACHINE_ARCH pairs. 60184d9c625SLionel Sambuc# 60284d9c625SLionel Sambuc# Each line contains a MACHINE and MACHINE_ARCH value, an optional ALIAS 60384d9c625SLionel Sambuc# which may be used to refer to the MACHINE/MACHINE_ARCH pair, and an 60484d9c625SLionel Sambuc# optional DEFAULT or NO_DEFAULT keyword. 60584d9c625SLionel Sambuc# 60684d9c625SLionel Sambuc# When a MACHINE corresponds to multiple possible values of 60784d9c625SLionel Sambuc# MACHINE_ARCH, then this table should list all allowed combinations. 60884d9c625SLionel Sambuc# If the MACHINE is associated with a default MACHINE_ARCH (to be 60984d9c625SLionel Sambuc# used when the user specifies the MACHINE but fails to specify the 61084d9c625SLionel Sambuc# MACHINE_ARCH), then one of the lines should have the "DEFAULT" 61184d9c625SLionel Sambuc# keyword. If there is no default MACHINE_ARCH for a particular 61284d9c625SLionel Sambuc# MACHINE, then there should be a line with the "NO_DEFAULT" keyword, 61384d9c625SLionel Sambuc# and with a blank MACHINE_ARCH. 61484d9c625SLionel Sambuc# 61584d9c625SLionel Sambucvalid_MACHINE_ARCH=' 61684d9c625SLionel SambucMACHINE=acorn26 MACHINE_ARCH=arm 61784d9c625SLionel SambucMACHINE=acorn32 MACHINE_ARCH=arm 61884d9c625SLionel SambucMACHINE=algor MACHINE_ARCH=mips64el ALIAS=algor64 61984d9c625SLionel SambucMACHINE=algor MACHINE_ARCH=mipsel DEFAULT 62084d9c625SLionel SambucMACHINE=alpha MACHINE_ARCH=alpha 62184d9c625SLionel SambucMACHINE=amd64 MACHINE_ARCH=x86_64 62284d9c625SLionel SambucMACHINE=amiga MACHINE_ARCH=m68k 62384d9c625SLionel SambucMACHINE=amigappc MACHINE_ARCH=powerpc 62484d9c625SLionel SambucMACHINE=arc MACHINE_ARCH=mips64el ALIAS=arc64 62584d9c625SLionel SambucMACHINE=arc MACHINE_ARCH=mipsel DEFAULT 62684d9c625SLionel SambucMACHINE=atari MACHINE_ARCH=m68k 62784d9c625SLionel SambucMACHINE=bebox MACHINE_ARCH=powerpc 628*0a6a1f1dSLionel SambucMACHINE=cats MACHINE_ARCH=arm ALIAS=ocats 629*0a6a1f1dSLionel SambucMACHINE=cats MACHINE_ARCH=earmv4 ALIAS=ecats DEFAULT 63084d9c625SLionel SambucMACHINE=cesfic MACHINE_ARCH=m68k 63184d9c625SLionel SambucMACHINE=cobalt MACHINE_ARCH=mips64el ALIAS=cobalt64 63284d9c625SLionel SambucMACHINE=cobalt MACHINE_ARCH=mipsel DEFAULT 63384d9c625SLionel SambucMACHINE=dreamcast MACHINE_ARCH=sh3el 63484d9c625SLionel SambucMACHINE=emips MACHINE_ARCH=mipseb 63584d9c625SLionel SambucMACHINE=epoc32 MACHINE_ARCH=arm 636*0a6a1f1dSLionel SambucMACHINE=evbarm MACHINE_ARCH=arm ALIAS=evboarm-el 637*0a6a1f1dSLionel SambucMACHINE=evbarm MACHINE_ARCH=armeb ALIAS=evboarm-eb 638*0a6a1f1dSLionel SambucMACHINE=evbarm MACHINE_ARCH=earm ALIAS=evbearm-el DEFAULT 63984d9c625SLionel SambucMACHINE=evbarm MACHINE_ARCH=earmeb ALIAS=evbearm-eb 64084d9c625SLionel SambucMACHINE=evbarm MACHINE_ARCH=earmhf ALIAS=evbearmhf-el 64184d9c625SLionel SambucMACHINE=evbarm MACHINE_ARCH=earmhfeb ALIAS=evbearmhf-eb 64284d9c625SLionel SambucMACHINE=evbarm MACHINE_ARCH=earmv4 ALIAS=evbearmv4-el 64384d9c625SLionel SambucMACHINE=evbarm MACHINE_ARCH=earmv4eb ALIAS=evbearmv4-eb 64484d9c625SLionel SambucMACHINE=evbarm MACHINE_ARCH=earmv5 ALIAS=evbearmv5-el 64584d9c625SLionel SambucMACHINE=evbarm MACHINE_ARCH=earmv5eb ALIAS=evbearmv5-eb 64684d9c625SLionel SambucMACHINE=evbarm MACHINE_ARCH=earmv6 ALIAS=evbearmv6-el 64784d9c625SLionel SambucMACHINE=evbarm MACHINE_ARCH=earmv6hf ALIAS=evbearmv6hf-el 64884d9c625SLionel SambucMACHINE=evbarm MACHINE_ARCH=earmv6eb ALIAS=evbearmv6-eb 64984d9c625SLionel SambucMACHINE=evbarm MACHINE_ARCH=earmv6hfeb ALIAS=evbearmv6hf-eb 65084d9c625SLionel SambucMACHINE=evbarm MACHINE_ARCH=earmv7 ALIAS=evbearmv7-el 65184d9c625SLionel SambucMACHINE=evbarm MACHINE_ARCH=earmv7eb ALIAS=evbearmv7-eb 65284d9c625SLionel SambucMACHINE=evbarm MACHINE_ARCH=earmv7hf ALIAS=evbearmv7hf-el 65384d9c625SLionel SambucMACHINE=evbarm MACHINE_ARCH=earmv7hfeb ALIAS=evbearmv7hf-eb 654*0a6a1f1dSLionel SambucMACHINE=evbarm64 MACHINE_ARCH=aarch64 ALIAS=evbarm64-el DEFAULT 655*0a6a1f1dSLionel SambucMACHINE=evbarm64 MACHINE_ARCH=aarch64eb ALIAS=evbarm64-eb 65684d9c625SLionel SambucMACHINE=evbcf MACHINE_ARCH=coldfire 65784d9c625SLionel SambucMACHINE=evbmips MACHINE_ARCH= NO_DEFAULT 65884d9c625SLionel SambucMACHINE=evbmips MACHINE_ARCH=mips64eb ALIAS=evbmips64-eb 65984d9c625SLionel SambucMACHINE=evbmips MACHINE_ARCH=mips64el ALIAS=evbmips64-el 66084d9c625SLionel SambucMACHINE=evbmips MACHINE_ARCH=mipseb ALIAS=evbmips-eb 66184d9c625SLionel SambucMACHINE=evbmips MACHINE_ARCH=mipsel ALIAS=evbmips-el 66284d9c625SLionel SambucMACHINE=evbppc MACHINE_ARCH=powerpc DEFAULT 66384d9c625SLionel SambucMACHINE=evbppc MACHINE_ARCH=powerpc64 ALIAS=evbppc64 66484d9c625SLionel SambucMACHINE=evbsh3 MACHINE_ARCH= NO_DEFAULT 66584d9c625SLionel SambucMACHINE=evbsh3 MACHINE_ARCH=sh3eb ALIAS=evbsh3-eb 66684d9c625SLionel SambucMACHINE=evbsh3 MACHINE_ARCH=sh3el ALIAS=evbsh3-el 66784d9c625SLionel SambucMACHINE=ews4800mips MACHINE_ARCH=mipseb 66884d9c625SLionel SambucMACHINE=hp300 MACHINE_ARCH=m68k 669*0a6a1f1dSLionel SambucMACHINE=hppa MACHINE_ARCH=hppa 670*0a6a1f1dSLionel SambucMACHINE=hpcarm MACHINE_ARCH=arm ALIAS=hpcoarm 671*0a6a1f1dSLionel SambucMACHINE=hpcarm MACHINE_ARCH=earmv4 ALIAS=hpcearm DEFAULT 67284d9c625SLionel SambucMACHINE=hpcmips MACHINE_ARCH=mipsel 67384d9c625SLionel SambucMACHINE=hpcsh MACHINE_ARCH=sh3el 67484d9c625SLionel SambucMACHINE=i386 MACHINE_ARCH=i386 67584d9c625SLionel SambucMACHINE=ia64 MACHINE_ARCH=ia64 67684d9c625SLionel SambucMACHINE=ibmnws MACHINE_ARCH=powerpc 677*0a6a1f1dSLionel SambucMACHINE=iyonix MACHINE_ARCH=arm ALIAS=oiyonix 678*0a6a1f1dSLionel SambucMACHINE=iyonix MACHINE_ARCH=earm ALIAS=eiyonix DEFAULT 67984d9c625SLionel SambucMACHINE=landisk MACHINE_ARCH=sh3el 68084d9c625SLionel SambucMACHINE=luna68k MACHINE_ARCH=m68k 68184d9c625SLionel SambucMACHINE=mac68k MACHINE_ARCH=m68k 68284d9c625SLionel SambucMACHINE=macppc MACHINE_ARCH=powerpc DEFAULT 68384d9c625SLionel SambucMACHINE=macppc MACHINE_ARCH=powerpc64 ALIAS=macppc64 68484d9c625SLionel SambucMACHINE=mipsco MACHINE_ARCH=mipseb 68584d9c625SLionel SambucMACHINE=mmeye MACHINE_ARCH=sh3eb 68684d9c625SLionel SambucMACHINE=mvme68k MACHINE_ARCH=m68k 68784d9c625SLionel SambucMACHINE=mvmeppc MACHINE_ARCH=powerpc 688*0a6a1f1dSLionel SambucMACHINE=netwinder MACHINE_ARCH=arm ALIAS=onetwinder 689*0a6a1f1dSLionel SambucMACHINE=netwinder MACHINE_ARCH=earmv4 ALIAS=enetwinder DEFAULT 69084d9c625SLionel SambucMACHINE=news68k MACHINE_ARCH=m68k 69184d9c625SLionel SambucMACHINE=newsmips MACHINE_ARCH=mipseb 69284d9c625SLionel SambucMACHINE=next68k MACHINE_ARCH=m68k 69384d9c625SLionel SambucMACHINE=ofppc MACHINE_ARCH=powerpc DEFAULT 69484d9c625SLionel SambucMACHINE=ofppc MACHINE_ARCH=powerpc64 ALIAS=ofppc64 695*0a6a1f1dSLionel SambucMACHINE=or1k MACHINE_ARCH=or1k 696*0a6a1f1dSLionel SambucMACHINE=playstation2 MACHINE_ARCH=mipsel 69784d9c625SLionel SambucMACHINE=pmax MACHINE_ARCH=mips64el ALIAS=pmax64 69884d9c625SLionel SambucMACHINE=pmax MACHINE_ARCH=mipsel DEFAULT 69984d9c625SLionel SambucMACHINE=prep MACHINE_ARCH=powerpc 700*0a6a1f1dSLionel SambucMACHINE=riscv MACHINE_ARCH=riscv64 ALIAS=riscv64 DEFAULT 701*0a6a1f1dSLionel SambucMACHINE=riscv MACHINE_ARCH=riscv32 ALIAS=riscv32 70284d9c625SLionel SambucMACHINE=rs6000 MACHINE_ARCH=powerpc 70384d9c625SLionel SambucMACHINE=sandpoint MACHINE_ARCH=powerpc 70484d9c625SLionel SambucMACHINE=sbmips MACHINE_ARCH= NO_DEFAULT 70584d9c625SLionel SambucMACHINE=sbmips MACHINE_ARCH=mips64eb ALIAS=sbmips64-eb 70684d9c625SLionel SambucMACHINE=sbmips MACHINE_ARCH=mips64el ALIAS=sbmips64-el 70784d9c625SLionel SambucMACHINE=sbmips MACHINE_ARCH=mipseb ALIAS=sbmips-eb 70884d9c625SLionel SambucMACHINE=sbmips MACHINE_ARCH=mipsel ALIAS=sbmips-el 70984d9c625SLionel SambucMACHINE=sgimips MACHINE_ARCH=mips64eb ALIAS=sgimips64 71084d9c625SLionel SambucMACHINE=sgimips MACHINE_ARCH=mipseb DEFAULT 711*0a6a1f1dSLionel SambucMACHINE=shark MACHINE_ARCH=arm ALIAS=oshark 712*0a6a1f1dSLionel SambucMACHINE=shark MACHINE_ARCH=earmv4 ALIAS=eshark DEFAULT 71384d9c625SLionel SambucMACHINE=sparc MACHINE_ARCH=sparc 71484d9c625SLionel SambucMACHINE=sparc64 MACHINE_ARCH=sparc64 71584d9c625SLionel SambucMACHINE=sun2 MACHINE_ARCH=m68000 71684d9c625SLionel SambucMACHINE=sun3 MACHINE_ARCH=m68k 71784d9c625SLionel SambucMACHINE=vax MACHINE_ARCH=vax 71884d9c625SLionel SambucMACHINE=x68k MACHINE_ARCH=m68k 719*0a6a1f1dSLionel SambucMACHINE=zaurus MACHINE_ARCH=arm ALIAS=ozaurus 720*0a6a1f1dSLionel SambucMACHINE=zaurus MACHINE_ARCH=earm ALIAS=ezaurus DEFAULT 72184d9c625SLionel Sambuc' 72284d9c625SLionel Sambuc 72384d9c625SLionel Sambuc# getarch -- find the default MACHINE_ARCH for a MACHINE, 72484d9c625SLionel Sambuc# or convert an alias to a MACHINE/MACHINE_ARCH pair. 72584d9c625SLionel Sambuc# 726*0a6a1f1dSLionel Sambuc# Saves the original value of MACHINE in makewrappermachine before 727*0a6a1f1dSLionel Sambuc# alias processing. 72884d9c625SLionel Sambuc# 72984d9c625SLionel Sambuc# Sets MACHINE and MACHINE_ARCH if the input MACHINE value is 73084d9c625SLionel Sambuc# recognised as an alias, or recognised as a machine that has a default 73184d9c625SLionel Sambuc# MACHINE_ARCH (or that has only one possible MACHINE_ARCH). 73284d9c625SLionel Sambuc# 73384d9c625SLionel Sambuc# Leaves MACHINE and MACHINE_ARCH unchanged if MACHINE is recognised 73484d9c625SLionel Sambuc# as being associated with multiple MACHINE_ARCH values with no default. 73584d9c625SLionel Sambuc# 73684d9c625SLionel Sambuc# Bombs if MACHINE is not recognised. 73784d9c625SLionel Sambuc# 738c8a0e2f4SThomas Veermangetarch() 739c8a0e2f4SThomas Veerman{ 74084d9c625SLionel Sambuc local IFS 74184d9c625SLionel Sambuc local found="" 74284d9c625SLionel Sambuc local line 743c8a0e2f4SThomas Veerman 74484d9c625SLionel Sambuc IFS="${nl}" 74584d9c625SLionel Sambuc makewrappermachine="${MACHINE}" 74684d9c625SLionel Sambuc for line in ${valid_MACHINE_ARCH}; do 74784d9c625SLionel Sambuc line="${line%%#*}" # ignore comments 74884d9c625SLionel Sambuc line="$( IFS=" ${tab}" ; echo $line )" # normalise white space 74984d9c625SLionel Sambuc case "${line} " in 75084d9c625SLionel Sambuc " ") 75184d9c625SLionel Sambuc # skip blank lines or comment lines 75284d9c625SLionel Sambuc continue 7539152e1c5SLionel Sambuc ;; 75484d9c625SLionel Sambuc *" ALIAS=${MACHINE} "*) 75584d9c625SLionel Sambuc # Found a line with a matching ALIAS=<alias>. 75684d9c625SLionel Sambuc found="$line" 75784d9c625SLionel Sambuc break 758c8a0e2f4SThomas Veerman ;; 75984d9c625SLionel Sambuc "MACHINE=${MACHINE} "*" NO_DEFAULT"*) 76084d9c625SLionel Sambuc # Found an explicit "NO_DEFAULT" for this MACHINE. 76184d9c625SLionel Sambuc found="$line" 76284d9c625SLionel Sambuc break 763c8a0e2f4SThomas Veerman ;; 76484d9c625SLionel Sambuc "MACHINE=${MACHINE} "*" DEFAULT"*) 76584d9c625SLionel Sambuc # Found an explicit "DEFAULT" for this MACHINE. 76684d9c625SLionel Sambuc found="$line" 76784d9c625SLionel Sambuc break 768c8a0e2f4SThomas Veerman ;; 76984d9c625SLionel Sambuc "MACHINE=${MACHINE} "*) 77084d9c625SLionel Sambuc # Found a line for this MACHINE. If it's the 77184d9c625SLionel Sambuc # first such line, then tentatively accept it. 77284d9c625SLionel Sambuc # If it's not the first matching line, then 77384d9c625SLionel Sambuc # remember that there was more than one match. 77484d9c625SLionel Sambuc case "$found" in 77584d9c625SLionel Sambuc '') found="$line" ;; 776*0a6a1f1dSLionel Sambuc *) found="MULTIPLE_MATCHES" ;; 777c8a0e2f4SThomas Veerman esac 778c8a0e2f4SThomas Veerman ;; 77984d9c625SLionel Sambuc esac 78084d9c625SLionel Sambuc done 781c8a0e2f4SThomas Veerman 78284d9c625SLionel Sambuc case "$found" in 78384d9c625SLionel Sambuc *NO_DEFAULT*|*MULTIPLE_MATCHES*) 78484d9c625SLionel Sambuc # MACHINE is OK, but MACHINE_ARCH is still unknown 78584d9c625SLionel Sambuc return 786c8a0e2f4SThomas Veerman ;; 78784d9c625SLionel Sambuc "MACHINE="*" MACHINE_ARCH="*) 78884d9c625SLionel Sambuc # Obey the MACHINE= and MACHINE_ARCH= parts of the line. 78984d9c625SLionel Sambuc IFS=" " 79084d9c625SLionel Sambuc for frag in ${found}; do 79184d9c625SLionel Sambuc case "$frag" in 79284d9c625SLionel Sambuc MACHINE=*|MACHINE_ARCH=*) 79384d9c625SLionel Sambuc eval "$frag" 794c8a0e2f4SThomas Veerman ;; 79584d9c625SLionel Sambuc esac 79684d9c625SLionel Sambuc done 797c8a0e2f4SThomas Veerman ;; 798c8a0e2f4SThomas Veerman *) 799c8a0e2f4SThomas Veerman bomb "Unknown target MACHINE: ${MACHINE}" 800c8a0e2f4SThomas Veerman ;; 801c8a0e2f4SThomas Veerman esac 802c8a0e2f4SThomas Veerman} 803c8a0e2f4SThomas Veerman 80484d9c625SLionel Sambuc# validatearch -- check that the MACHINE/MACHINE_ARCH pair is supported. 80584d9c625SLionel Sambuc# 80684d9c625SLionel Sambuc# Bombs if the pair is not supported. 80784d9c625SLionel Sambuc# 808c8a0e2f4SThomas Veermanvalidatearch() 809c8a0e2f4SThomas Veerman{ 81084d9c625SLionel Sambuc local IFS 81184d9c625SLionel Sambuc local line 81284d9c625SLionel Sambuc local foundpair=false foundmachine=false foundarch=false 81384d9c625SLionel Sambuc 814c8a0e2f4SThomas Veerman case "${MACHINE_ARCH}" in 815c8a0e2f4SThomas Veerman "") 816c8a0e2f4SThomas Veerman bomb "No MACHINE_ARCH provided" 817c8a0e2f4SThomas Veerman ;; 81884d9c625SLionel Sambuc esac 819c8a0e2f4SThomas Veerman 82084d9c625SLionel Sambuc IFS="${nl}" 82184d9c625SLionel Sambuc for line in ${valid_MACHINE_ARCH}; do 82284d9c625SLionel Sambuc line="${line%%#*}" # ignore comments 82384d9c625SLionel Sambuc line="$( IFS=" ${tab}" ; echo $line )" # normalise white space 82484d9c625SLionel Sambuc case "${line} " in 82584d9c625SLionel Sambuc " ") 82684d9c625SLionel Sambuc # skip blank lines or comment lines 82784d9c625SLionel Sambuc continue 82884d9c625SLionel Sambuc ;; 82984d9c625SLionel Sambuc "MACHINE=${MACHINE} MACHINE_ARCH=${MACHINE_ARCH} "*) 83084d9c625SLionel Sambuc foundpair=true 83184d9c625SLionel Sambuc ;; 83284d9c625SLionel Sambuc "MACHINE=${MACHINE} "*) 83384d9c625SLionel Sambuc foundmachine=true 83484d9c625SLionel Sambuc ;; 83584d9c625SLionel Sambuc *"MACHINE_ARCH=${MACHINE_ARCH} "*) 83684d9c625SLionel Sambuc foundarch=true 83784d9c625SLionel Sambuc ;; 83884d9c625SLionel Sambuc esac 83984d9c625SLionel Sambuc done 84084d9c625SLionel Sambuc 84184d9c625SLionel Sambuc case "${foundpair}:${foundmachine}:${foundarch}" in 84284d9c625SLionel Sambuc true:*) 84384d9c625SLionel Sambuc : OK 84484d9c625SLionel Sambuc ;; 84584d9c625SLionel Sambuc *:false:*) 84684d9c625SLionel Sambuc bomb "Unknown target MACHINE: ${MACHINE}" 84784d9c625SLionel Sambuc ;; 84884d9c625SLionel Sambuc *:*:false) 849c8a0e2f4SThomas Veerman bomb "Unknown target MACHINE_ARCH: ${MACHINE_ARCH}" 850c8a0e2f4SThomas Veerman ;; 851c8a0e2f4SThomas Veerman *) 852c8a0e2f4SThomas Veerman bomb "MACHINE_ARCH '${MACHINE_ARCH}' does not support MACHINE '${MACHINE}'" 85384d9c625SLionel Sambuc ;; 85484d9c625SLionel Sambuc esac 855c8a0e2f4SThomas Veerman} 856c8a0e2f4SThomas Veerman 857*0a6a1f1dSLionel Sambuc# listarch -- list valid MACHINE/MACHINE_ARCH/ALIAS values, 858*0a6a1f1dSLionel Sambuc# optionally restricted to those where the MACHINE and/or MACHINE_ARCH 859*0a6a1f1dSLionel Sambuc# match specifed glob patterns. 860*0a6a1f1dSLionel Sambuc# 861*0a6a1f1dSLionel Sambuclistarch() 862*0a6a1f1dSLionel Sambuc{ 863*0a6a1f1dSLionel Sambuc local machglob="$1" archglob="$2" 864*0a6a1f1dSLionel Sambuc local IFS 865*0a6a1f1dSLionel Sambuc local wildcard="*" 866*0a6a1f1dSLionel Sambuc local line xline frag 867*0a6a1f1dSLionel Sambuc local line_matches_machine line_matches_arch 868*0a6a1f1dSLionel Sambuc local found=false 869*0a6a1f1dSLionel Sambuc 870*0a6a1f1dSLionel Sambuc # Empty machglob or archglob should match anything 871*0a6a1f1dSLionel Sambuc : "${machglob:=${wildcard}}" 872*0a6a1f1dSLionel Sambuc : "${archglob:=${wildcard}}" 873*0a6a1f1dSLionel Sambuc 874*0a6a1f1dSLionel Sambuc IFS="${nl}" 875*0a6a1f1dSLionel Sambuc for line in ${valid_MACHINE_ARCH}; do 876*0a6a1f1dSLionel Sambuc line="${line%%#*}" # ignore comments 877*0a6a1f1dSLionel Sambuc xline="$( IFS=" ${tab}" ; echo $line )" # normalise white space 878*0a6a1f1dSLionel Sambuc [ -z "${xline}" ] && continue # skip blank or comment lines 879*0a6a1f1dSLionel Sambuc 880*0a6a1f1dSLionel Sambuc line_matches_machine=false 881*0a6a1f1dSLionel Sambuc line_matches_arch=false 882*0a6a1f1dSLionel Sambuc 883*0a6a1f1dSLionel Sambuc IFS=" " 884*0a6a1f1dSLionel Sambuc for frag in ${xline}; do 885*0a6a1f1dSLionel Sambuc case "${frag}" in 886*0a6a1f1dSLionel Sambuc MACHINE=${machglob}) 887*0a6a1f1dSLionel Sambuc line_matches_machine=true ;; 888*0a6a1f1dSLionel Sambuc ALIAS=${machglob}) 889*0a6a1f1dSLionel Sambuc line_matches_machine=true ;; 890*0a6a1f1dSLionel Sambuc MACHINE_ARCH=${archglob}) 891*0a6a1f1dSLionel Sambuc line_matches_arch=true ;; 892*0a6a1f1dSLionel Sambuc esac 893*0a6a1f1dSLionel Sambuc done 894*0a6a1f1dSLionel Sambuc 895*0a6a1f1dSLionel Sambuc if $line_matches_machine && $line_matches_arch; then 896*0a6a1f1dSLionel Sambuc found=true 897*0a6a1f1dSLionel Sambuc echo "$line" 898*0a6a1f1dSLionel Sambuc fi 899*0a6a1f1dSLionel Sambuc done 900*0a6a1f1dSLionel Sambuc if ! $found; then 901*0a6a1f1dSLionel Sambuc echo >&2 "No match for" \ 902*0a6a1f1dSLionel Sambuc "MACHINE=${machglob} MACHINE_ARCH=${archglob}" 903*0a6a1f1dSLionel Sambuc return 1 904*0a6a1f1dSLionel Sambuc fi 905*0a6a1f1dSLionel Sambuc return 0 906*0a6a1f1dSLionel Sambuc} 907*0a6a1f1dSLionel Sambuc 908c8a0e2f4SThomas Veerman# nobomb_getmakevar -- 909c8a0e2f4SThomas Veerman# Given the name of a make variable in $1, print make's idea of the 910c8a0e2f4SThomas Veerman# value of that variable, or return 1 if there's an error. 911c8a0e2f4SThomas Veerman# 912c8a0e2f4SThomas Veermannobomb_getmakevar() 913c8a0e2f4SThomas Veerman{ 914c8a0e2f4SThomas Veerman [ -x "${make}" ] || return 1 915c8a0e2f4SThomas Veerman "${make}" -m ${TOP}/share/mk -s -B -f- _x_ <<EOF || return 1 916c8a0e2f4SThomas Veerman_x_: 917c8a0e2f4SThomas Veerman echo \${$1} 918b8a678efSLionel Sambuc# LSC FIXME: We are cross compiling, so overwrite default and build tools 919b8a678efSLionel SambucUSETOOLS:=yes 920c8a0e2f4SThomas Veerman.include <bsd.prog.mk> 921c8a0e2f4SThomas Veerman.include <bsd.kernobj.mk> 922c8a0e2f4SThomas VeermanEOF 923c8a0e2f4SThomas Veerman} 924c8a0e2f4SThomas Veerman 925c8a0e2f4SThomas Veerman# bomb_getmakevar -- 926c8a0e2f4SThomas Veerman# Given the name of a make variable in $1, print make's idea of the 927c8a0e2f4SThomas Veerman# value of that variable, or bomb if there's an error. 928c8a0e2f4SThomas Veerman# 929c8a0e2f4SThomas Veermanbomb_getmakevar() 930c8a0e2f4SThomas Veerman{ 931c8a0e2f4SThomas Veerman [ -x "${make}" ] || bomb "bomb_getmakevar $1: ${make} is not executable" 932c8a0e2f4SThomas Veerman nobomb_getmakevar "$1" || bomb "bomb_getmakevar $1: ${make} failed" 933c8a0e2f4SThomas Veerman} 934c8a0e2f4SThomas Veerman 935c8a0e2f4SThomas Veerman# getmakevar -- 936c8a0e2f4SThomas Veerman# Given the name of a make variable in $1, print make's idea of the 937c8a0e2f4SThomas Veerman# value of that variable, or print a literal '$' followed by the 938c8a0e2f4SThomas Veerman# variable name if ${make} is not executable. This is intended for use in 939c8a0e2f4SThomas Veerman# messages that need to be readable even if $make hasn't been built, 940c8a0e2f4SThomas Veerman# such as when build.sh is run with the "-n" option. 941c8a0e2f4SThomas Veerman# 942c8a0e2f4SThomas Veermangetmakevar() 943c8a0e2f4SThomas Veerman{ 944c8a0e2f4SThomas Veerman if [ -x "${make}" ]; then 945c8a0e2f4SThomas Veerman bomb_getmakevar "$1" 946c8a0e2f4SThomas Veerman else 947c8a0e2f4SThomas Veerman echo "\$$1" 948c8a0e2f4SThomas Veerman fi 949c8a0e2f4SThomas Veerman} 950c8a0e2f4SThomas Veerman 951c8a0e2f4SThomas Veermansetmakeenv() 952c8a0e2f4SThomas Veerman{ 953c8a0e2f4SThomas Veerman eval "$1='$2'; export $1" 954c8a0e2f4SThomas Veerman makeenv="${makeenv} $1" 955c8a0e2f4SThomas Veerman} 956c8a0e2f4SThomas Veerman 957c8a0e2f4SThomas Veermanunsetmakeenv() 958c8a0e2f4SThomas Veerman{ 959c8a0e2f4SThomas Veerman eval "unset $1" 960c8a0e2f4SThomas Veerman makeenv="${makeenv} $1" 961c8a0e2f4SThomas Veerman} 962c8a0e2f4SThomas Veerman 963c8a0e2f4SThomas Veerman# Given a variable name in $1, modify the variable in place as follows: 964c8a0e2f4SThomas Veerman# For each space-separated word in the variable, call resolvepath. 965c8a0e2f4SThomas Veermanresolvepaths() 966c8a0e2f4SThomas Veerman{ 967c8a0e2f4SThomas Veerman local var="$1" 968c8a0e2f4SThomas Veerman local val 969c8a0e2f4SThomas Veerman eval val=\"\${${var}}\" 970c8a0e2f4SThomas Veerman local newval='' 971c8a0e2f4SThomas Veerman local word 972c8a0e2f4SThomas Veerman for word in ${val}; do 973c8a0e2f4SThomas Veerman resolvepath word 974c8a0e2f4SThomas Veerman newval="${newval}${newval:+ }${word}" 975c8a0e2f4SThomas Veerman done 976c8a0e2f4SThomas Veerman eval ${var}=\"\${newval}\" 977c8a0e2f4SThomas Veerman} 978c8a0e2f4SThomas Veerman 979c8a0e2f4SThomas Veerman# Given a variable name in $1, modify the variable in place as follows: 980c8a0e2f4SThomas Veerman# Convert possibly-relative path to absolute path by prepending 981c8a0e2f4SThomas Veerman# ${TOP} if necessary. Also delete trailing "/", if any. 982c8a0e2f4SThomas Veermanresolvepath() 983c8a0e2f4SThomas Veerman{ 984c8a0e2f4SThomas Veerman local var="$1" 985c8a0e2f4SThomas Veerman local val 986c8a0e2f4SThomas Veerman eval val=\"\${${var}}\" 987c8a0e2f4SThomas Veerman case "${val}" in 988c8a0e2f4SThomas Veerman /) 989c8a0e2f4SThomas Veerman ;; 990c8a0e2f4SThomas Veerman /*) 991c8a0e2f4SThomas Veerman val="${val%/}" 992c8a0e2f4SThomas Veerman ;; 993c8a0e2f4SThomas Veerman *) 994c8a0e2f4SThomas Veerman val="${TOP}/${val%/}" 995c8a0e2f4SThomas Veerman ;; 996c8a0e2f4SThomas Veerman esac 997c8a0e2f4SThomas Veerman eval ${var}=\"\${val}\" 998c8a0e2f4SThomas Veerman} 999c8a0e2f4SThomas Veerman 1000c8a0e2f4SThomas Veermanusage() 1001c8a0e2f4SThomas Veerman{ 1002c8a0e2f4SThomas Veerman if [ -n "$*" ]; then 1003c8a0e2f4SThomas Veerman echo "" 1004c8a0e2f4SThomas Veerman echo "${progname}: $*" 1005c8a0e2f4SThomas Veerman fi 1006c8a0e2f4SThomas Veerman cat <<_usage_ 1007c8a0e2f4SThomas Veerman 1008c8a0e2f4SThomas VeermanUsage: ${progname} [-EhnorUuxy] [-a arch] [-B buildid] [-C cdextras] 1009c8a0e2f4SThomas Veerman [-D dest] [-j njob] [-M obj] [-m mach] [-N noisy] 1010c8a0e2f4SThomas Veerman [-O obj] [-R release] [-S seed] [-T tools] 1011c8a0e2f4SThomas Veerman [-V var=[value]] [-w wrapper] [-X x11src] [-Y extsrcsrc] 1012c8a0e2f4SThomas Veerman [-Z var] 1013c8a0e2f4SThomas Veerman operation [...] 1014c8a0e2f4SThomas Veerman 1015c8a0e2f4SThomas Veerman Build operations (all imply "obj" and "tools"): 1016c8a0e2f4SThomas Veerman build Run "make build". 1017c8a0e2f4SThomas Veerman distribution Run "make distribution" (includes DESTDIR/etc/ files). 1018c8a0e2f4SThomas Veerman release Run "make release" (includes kernels & distrib media). 1019c8a0e2f4SThomas Veerman 1020c8a0e2f4SThomas Veerman Other operations: 1021c8a0e2f4SThomas Veerman help Show this message and exit. 1022c8a0e2f4SThomas Veerman makewrapper Create ${toolprefix}make-\${MACHINE} wrapper and ${toolprefix}make. 1023c8a0e2f4SThomas Veerman Always performed. 1024c8a0e2f4SThomas Veerman cleandir Run "make cleandir". [Default unless -u is used] 1025c8a0e2f4SThomas Veerman obj Run "make obj". [Default unless -o is used] 1026c8a0e2f4SThomas Veerman tools Build and install tools. 1027c8a0e2f4SThomas Veerman install=idir Run "make installworld" to \`idir' to install all sets 1028c8a0e2f4SThomas Veerman except \`etc'. Useful after "distribution" or "release" 1029c8a0e2f4SThomas Veerman kernel=conf Build kernel with config file \`conf' 1030*0a6a1f1dSLionel Sambuc kernel.gdb=conf Build kernel (including netbsd.gdb) with config 1031*0a6a1f1dSLionel Sambuc file \`conf' 1032c8a0e2f4SThomas Veerman releasekernel=conf Install kernel built by kernel=conf to RELEASEDIR. 1033*0a6a1f1dSLionel Sambuc kernels Build all kernels 1034c8a0e2f4SThomas Veerman installmodules=idir Run "make installmodules" to \`idir' to install all 1035c8a0e2f4SThomas Veerman kernel modules. 1036c8a0e2f4SThomas Veerman modules Build kernel modules. 1037c8a0e2f4SThomas Veerman rumptest Do a linktest for rump (for developers). 1038c8a0e2f4SThomas Veerman sets Create binary sets in 1039c8a0e2f4SThomas Veerman RELEASEDIR/RELEASEMACHINEDIR/binary/sets. 1040c8a0e2f4SThomas Veerman DESTDIR should be populated beforehand. 1041c8a0e2f4SThomas Veerman sourcesets Create source sets in RELEASEDIR/source/sets. 1042c8a0e2f4SThomas Veerman syspkgs Create syspkgs in 1043c8a0e2f4SThomas Veerman RELEASEDIR/RELEASEMACHINEDIR/binary/syspkgs. 1044*0a6a1f1dSLionel Sambuc iso-image Create CD-ROM image in RELEASEDIR/images. 1045*0a6a1f1dSLionel Sambuc iso-image-source Create CD-ROM image with source in RELEASEDIR/images. 1046c8a0e2f4SThomas Veerman live-image Create bootable live image in 1047c8a0e2f4SThomas Veerman RELEASEDIR/RELEASEMACHINEDIR/installation/liveimage. 1048c8a0e2f4SThomas Veerman install-image Create bootable installation image in 1049c8a0e2f4SThomas Veerman RELEASEDIR/RELEASEMACHINEDIR/installation/installimage. 1050*0a6a1f1dSLionel Sambuc disk-image=target Create bootable disk image in 105184d9c625SLionel Sambuc RELEASEDIR/RELEASEMACHINEDIR/binary/gzimg/target.img.gz. 1052*0a6a1f1dSLionel Sambuc params Display various make(1) parameters. 1053*0a6a1f1dSLionel Sambuc list-arch Display a list of valid MACHINE/MACHINE_ARCH values, 1054*0a6a1f1dSLionel Sambuc and exit. The list may be narrowed by passing glob 1055*0a6a1f1dSLionel Sambuc patterns or exact values in MACHINE or MACHINE_ARCH. 1056c8a0e2f4SThomas Veerman 1057c8a0e2f4SThomas Veerman Options: 1058c8a0e2f4SThomas Veerman -a arch Set MACHINE_ARCH to arch. [Default: deduced from MACHINE] 1059c8a0e2f4SThomas Veerman -B buildid Set BUILDID to buildid. 1060c8a0e2f4SThomas Veerman -C cdextras Append cdextras to CDEXTRA variable for inclusion on CD-ROM. 1061c8a0e2f4SThomas Veerman -D dest Set DESTDIR to dest. [Default: destdir.MACHINE] 1062c8a0e2f4SThomas Veerman -E Set "expert" mode; disables various safety checks. 1063c8a0e2f4SThomas Veerman Should not be used without expert knowledge of the build system. 1064c8a0e2f4SThomas Veerman -h Print this help message. 1065c8a0e2f4SThomas Veerman -j njob Run up to njob jobs in parallel; see make(1) -j. 1066c8a0e2f4SThomas Veerman -M obj Set obj root directory to obj; sets MAKEOBJDIRPREFIX. 1067c8a0e2f4SThomas Veerman Unsets MAKEOBJDIR. 1068*0a6a1f1dSLionel Sambuc -m mach Set MACHINE to mach. Some mach values are actually 1069*0a6a1f1dSLionel Sambuc aliases that set MACHINE/MACHINE_ARCH pairs. 1070*0a6a1f1dSLionel Sambuc [Default: deduced from the host system if the host 1071*0a6a1f1dSLionel Sambuc OS is NetBSD] 1072c8a0e2f4SThomas Veerman -N noisy Set the noisyness (MAKEVERBOSE) level of the build: 1073c8a0e2f4SThomas Veerman 0 Minimal output ("quiet") 1074c8a0e2f4SThomas Veerman 1 Describe what is occurring 1075c8a0e2f4SThomas Veerman 2 Describe what is occurring and echo the actual command 1076c8a0e2f4SThomas Veerman 3 Ignore the effect of the "@" prefix in make commands 1077c8a0e2f4SThomas Veerman 4 Trace shell commands using the shell's -x flag 1078c8a0e2f4SThomas Veerman [Default: 2] 1079c8a0e2f4SThomas Veerman -n Show commands that would be executed, but do not execute them. 1080c8a0e2f4SThomas Veerman -O obj Set obj root directory to obj; sets a MAKEOBJDIR pattern. 1081c8a0e2f4SThomas Veerman Unsets MAKEOBJDIRPREFIX. 1082c8a0e2f4SThomas Veerman -o Set MKOBJDIRS=no; do not create objdirs at start of build. 1083c8a0e2f4SThomas Veerman -R release Set RELEASEDIR to release. [Default: releasedir] 1084c8a0e2f4SThomas Veerman -r Remove contents of TOOLDIR and DESTDIR before building. 1085c8a0e2f4SThomas Veerman -S seed Set BUILDSEED to seed. [Default: NetBSD-majorversion] 1086c8a0e2f4SThomas Veerman -T tools Set TOOLDIR to tools. If unset, and TOOLDIR is not set in 1087c8a0e2f4SThomas Veerman the environment, ${toolprefix}make will be (re)built 1088c8a0e2f4SThomas Veerman unconditionally. 1089c8a0e2f4SThomas Veerman -U Set MKUNPRIVED=yes; build without requiring root privileges, 1090c8a0e2f4SThomas Veerman install from an UNPRIVED build with proper file permissions. 1091c8a0e2f4SThomas Veerman -u Set MKUPDATE=yes; do not run "make cleandir" first. 1092c8a0e2f4SThomas Veerman Without this, everything is rebuilt, including the tools. 1093c8a0e2f4SThomas Veerman -V var=[value] Set variable \`var' to \`value'. 1094c8a0e2f4SThomas Veerman -w wrapper Create ${toolprefix}make script as wrapper. 1095c8a0e2f4SThomas Veerman [Default: \${TOOLDIR}/bin/${toolprefix}make-\${MACHINE}] 1096c8a0e2f4SThomas Veerman -X x11src Set X11SRCDIR to x11src. [Default: /usr/xsrc] 1097c8a0e2f4SThomas Veerman -x Set MKX11=yes; build X11 from X11SRCDIR 1098c8a0e2f4SThomas Veerman -Y extsrcsrc Set EXTSRCSRCDIR to extsrcsrc. [Default: /usr/extsrc] 1099c8a0e2f4SThomas Veerman -y Set MKEXTSRC=yes; build extsrc from EXTSRCSRCDIR 1100c8a0e2f4SThomas Veerman -Z var Unset ("zap") variable \`var'. 1101c8a0e2f4SThomas Veerman 1102c8a0e2f4SThomas Veerman_usage_ 1103c8a0e2f4SThomas Veerman exit 1 1104c8a0e2f4SThomas Veerman} 1105c8a0e2f4SThomas Veerman 1106c8a0e2f4SThomas Veermanparseoptions() 1107c8a0e2f4SThomas Veerman{ 1108c8a0e2f4SThomas Veerman opts='a:B:C:D:Ehj:M:m:N:nO:oR:rS:T:UuV:w:X:xY:yZ:' 1109*0a6a1f1dSLionel Sambuc opt_a=false 1110*0a6a1f1dSLionel Sambuc opt_m=false 1111c8a0e2f4SThomas Veerman 1112c8a0e2f4SThomas Veerman if type getopts >/dev/null 2>&1; then 1113c8a0e2f4SThomas Veerman # Use POSIX getopts. 1114c8a0e2f4SThomas Veerman # 1115c8a0e2f4SThomas Veerman getoptcmd='getopts ${opts} opt && opt=-${opt}' 1116c8a0e2f4SThomas Veerman optargcmd=':' 1117c8a0e2f4SThomas Veerman optremcmd='shift $((${OPTIND} -1))' 1118c8a0e2f4SThomas Veerman else 1119c8a0e2f4SThomas Veerman type getopt >/dev/null 2>&1 || 1120c8a0e2f4SThomas Veerman bomb "Shell does not support getopts or getopt" 1121c8a0e2f4SThomas Veerman 1122c8a0e2f4SThomas Veerman # Use old-style getopt(1) (doesn't handle whitespace in args). 1123c8a0e2f4SThomas Veerman # 1124c8a0e2f4SThomas Veerman args="$(getopt ${opts} $*)" 1125c8a0e2f4SThomas Veerman [ $? = 0 ] || usage 1126c8a0e2f4SThomas Veerman set -- ${args} 1127c8a0e2f4SThomas Veerman 1128c8a0e2f4SThomas Veerman getoptcmd='[ $# -gt 0 ] && opt="$1" && shift' 1129c8a0e2f4SThomas Veerman optargcmd='OPTARG="$1"; shift' 1130c8a0e2f4SThomas Veerman optremcmd=':' 1131c8a0e2f4SThomas Veerman fi 1132c8a0e2f4SThomas Veerman 1133c8a0e2f4SThomas Veerman # Parse command line options. 1134c8a0e2f4SThomas Veerman # 1135c8a0e2f4SThomas Veerman while eval ${getoptcmd}; do 1136c8a0e2f4SThomas Veerman case ${opt} in 1137c8a0e2f4SThomas Veerman 1138c8a0e2f4SThomas Veerman -a) 1139c8a0e2f4SThomas Veerman eval ${optargcmd} 1140c8a0e2f4SThomas Veerman MACHINE_ARCH=${OPTARG} 1141*0a6a1f1dSLionel Sambuc opt_a=true 1142c8a0e2f4SThomas Veerman ;; 1143c8a0e2f4SThomas Veerman 1144c8a0e2f4SThomas Veerman -B) 1145c8a0e2f4SThomas Veerman eval ${optargcmd} 1146c8a0e2f4SThomas Veerman BUILDID=${OPTARG} 1147c8a0e2f4SThomas Veerman ;; 1148c8a0e2f4SThomas Veerman 1149c8a0e2f4SThomas Veerman -C) 1150c8a0e2f4SThomas Veerman eval ${optargcmd}; resolvepaths OPTARG 1151c8a0e2f4SThomas Veerman CDEXTRA="${CDEXTRA}${CDEXTRA:+ }${OPTARG}" 1152c8a0e2f4SThomas Veerman ;; 1153c8a0e2f4SThomas Veerman 1154c8a0e2f4SThomas Veerman -D) 1155c8a0e2f4SThomas Veerman eval ${optargcmd}; resolvepath OPTARG 1156c8a0e2f4SThomas Veerman setmakeenv DESTDIR "${OPTARG}" 1157c8a0e2f4SThomas Veerman ;; 1158c8a0e2f4SThomas Veerman 1159c8a0e2f4SThomas Veerman -E) 1160c8a0e2f4SThomas Veerman do_expertmode=true 1161c8a0e2f4SThomas Veerman ;; 1162c8a0e2f4SThomas Veerman 1163c8a0e2f4SThomas Veerman -j) 1164c8a0e2f4SThomas Veerman eval ${optargcmd} 1165c8a0e2f4SThomas Veerman parallel="-j ${OPTARG}" 1166c8a0e2f4SThomas Veerman ;; 1167c8a0e2f4SThomas Veerman 1168c8a0e2f4SThomas Veerman -M) 1169c8a0e2f4SThomas Veerman eval ${optargcmd}; resolvepath OPTARG 1170c8a0e2f4SThomas Veerman case "${OPTARG}" in 1171c8a0e2f4SThomas Veerman \$*) usage "-M argument must not begin with '\$'" 1172c8a0e2f4SThomas Veerman ;; 1173c8a0e2f4SThomas Veerman *\$*) # can use resolvepath, but can't set TOP_objdir 1174c8a0e2f4SThomas Veerman resolvepath OPTARG 1175c8a0e2f4SThomas Veerman ;; 1176c8a0e2f4SThomas Veerman *) resolvepath OPTARG 1177c8a0e2f4SThomas Veerman TOP_objdir="${OPTARG}${TOP}" 1178c8a0e2f4SThomas Veerman ;; 1179c8a0e2f4SThomas Veerman esac 1180c8a0e2f4SThomas Veerman unsetmakeenv MAKEOBJDIR 1181c8a0e2f4SThomas Veerman setmakeenv MAKEOBJDIRPREFIX "${OPTARG}" 1182c8a0e2f4SThomas Veerman ;; 1183c8a0e2f4SThomas Veerman 1184c8a0e2f4SThomas Veerman # -m overrides MACHINE_ARCH unless "-a" is specified 1185c8a0e2f4SThomas Veerman -m) 1186c8a0e2f4SThomas Veerman eval ${optargcmd} 1187c8a0e2f4SThomas Veerman MACHINE="${OPTARG}" 1188*0a6a1f1dSLionel Sambuc opt_m=true 1189c8a0e2f4SThomas Veerman ;; 1190c8a0e2f4SThomas Veerman 1191c8a0e2f4SThomas Veerman -N) 1192c8a0e2f4SThomas Veerman eval ${optargcmd} 1193c8a0e2f4SThomas Veerman case "${OPTARG}" in 1194c8a0e2f4SThomas Veerman 0|1|2|3|4) 1195c8a0e2f4SThomas Veerman setmakeenv MAKEVERBOSE "${OPTARG}" 1196c8a0e2f4SThomas Veerman ;; 1197c8a0e2f4SThomas Veerman *) 1198c8a0e2f4SThomas Veerman usage "'${OPTARG}' is not a valid value for -N" 1199c8a0e2f4SThomas Veerman ;; 1200c8a0e2f4SThomas Veerman esac 1201c8a0e2f4SThomas Veerman ;; 1202c8a0e2f4SThomas Veerman 1203c8a0e2f4SThomas Veerman -n) 1204c8a0e2f4SThomas Veerman runcmd=echo 1205c8a0e2f4SThomas Veerman ;; 1206c8a0e2f4SThomas Veerman 1207c8a0e2f4SThomas Veerman -O) 1208c8a0e2f4SThomas Veerman eval ${optargcmd} 1209c8a0e2f4SThomas Veerman case "${OPTARG}" in 1210c8a0e2f4SThomas Veerman *\$*) usage "-O argument must not contain '\$'" 1211c8a0e2f4SThomas Veerman ;; 1212c8a0e2f4SThomas Veerman *) resolvepath OPTARG 1213c8a0e2f4SThomas Veerman TOP_objdir="${OPTARG}" 1214c8a0e2f4SThomas Veerman ;; 1215c8a0e2f4SThomas Veerman esac 1216c8a0e2f4SThomas Veerman unsetmakeenv MAKEOBJDIRPREFIX 1217c8a0e2f4SThomas Veerman setmakeenv MAKEOBJDIR "\${.CURDIR:C,^$TOP,$OPTARG,}" 1218c8a0e2f4SThomas Veerman ;; 1219c8a0e2f4SThomas Veerman 1220c8a0e2f4SThomas Veerman -o) 1221c8a0e2f4SThomas Veerman MKOBJDIRS=no 1222c8a0e2f4SThomas Veerman ;; 1223c8a0e2f4SThomas Veerman 1224c8a0e2f4SThomas Veerman -R) 1225c8a0e2f4SThomas Veerman eval ${optargcmd}; resolvepath OPTARG 1226c8a0e2f4SThomas Veerman setmakeenv RELEASEDIR "${OPTARG}" 1227c8a0e2f4SThomas Veerman ;; 1228c8a0e2f4SThomas Veerman 1229c8a0e2f4SThomas Veerman -r) 1230c8a0e2f4SThomas Veerman do_removedirs=true 1231c8a0e2f4SThomas Veerman do_rebuildmake=true 1232c8a0e2f4SThomas Veerman ;; 1233c8a0e2f4SThomas Veerman 1234c8a0e2f4SThomas Veerman -S) 1235c8a0e2f4SThomas Veerman eval ${optargcmd} 1236c8a0e2f4SThomas Veerman setmakeenv BUILDSEED "${OPTARG}" 1237c8a0e2f4SThomas Veerman ;; 1238c8a0e2f4SThomas Veerman 1239c8a0e2f4SThomas Veerman -T) 1240c8a0e2f4SThomas Veerman eval ${optargcmd}; resolvepath OPTARG 1241c8a0e2f4SThomas Veerman TOOLDIR="${OPTARG}" 1242c8a0e2f4SThomas Veerman export TOOLDIR 1243c8a0e2f4SThomas Veerman ;; 1244c8a0e2f4SThomas Veerman 1245c8a0e2f4SThomas Veerman -U) 1246c8a0e2f4SThomas Veerman setmakeenv MKUNPRIVED yes 1247c8a0e2f4SThomas Veerman ;; 1248c8a0e2f4SThomas Veerman 1249c8a0e2f4SThomas Veerman -u) 1250c8a0e2f4SThomas Veerman setmakeenv MKUPDATE yes 1251c8a0e2f4SThomas Veerman ;; 1252c8a0e2f4SThomas Veerman 1253c8a0e2f4SThomas Veerman -V) 1254c8a0e2f4SThomas Veerman eval ${optargcmd} 1255c8a0e2f4SThomas Veerman case "${OPTARG}" in 1256c8a0e2f4SThomas Veerman # XXX: consider restricting which variables can be changed? 1257c8a0e2f4SThomas Veerman [a-zA-Z_][a-zA-Z_0-9]*=*) 1258c8a0e2f4SThomas Veerman setmakeenv "${OPTARG%%=*}" "${OPTARG#*=}" 1259c8a0e2f4SThomas Veerman ;; 1260c8a0e2f4SThomas Veerman *) 1261c8a0e2f4SThomas Veerman usage "-V argument must be of the form 'var=[value]'" 1262c8a0e2f4SThomas Veerman ;; 1263c8a0e2f4SThomas Veerman esac 1264c8a0e2f4SThomas Veerman ;; 1265c8a0e2f4SThomas Veerman 1266c8a0e2f4SThomas Veerman -w) 1267c8a0e2f4SThomas Veerman eval ${optargcmd}; resolvepath OPTARG 1268c8a0e2f4SThomas Veerman makewrapper="${OPTARG}" 1269c8a0e2f4SThomas Veerman ;; 1270c8a0e2f4SThomas Veerman 1271c8a0e2f4SThomas Veerman -X) 1272c8a0e2f4SThomas Veerman eval ${optargcmd}; resolvepath OPTARG 1273c8a0e2f4SThomas Veerman setmakeenv X11SRCDIR "${OPTARG}" 1274c8a0e2f4SThomas Veerman ;; 1275c8a0e2f4SThomas Veerman 1276c8a0e2f4SThomas Veerman -x) 1277c8a0e2f4SThomas Veerman setmakeenv MKX11 yes 1278c8a0e2f4SThomas Veerman ;; 1279c8a0e2f4SThomas Veerman 1280c8a0e2f4SThomas Veerman -Y) 1281c8a0e2f4SThomas Veerman eval ${optargcmd}; resolvepath OPTARG 1282c8a0e2f4SThomas Veerman setmakeenv EXTSRCSRCDIR "${OPTARG}" 1283c8a0e2f4SThomas Veerman ;; 1284c8a0e2f4SThomas Veerman 1285c8a0e2f4SThomas Veerman -y) 1286c8a0e2f4SThomas Veerman setmakeenv MKEXTSRC yes 1287c8a0e2f4SThomas Veerman ;; 1288c8a0e2f4SThomas Veerman 1289c8a0e2f4SThomas Veerman -Z) 1290c8a0e2f4SThomas Veerman eval ${optargcmd} 1291c8a0e2f4SThomas Veerman # XXX: consider restricting which variables can be unset? 1292c8a0e2f4SThomas Veerman unsetmakeenv "${OPTARG}" 1293c8a0e2f4SThomas Veerman ;; 1294c8a0e2f4SThomas Veerman 1295c8a0e2f4SThomas Veerman --) 1296c8a0e2f4SThomas Veerman break 1297c8a0e2f4SThomas Veerman ;; 1298c8a0e2f4SThomas Veerman 1299c8a0e2f4SThomas Veerman -'?'|-h) 1300c8a0e2f4SThomas Veerman usage 1301c8a0e2f4SThomas Veerman ;; 1302c8a0e2f4SThomas Veerman 1303c8a0e2f4SThomas Veerman esac 1304c8a0e2f4SThomas Veerman done 1305c8a0e2f4SThomas Veerman 1306c8a0e2f4SThomas Veerman # Validate operations. 1307c8a0e2f4SThomas Veerman # 1308c8a0e2f4SThomas Veerman eval ${optremcmd} 1309c8a0e2f4SThomas Veerman while [ $# -gt 0 ]; do 1310c8a0e2f4SThomas Veerman op=$1; shift 1311c8a0e2f4SThomas Veerman operations="${operations} ${op}" 1312c8a0e2f4SThomas Veerman 1313c8a0e2f4SThomas Veerman case "${op}" in 1314c8a0e2f4SThomas Veerman 1315c8a0e2f4SThomas Veerman help) 1316c8a0e2f4SThomas Veerman usage 1317c8a0e2f4SThomas Veerman ;; 1318c8a0e2f4SThomas Veerman 1319*0a6a1f1dSLionel Sambuc list-arch) 1320*0a6a1f1dSLionel Sambuc listarch "${MACHINE}" "${MACHINE_ARCH}" 1321*0a6a1f1dSLionel Sambuc exit $? 132284d9c625SLionel Sambuc ;; 132384d9c625SLionel Sambuc 132484d9c625SLionel Sambuc show-params) 132584d9c625SLionel Sambuc op=show_params # used as part of a variable name 1326c8a0e2f4SThomas Veerman ;; 1327c8a0e2f4SThomas Veerman 1328*0a6a1f1dSLionel Sambuc kernel=*|releasekernel=*|kernel.gdb=*) 1329c8a0e2f4SThomas Veerman arg=${op#*=} 1330c8a0e2f4SThomas Veerman op=${op%%=*} 1331c8a0e2f4SThomas Veerman [ -n "${arg}" ] || 1332c8a0e2f4SThomas Veerman bomb "Must supply a kernel name with \`${op}=...'" 1333c8a0e2f4SThomas Veerman ;; 1334c8a0e2f4SThomas Veerman 133584d9c625SLionel Sambuc disk-image=*) 133684d9c625SLionel Sambuc arg=${op#*=} 133784d9c625SLionel Sambuc op=disk_image 133884d9c625SLionel Sambuc [ -n "${arg}" ] || 133984d9c625SLionel Sambuc bomb "Must supply a target name with \`${op}=...'" 134084d9c625SLionel Sambuc 134184d9c625SLionel Sambuc ;; 134284d9c625SLionel Sambuc 1343c8a0e2f4SThomas Veerman install=*|installmodules=*) 1344c8a0e2f4SThomas Veerman arg=${op#*=} 1345c8a0e2f4SThomas Veerman op=${op%%=*} 1346c8a0e2f4SThomas Veerman [ -n "${arg}" ] || 1347c8a0e2f4SThomas Veerman bomb "Must supply a directory with \`install=...'" 1348c8a0e2f4SThomas Veerman ;; 1349c8a0e2f4SThomas Veerman 1350*0a6a1f1dSLionel Sambuc build|\ 1351*0a6a1f1dSLionel Sambuc cleandir|\ 1352*0a6a1f1dSLionel Sambuc distribution|\ 1353*0a6a1f1dSLionel Sambuc install-image|\ 1354*0a6a1f1dSLionel Sambuc iso-image-source|\ 1355*0a6a1f1dSLionel Sambuc iso-image|\ 1356*0a6a1f1dSLionel Sambuc kernels|\ 1357*0a6a1f1dSLionel Sambuc live-image|\ 1358*0a6a1f1dSLionel Sambuc makewrapper|\ 1359*0a6a1f1dSLionel Sambuc modules|\ 1360*0a6a1f1dSLionel Sambuc obj|\ 1361*0a6a1f1dSLionel Sambuc params|\ 1362*0a6a1f1dSLionel Sambuc release|\ 1363*0a6a1f1dSLionel Sambuc rump|\ 1364*0a6a1f1dSLionel Sambuc rumptest|\ 1365*0a6a1f1dSLionel Sambuc sets|\ 1366*0a6a1f1dSLionel Sambuc sourcesets|\ 1367*0a6a1f1dSLionel Sambuc syspkgs|\ 1368*0a6a1f1dSLionel Sambuc tools) 1369c8a0e2f4SThomas Veerman ;; 1370c8a0e2f4SThomas Veerman 1371c8a0e2f4SThomas Veerman *) 1372c8a0e2f4SThomas Veerman usage "Unknown operation \`${op}'" 1373c8a0e2f4SThomas Veerman ;; 1374c8a0e2f4SThomas Veerman 1375c8a0e2f4SThomas Veerman esac 1376*0a6a1f1dSLionel Sambuc # ${op} may contain chars that are not allowed in variable 1377*0a6a1f1dSLionel Sambuc # names. Replace them with '_' before setting do_${op}. 1378*0a6a1f1dSLionel Sambuc op="$( echo "$op" | tr -s '.-' '__')" 1379c8a0e2f4SThomas Veerman eval do_${op}=true 1380c8a0e2f4SThomas Veerman done 1381c8a0e2f4SThomas Veerman [ -n "${operations}" ] || usage "Missing operation to perform." 1382c8a0e2f4SThomas Veerman 1383c8a0e2f4SThomas Veerman # Set up MACHINE*. On a NetBSD host, these are allowed to be unset. 1384c8a0e2f4SThomas Veerman # 1385c8a0e2f4SThomas Veerman if [ -z "${MACHINE}" ]; then 1386c8a0e2f4SThomas Veerman [ "${uname_s}" = "Minix" ] || 1387c8a0e2f4SThomas Veerman bomb "MACHINE must be set, or -m must be used, for cross builds." 1388c8a0e2f4SThomas Veerman MACHINE=${uname_m} 1389c8a0e2f4SThomas Veerman fi 1390*0a6a1f1dSLionel Sambuc if $opt_m && ! $opt_a; then 1391*0a6a1f1dSLionel Sambuc # Settings implied by the command line -m option 1392*0a6a1f1dSLionel Sambuc # override MACHINE_ARCH from the environment (if any). 1393*0a6a1f1dSLionel Sambuc getarch 1394*0a6a1f1dSLionel Sambuc fi 1395c8a0e2f4SThomas Veerman [ -n "${MACHINE_ARCH}" ] || getarch 1396c8a0e2f4SThomas Veerman validatearch 1397c8a0e2f4SThomas Veerman 1398c8a0e2f4SThomas Veerman # Set up default make(1) environment. 1399c8a0e2f4SThomas Veerman # 1400c8a0e2f4SThomas Veerman makeenv="${makeenv} TOOLDIR MACHINE MACHINE_ARCH MAKEFLAGS" 1401c8a0e2f4SThomas Veerman [ -z "${BUILDID}" ] || makeenv="${makeenv} BUILDID" 1402*0a6a1f1dSLionel Sambuc [ -z "${BUILDINFO}" ] || makeenv="${makeenv} BUILDINFO" 1403c8a0e2f4SThomas Veerman MAKEFLAGS="-de -m ${TOP}/share/mk ${MAKEFLAGS}" 1404c8a0e2f4SThomas Veerman MAKEFLAGS="${MAKEFLAGS} MKOBJDIRS=${MKOBJDIRS-yes}" 14059152e1c5SLionel Sambuc export MAKEFLAGS MACHINE MACHINE_ARCH 1406*0a6a1f1dSLionel Sambuc setmakeenv USETOOLS "yes" 1407*0a6a1f1dSLionel Sambuc setmakeenv MAKEWRAPPERMACHINE "${makewrappermachine:-${MACHINE}}" 1408c8a0e2f4SThomas Veerman} 1409c8a0e2f4SThomas Veerman 1410c8a0e2f4SThomas Veerman# sanitycheck -- 1411c8a0e2f4SThomas Veerman# Sanity check after parsing command line options, before rebuildmake. 1412c8a0e2f4SThomas Veerman# 1413c8a0e2f4SThomas Veermansanitycheck() 1414c8a0e2f4SThomas Veerman{ 141584d9c625SLionel Sambuc # Install as non-root is a bad idea. 141684d9c625SLionel Sambuc # 141784d9c625SLionel Sambuc if ${do_install} && [ "$id_u" -ne 0 ] ; then 141884d9c625SLionel Sambuc if ${do_expertmode}; then 141984d9c625SLionel Sambuc warning "Will install as an unprivileged user." 142084d9c625SLionel Sambuc else 142184d9c625SLionel Sambuc bomb "-E must be set for install as an unprivileged user." 142284d9c625SLionel Sambuc fi 142384d9c625SLionel Sambuc fi 142484d9c625SLionel Sambuc 1425c8a0e2f4SThomas Veerman # If the PATH contains any non-absolute components (including, 1426c8a0e2f4SThomas Veerman # but not limited to, "." or ""), then complain. As an exception, 1427c8a0e2f4SThomas Veerman # allow "" or "." as the last component of the PATH. This is fatal 1428c8a0e2f4SThomas Veerman # if expert mode is not in effect. 1429c8a0e2f4SThomas Veerman # 1430c8a0e2f4SThomas Veerman local path="${PATH}" 1431c8a0e2f4SThomas Veerman path="${path%:}" # delete trailing ":" 1432c8a0e2f4SThomas Veerman path="${path%:.}" # delete trailing ":." 1433c8a0e2f4SThomas Veerman case ":${path}:/" in 1434c8a0e2f4SThomas Veerman *:[!/]*) 1435c8a0e2f4SThomas Veerman if ${do_expertmode}; then 1436c8a0e2f4SThomas Veerman warning "PATH contains non-absolute components" 1437c8a0e2f4SThomas Veerman else 1438c8a0e2f4SThomas Veerman bomb "PATH environment variable must not" \ 1439c8a0e2f4SThomas Veerman "contain non-absolute components" 1440c8a0e2f4SThomas Veerman fi 1441c8a0e2f4SThomas Veerman ;; 1442c8a0e2f4SThomas Veerman esac 1443c8a0e2f4SThomas Veerman} 1444c8a0e2f4SThomas Veerman 1445c8a0e2f4SThomas Veerman# print_tooldir_make -- 1446c8a0e2f4SThomas Veerman# Try to find and print a path to an existing 1447c8a0e2f4SThomas Veerman# ${TOOLDIR}/bin/${toolprefix}make, for use by rebuildmake() before a 1448c8a0e2f4SThomas Veerman# new version of ${toolprefix}make has been built. 1449c8a0e2f4SThomas Veerman# 1450c8a0e2f4SThomas Veerman# * If TOOLDIR was set in the environment or on the command line, use 1451c8a0e2f4SThomas Veerman# that value. 1452c8a0e2f4SThomas Veerman# * Otherwise try to guess what TOOLDIR would be if not overridden by 1453c8a0e2f4SThomas Veerman# /etc/mk.conf, and check whether the resulting directory contains 1454c8a0e2f4SThomas Veerman# a copy of ${toolprefix}make (this should work for everybody who 1455c8a0e2f4SThomas Veerman# doesn't override TOOLDIR via /etc/mk.conf); 1456c8a0e2f4SThomas Veerman# * Failing that, search for ${toolprefix}make, nbmake, bmake, or make, 1457c8a0e2f4SThomas Veerman# in the PATH (this might accidentally find a version of make that 1458c8a0e2f4SThomas Veerman# does not understand the syntax used by NetBSD make, and that will 1459c8a0e2f4SThomas Veerman# lead to failure in the next step); 1460c8a0e2f4SThomas Veerman# * If a copy of make was found above, try to use it with 1461c8a0e2f4SThomas Veerman# nobomb_getmakevar to find the correct value for TOOLDIR, and believe the 1462c8a0e2f4SThomas Veerman# result only if it's a directory that already exists; 1463c8a0e2f4SThomas Veerman# * If a value of TOOLDIR was found above, and if 1464c8a0e2f4SThomas Veerman# ${TOOLDIR}/bin/${toolprefix}make exists, print that value. 1465c8a0e2f4SThomas Veerman# 1466c8a0e2f4SThomas Veermanprint_tooldir_make() 1467c8a0e2f4SThomas Veerman{ 1468c8a0e2f4SThomas Veerman local possible_TOP_OBJ 1469c8a0e2f4SThomas Veerman local possible_TOOLDIR 1470c8a0e2f4SThomas Veerman local possible_make 1471c8a0e2f4SThomas Veerman local tooldir_make 1472c8a0e2f4SThomas Veerman 1473c8a0e2f4SThomas Veerman if [ -n "${TOOLDIR}" ]; then 1474c8a0e2f4SThomas Veerman echo "${TOOLDIR}/bin/${toolprefix}make" 1475c8a0e2f4SThomas Veerman return 0 1476c8a0e2f4SThomas Veerman fi 1477c8a0e2f4SThomas Veerman 1478c8a0e2f4SThomas Veerman # Set host_ostype to something like "NetBSD-4.5.6-i386". This 1479c8a0e2f4SThomas Veerman # is intended to match the HOST_OSTYPE variable in <bsd.own.mk>. 1480c8a0e2f4SThomas Veerman # 1481c8a0e2f4SThomas Veerman local host_ostype="${uname_s}-$( 1482c8a0e2f4SThomas Veerman echo "${uname_r}" | sed -e 's/([^)]*)//g' -e 's/ /_/g' 1483c8a0e2f4SThomas Veerman )-$( 1484c8a0e2f4SThomas Veerman echo "${uname_p}" | sed -e 's/([^)]*)//g' -e 's/ /_/g' 1485c8a0e2f4SThomas Veerman )" 1486c8a0e2f4SThomas Veerman 1487c8a0e2f4SThomas Veerman # Look in a few potential locations for 1488c8a0e2f4SThomas Veerman # ${possible_TOOLDIR}/bin/${toolprefix}make. 1489c8a0e2f4SThomas Veerman # If we find it, then set possible_make. 1490c8a0e2f4SThomas Veerman # 1491c8a0e2f4SThomas Veerman # In the usual case (without interference from environment 1492c8a0e2f4SThomas Veerman # variables or /etc/mk.conf), <bsd.own.mk> should set TOOLDIR to 1493c8a0e2f4SThomas Veerman # "${_SRC_TOP_OBJ_}/tooldir.${host_ostype}". 1494c8a0e2f4SThomas Veerman # 1495c8a0e2f4SThomas Veerman # In practice it's difficult to figure out the correct value 1496c8a0e2f4SThomas Veerman # for _SRC_TOP_OBJ_. In the easiest case, when the -M or -O 1497c8a0e2f4SThomas Veerman # options were passed to build.sh, then ${TOP_objdir} will be 1498c8a0e2f4SThomas Veerman # the correct value. We also try a few other possibilities, but 1499c8a0e2f4SThomas Veerman # we do not replicate all the logic of <bsd.obj.mk>. 1500c8a0e2f4SThomas Veerman # 1501c8a0e2f4SThomas Veerman for possible_TOP_OBJ in \ 1502c8a0e2f4SThomas Veerman "${TOP_objdir}" \ 1503c8a0e2f4SThomas Veerman "${MAKEOBJDIRPREFIX:+${MAKEOBJDIRPREFIX}${TOP}}" \ 1504c8a0e2f4SThomas Veerman "${TOP}" \ 1505c8a0e2f4SThomas Veerman "${TOP}/obj" \ 1506c8a0e2f4SThomas Veerman "${TOP}/obj.${MACHINE}" 1507c8a0e2f4SThomas Veerman do 1508c8a0e2f4SThomas Veerman [ -n "${possible_TOP_OBJ}" ] || continue 1509c8a0e2f4SThomas Veerman possible_TOOLDIR="${possible_TOP_OBJ}/tooldir.${host_ostype}" 1510c8a0e2f4SThomas Veerman possible_make="${possible_TOOLDIR}/bin/${toolprefix}make" 1511c8a0e2f4SThomas Veerman if [ -x "${possible_make}" ]; then 1512c8a0e2f4SThomas Veerman break 1513c8a0e2f4SThomas Veerman else 1514c8a0e2f4SThomas Veerman unset possible_make 1515c8a0e2f4SThomas Veerman fi 1516c8a0e2f4SThomas Veerman done 1517c8a0e2f4SThomas Veerman 1518c8a0e2f4SThomas Veerman # If the above didn't work, search the PATH for a suitable 1519c8a0e2f4SThomas Veerman # ${toolprefix}make, nbmake, bmake, or make. 1520c8a0e2f4SThomas Veerman # 1521c8a0e2f4SThomas Veerman : ${possible_make:=$(find_in_PATH ${toolprefix}make '')} 1522c8a0e2f4SThomas Veerman : ${possible_make:=$(find_in_PATH nbmake '')} 1523c8a0e2f4SThomas Veerman : ${possible_make:=$(find_in_PATH bmake '')} 1524c8a0e2f4SThomas Veerman : ${possible_make:=$(find_in_PATH make '')} 1525c8a0e2f4SThomas Veerman 1526c8a0e2f4SThomas Veerman # At this point, we don't care whether possible_make is in the 1527c8a0e2f4SThomas Veerman # correct TOOLDIR or not; we simply want it to be usable by 1528c8a0e2f4SThomas Veerman # getmakevar to help us find the correct TOOLDIR. 1529c8a0e2f4SThomas Veerman # 1530c8a0e2f4SThomas Veerman # Use ${possible_make} with nobomb_getmakevar to try to find 1531c8a0e2f4SThomas Veerman # the value of TOOLDIR. Believe the result only if it's 1532c8a0e2f4SThomas Veerman # a directory that already exists and contains bin/${toolprefix}make. 1533c8a0e2f4SThomas Veerman # 1534c8a0e2f4SThomas Veerman if [ -x "${possible_make}" ]; then 1535c8a0e2f4SThomas Veerman possible_TOOLDIR="$( 1536c8a0e2f4SThomas Veerman make="${possible_make}" \ 1537c8a0e2f4SThomas Veerman nobomb_getmakevar TOOLDIR 2>/dev/null 1538c8a0e2f4SThomas Veerman )" 1539c8a0e2f4SThomas Veerman if [ $? = 0 ] && [ -n "${possible_TOOLDIR}" ] \ 1540c8a0e2f4SThomas Veerman && [ -d "${possible_TOOLDIR}" ]; 1541c8a0e2f4SThomas Veerman then 1542c8a0e2f4SThomas Veerman tooldir_make="${possible_TOOLDIR}/bin/${toolprefix}make" 1543c8a0e2f4SThomas Veerman if [ -x "${tooldir_make}" ]; then 1544c8a0e2f4SThomas Veerman echo "${tooldir_make}" 1545c8a0e2f4SThomas Veerman return 0 1546c8a0e2f4SThomas Veerman fi 1547c8a0e2f4SThomas Veerman fi 1548c8a0e2f4SThomas Veerman fi 1549c8a0e2f4SThomas Veerman return 1 1550c8a0e2f4SThomas Veerman} 1551c8a0e2f4SThomas Veerman 1552c8a0e2f4SThomas Veerman# rebuildmake -- 1553c8a0e2f4SThomas Veerman# Rebuild nbmake in a temporary directory if necessary. Sets $make 1554c8a0e2f4SThomas Veerman# to a path to the nbmake executable. Sets done_rebuildmake=true 1555c8a0e2f4SThomas Veerman# if nbmake was rebuilt. 1556c8a0e2f4SThomas Veerman# 1557c8a0e2f4SThomas Veerman# There is a cyclic dependency between building nbmake and choosing 1558c8a0e2f4SThomas Veerman# TOOLDIR: TOOLDIR may be affected by settings in /etc/mk.conf, so we 1559c8a0e2f4SThomas Veerman# would like to use getmakevar to get the value of TOOLDIR; but we can't 1560c8a0e2f4SThomas Veerman# use getmakevar before we have an up to date version of nbmake; we 1561c8a0e2f4SThomas Veerman# might already have an up to date version of nbmake in TOOLDIR, but we 1562c8a0e2f4SThomas Veerman# don't yet know where TOOLDIR is. 1563c8a0e2f4SThomas Veerman# 1564c8a0e2f4SThomas Veerman# The default value of TOOLDIR also depends on the location of the top 1565c8a0e2f4SThomas Veerman# level object directory, so $(getmakevar TOOLDIR) invoked before or 1566c8a0e2f4SThomas Veerman# after making the top level object directory may produce different 1567c8a0e2f4SThomas Veerman# results. 1568c8a0e2f4SThomas Veerman# 1569c8a0e2f4SThomas Veerman# Strictly speaking, we should do the following: 1570c8a0e2f4SThomas Veerman# 1571c8a0e2f4SThomas Veerman# 1. build a new version of nbmake in a temporary directory; 1572c8a0e2f4SThomas Veerman# 2. use the temporary nbmake to create the top level obj directory; 1573c8a0e2f4SThomas Veerman# 3. use $(getmakevar TOOLDIR) with the temporary nbmake to 157484d9c625SLionel Sambuc# get the correct value of TOOLDIR; 1575c8a0e2f4SThomas Veerman# 4. move the temporary nbmake to ${TOOLDIR}/bin/nbmake. 1576c8a0e2f4SThomas Veerman# 1577c8a0e2f4SThomas Veerman# However, people don't like building nbmake unnecessarily if their 1578c8a0e2f4SThomas Veerman# TOOLDIR has not changed since an earlier build. We try to avoid 1579c8a0e2f4SThomas Veerman# rebuilding a temporary version of nbmake by taking some shortcuts to 1580c8a0e2f4SThomas Veerman# guess a value for TOOLDIR, looking for an existing version of nbmake 1581c8a0e2f4SThomas Veerman# in that TOOLDIR, and checking whether that nbmake is newer than the 1582c8a0e2f4SThomas Veerman# sources used to build it. 1583c8a0e2f4SThomas Veerman# 1584c8a0e2f4SThomas Veermanrebuildmake() 1585c8a0e2f4SThomas Veerman{ 1586c8a0e2f4SThomas Veerman make="$(print_tooldir_make)" 1587c8a0e2f4SThomas Veerman if [ -n "${make}" ] && [ -x "${make}" ]; then 1588c8a0e2f4SThomas Veerman for f in usr.bin/make/*.[ch] usr.bin/make/lst.lib/*.[ch]; do 1589c8a0e2f4SThomas Veerman if [ "${f}" -nt "${make}" ]; then 1590c8a0e2f4SThomas Veerman statusmsg "${make} outdated" \ 1591c8a0e2f4SThomas Veerman "(older than ${f}), needs building." 1592c8a0e2f4SThomas Veerman do_rebuildmake=true 1593c8a0e2f4SThomas Veerman break 1594c8a0e2f4SThomas Veerman fi 1595c8a0e2f4SThomas Veerman done 1596c8a0e2f4SThomas Veerman else 1597c8a0e2f4SThomas Veerman statusmsg "No \$TOOLDIR/bin/${toolprefix}make, needs building." 1598c8a0e2f4SThomas Veerman do_rebuildmake=true 1599c8a0e2f4SThomas Veerman fi 1600c8a0e2f4SThomas Veerman 1601c8a0e2f4SThomas Veerman # Build bootstrap ${toolprefix}make if needed. 1602c8a0e2f4SThomas Veerman if ${do_rebuildmake}; then 1603c8a0e2f4SThomas Veerman statusmsg "Bootstrapping ${toolprefix}make" 1604c8a0e2f4SThomas Veerman ${runcmd} cd "${tmpdir}" 1605c8a0e2f4SThomas Veerman ${runcmd} env CC="${HOST_CC-cc}" CPPFLAGS="${HOST_CPPFLAGS}" \ 1606c8a0e2f4SThomas Veerman CFLAGS="${HOST_CFLAGS--O}" LDFLAGS="${HOST_LDFLAGS}" \ 1607c8a0e2f4SThomas Veerman ${HOST_SH} "${TOP}/tools/make/configure" || 160884d9c625SLionel Sambuc ( cp ${tmpdir}/config.log ${tmpdir}-config.log 160984d9c625SLionel Sambuc bomb "Configure of ${toolprefix}make failed, see ${tmpdir}-config.log for details" ) 1610c8a0e2f4SThomas Veerman ${runcmd} ${HOST_SH} buildmake.sh || 1611c8a0e2f4SThomas Veerman bomb "Build of ${toolprefix}make failed" 1612c8a0e2f4SThomas Veerman make="${tmpdir}/${toolprefix}make" 1613c8a0e2f4SThomas Veerman ${runcmd} cd "${TOP}" 1614c8a0e2f4SThomas Veerman ${runcmd} rm -f usr.bin/make/*.o usr.bin/make/lst.lib/*.o 1615c8a0e2f4SThomas Veerman done_rebuildmake=true 1616c8a0e2f4SThomas Veerman fi 1617c8a0e2f4SThomas Veerman} 1618c8a0e2f4SThomas Veerman 1619c8a0e2f4SThomas Veerman# validatemakeparams -- 1620c8a0e2f4SThomas Veerman# Perform some late sanity checks, after rebuildmake, 1621c8a0e2f4SThomas Veerman# but before createmakewrapper or any real work. 1622c8a0e2f4SThomas Veerman# 162384d9c625SLionel Sambuc# Creates the top-level obj directory, because that 162484d9c625SLionel Sambuc# is needed by some of the sanity checks. 162584d9c625SLionel Sambuc# 162684d9c625SLionel Sambuc# Prints status messages reporting the values of several variables. 1627c8a0e2f4SThomas Veerman# 1628c8a0e2f4SThomas Veermanvalidatemakeparams() 1629c8a0e2f4SThomas Veerman{ 163084d9c625SLionel Sambuc # MAKECONF (which defaults to /etc/mk.conf in share/mk/bsd.own.mk) 163184d9c625SLionel Sambuc # can affect many things, so mention it in an early status message. 163284d9c625SLionel Sambuc # 163384d9c625SLionel Sambuc MAKECONF=$(getmakevar MAKECONF) 163484d9c625SLionel Sambuc if [ -e "${MAKECONF}" ]; then 163584d9c625SLionel Sambuc statusmsg2 "MAKECONF file:" "${MAKECONF}" 163684d9c625SLionel Sambuc else 163784d9c625SLionel Sambuc statusmsg2 "MAKECONF file:" "${MAKECONF} (File not found)" 163884d9c625SLionel Sambuc fi 163984d9c625SLionel Sambuc 1640*0a6a1f1dSLionel Sambuc # Normalise MKOBJDIRS, MKUNPRIVED, and MKUPDATE. 1641*0a6a1f1dSLionel Sambuc # These may be set as build.sh options or in "mk.conf". 1642*0a6a1f1dSLionel Sambuc # Don't export them as they're only used for tests in build.sh. 1643*0a6a1f1dSLionel Sambuc # 1644*0a6a1f1dSLionel Sambuc MKOBJDIRS=$(getmakevar MKOBJDIRS) 1645*0a6a1f1dSLionel Sambuc MKUNPRIVED=$(getmakevar MKUNPRIVED) 1646*0a6a1f1dSLionel Sambuc MKUPDATE=$(getmakevar MKUPDATE) 1647*0a6a1f1dSLionel Sambuc 1648*0a6a1f1dSLionel Sambuc # Non-root should always use either the -U or -E flag. 1649*0a6a1f1dSLionel Sambuc # 1650*0a6a1f1dSLionel Sambuc if ! ${do_expertmode} && \ 1651*0a6a1f1dSLionel Sambuc [ "$id_u" -ne 0 ] && \ 1652*0a6a1f1dSLionel Sambuc [ "${MKUNPRIVED}" = "no" ] ; then 1653*0a6a1f1dSLionel Sambuc bomb "-U or -E must be set for build as an unprivileged user." 1654*0a6a1f1dSLionel Sambuc fi 1655*0a6a1f1dSLionel Sambuc 1656c8a0e2f4SThomas Veerman if [ "${runcmd}" = "echo" ]; then 1657c8a0e2f4SThomas Veerman TOOLCHAIN_MISSING=no 1658c8a0e2f4SThomas Veerman EXTERNAL_TOOLCHAIN="" 1659c8a0e2f4SThomas Veerman else 1660c8a0e2f4SThomas Veerman TOOLCHAIN_MISSING=$(bomb_getmakevar TOOLCHAIN_MISSING) 1661c8a0e2f4SThomas Veerman EXTERNAL_TOOLCHAIN=$(bomb_getmakevar EXTERNAL_TOOLCHAIN) 1662c8a0e2f4SThomas Veerman fi 1663c8a0e2f4SThomas Veerman if [ "${TOOLCHAIN_MISSING}" = "yes" ] && \ 1664c8a0e2f4SThomas Veerman [ -z "${EXTERNAL_TOOLCHAIN}" ]; then 1665c8a0e2f4SThomas Veerman ${runcmd} echo "ERROR: build.sh (in-tree cross-toolchain) is not yet available for" 1666c8a0e2f4SThomas Veerman ${runcmd} echo " MACHINE: ${MACHINE}" 1667c8a0e2f4SThomas Veerman ${runcmd} echo " MACHINE_ARCH: ${MACHINE_ARCH}" 1668c8a0e2f4SThomas Veerman ${runcmd} echo "" 1669c8a0e2f4SThomas Veerman ${runcmd} echo "All builds for this platform should be done via a traditional make" 1670c8a0e2f4SThomas Veerman ${runcmd} echo "If you wish to use an external cross-toolchain, set" 1671c8a0e2f4SThomas Veerman ${runcmd} echo " EXTERNAL_TOOLCHAIN=<path to toolchain root>" 1672c8a0e2f4SThomas Veerman ${runcmd} echo "in either the environment or mk.conf and rerun" 1673c8a0e2f4SThomas Veerman ${runcmd} echo " ${progname} $*" 1674c8a0e2f4SThomas Veerman exit 1 1675c8a0e2f4SThomas Veerman fi 1676c8a0e2f4SThomas Veerman 1677c8a0e2f4SThomas Veerman if [ "${MKOBJDIRS}" != "no" ]; then 1678c8a0e2f4SThomas Veerman # Create the top-level object directory. 1679c8a0e2f4SThomas Veerman # 1680c8a0e2f4SThomas Veerman # "make obj NOSUBDIR=" can handle most cases, but it 1681c8a0e2f4SThomas Veerman # can't handle the case where MAKEOBJDIRPREFIX is set 1682c8a0e2f4SThomas Veerman # while the corresponding directory does not exist 1683c8a0e2f4SThomas Veerman # (rules in <bsd.obj.mk> would abort the build). We 1684c8a0e2f4SThomas Veerman # therefore have to handle the MAKEOBJDIRPREFIX case 1685c8a0e2f4SThomas Veerman # without invoking "make obj". The MAKEOBJDIR case 1686c8a0e2f4SThomas Veerman # could be handled either way, but we choose to handle 1687c8a0e2f4SThomas Veerman # it similarly to MAKEOBJDIRPREFIX. 1688c8a0e2f4SThomas Veerman # 1689c8a0e2f4SThomas Veerman if [ -n "${TOP_obj}" ]; then 1690c8a0e2f4SThomas Veerman # It must have been set by the "-M" or "-O" 1691c8a0e2f4SThomas Veerman # command line options, so there's no need to 1692c8a0e2f4SThomas Veerman # use getmakevar 1693c8a0e2f4SThomas Veerman : 1694c8a0e2f4SThomas Veerman elif [ -n "$MAKEOBJDIRPREFIX" ]; then 1695c8a0e2f4SThomas Veerman TOP_obj="$(getmakevar MAKEOBJDIRPREFIX)${TOP}" 1696c8a0e2f4SThomas Veerman elif [ -n "$MAKEOBJDIR" ]; then 1697c8a0e2f4SThomas Veerman TOP_obj="$(getmakevar MAKEOBJDIR)" 1698c8a0e2f4SThomas Veerman fi 1699c8a0e2f4SThomas Veerman if [ -n "$TOP_obj" ]; then 1700c8a0e2f4SThomas Veerman ${runcmd} mkdir -p "${TOP_obj}" || 1701c8a0e2f4SThomas Veerman bomb "Can't create top level object directory" \ 1702c8a0e2f4SThomas Veerman "${TOP_obj}" 1703c8a0e2f4SThomas Veerman else 1704c8a0e2f4SThomas Veerman ${runcmd} "${make}" -m ${TOP}/share/mk obj NOSUBDIR= || 1705c8a0e2f4SThomas Veerman bomb "Can't create top level object directory" \ 1706c8a0e2f4SThomas Veerman "using make obj" 1707c8a0e2f4SThomas Veerman fi 1708c8a0e2f4SThomas Veerman 1709c8a0e2f4SThomas Veerman # make obj in tools to ensure that the objdir for "tools" 1710c8a0e2f4SThomas Veerman # is available. 1711c8a0e2f4SThomas Veerman # 1712c8a0e2f4SThomas Veerman ${runcmd} cd tools 1713c8a0e2f4SThomas Veerman ${runcmd} "${make}" -m ${TOP}/share/mk obj NOSUBDIR= || 1714c8a0e2f4SThomas Veerman bomb "Failed to make obj in tools" 1715c8a0e2f4SThomas Veerman ${runcmd} cd "${TOP}" 1716c8a0e2f4SThomas Veerman fi 1717c8a0e2f4SThomas Veerman 1718c8a0e2f4SThomas Veerman # Find TOOLDIR, DESTDIR, and RELEASEDIR, according to getmakevar, 1719c8a0e2f4SThomas Veerman # and bomb if they have changed from the values we had from the 1720c8a0e2f4SThomas Veerman # command line or environment. 1721c8a0e2f4SThomas Veerman # 1722c8a0e2f4SThomas Veerman # This must be done after creating the top-level object directory. 1723c8a0e2f4SThomas Veerman # 1724c8a0e2f4SThomas Veerman for var in TOOLDIR DESTDIR RELEASEDIR 1725c8a0e2f4SThomas Veerman do 1726c8a0e2f4SThomas Veerman eval oldval=\"\$${var}\" 1727c8a0e2f4SThomas Veerman newval="$(getmakevar $var)" 1728c8a0e2f4SThomas Veerman if ! $do_expertmode; then 1729c8a0e2f4SThomas Veerman : ${_SRC_TOP_OBJ_:=$(getmakevar _SRC_TOP_OBJ_)} 1730c8a0e2f4SThomas Veerman case "$var" in 1731c8a0e2f4SThomas Veerman DESTDIR) 1732c8a0e2f4SThomas Veerman : ${newval:=${_SRC_TOP_OBJ_}/destdir.${MACHINE}} 1733c8a0e2f4SThomas Veerman makeenv="${makeenv} DESTDIR" 1734c8a0e2f4SThomas Veerman ;; 1735c8a0e2f4SThomas Veerman RELEASEDIR) 1736c8a0e2f4SThomas Veerman : ${newval:=${_SRC_TOP_OBJ_}/releasedir} 1737c8a0e2f4SThomas Veerman makeenv="${makeenv} RELEASEDIR" 1738c8a0e2f4SThomas Veerman ;; 1739c8a0e2f4SThomas Veerman esac 1740c8a0e2f4SThomas Veerman fi 1741c8a0e2f4SThomas Veerman if [ -n "$oldval" ] && [ "$oldval" != "$newval" ]; then 1742c8a0e2f4SThomas Veerman bomb "Value of ${var} has changed" \ 1743c8a0e2f4SThomas Veerman "(was \"${oldval}\", now \"${newval}\")" 1744c8a0e2f4SThomas Veerman fi 1745c8a0e2f4SThomas Veerman eval ${var}=\"\${newval}\" 1746c8a0e2f4SThomas Veerman eval export ${var} 1747c8a0e2f4SThomas Veerman statusmsg2 "${var} path:" "${newval}" 1748c8a0e2f4SThomas Veerman done 1749c8a0e2f4SThomas Veerman 1750c8a0e2f4SThomas Veerman # RELEASEMACHINEDIR is just a subdir name, e.g. "i386". 1751c8a0e2f4SThomas Veerman RELEASEMACHINEDIR=$(getmakevar RELEASEMACHINEDIR) 1752c8a0e2f4SThomas Veerman 1753c8a0e2f4SThomas Veerman # Check validity of TOOLDIR and DESTDIR. 1754c8a0e2f4SThomas Veerman # 1755c8a0e2f4SThomas Veerman if [ -z "${TOOLDIR}" ] || [ "${TOOLDIR}" = "/" ]; then 1756c8a0e2f4SThomas Veerman bomb "TOOLDIR '${TOOLDIR}' invalid" 1757c8a0e2f4SThomas Veerman fi 1758c8a0e2f4SThomas Veerman removedirs="${TOOLDIR}" 1759c8a0e2f4SThomas Veerman 1760c8a0e2f4SThomas Veerman if [ -z "${DESTDIR}" ] || [ "${DESTDIR}" = "/" ]; then 176184d9c625SLionel Sambuc if ${do_distribution} || ${do_release} || \ 176284d9c625SLionel Sambuc ( [ "${uname_s}" != "NetBSD" ] && [ "${uname_s}" != "Minix" ] ) || \ 1763c8a0e2f4SThomas Veerman [ "${uname_m}" != "${MACHINE}" ]; then 1764c8a0e2f4SThomas Veerman bomb "DESTDIR must != / for cross builds, or ${progname} 'distribution' or 'release'." 1765c8a0e2f4SThomas Veerman fi 1766c8a0e2f4SThomas Veerman if ! ${do_expertmode}; then 1767c8a0e2f4SThomas Veerman bomb "DESTDIR must != / for non -E (expert) builds" 1768c8a0e2f4SThomas Veerman fi 1769c8a0e2f4SThomas Veerman statusmsg "WARNING: Building to /, in expert mode." 1770c8a0e2f4SThomas Veerman statusmsg " This may cause your system to break! Reasons include:" 1771c8a0e2f4SThomas Veerman statusmsg " - your kernel is not up to date" 1772c8a0e2f4SThomas Veerman statusmsg " - the libraries or toolchain have changed" 1773c8a0e2f4SThomas Veerman statusmsg " YOU HAVE BEEN WARNED!" 1774c8a0e2f4SThomas Veerman else 1775c8a0e2f4SThomas Veerman removedirs="${removedirs} ${DESTDIR}" 1776c8a0e2f4SThomas Veerman fi 1777c8a0e2f4SThomas Veerman if ${do_releasekernel} && [ -z "${RELEASEDIR}" ]; then 1778c8a0e2f4SThomas Veerman bomb "Must set RELEASEDIR with \`releasekernel=...'" 1779c8a0e2f4SThomas Veerman fi 1780c8a0e2f4SThomas Veerman 1781c8a0e2f4SThomas Veerman # If a previous build.sh run used -U (and therefore created a 1782c8a0e2f4SThomas Veerman # METALOG file), then most subsequent build.sh runs must also 1783c8a0e2f4SThomas Veerman # use -U. If DESTDIR is about to be removed, then don't perform 1784c8a0e2f4SThomas Veerman # this check. 1785c8a0e2f4SThomas Veerman # 1786c8a0e2f4SThomas Veerman case "${do_removedirs} ${removedirs} " in 1787c8a0e2f4SThomas Veerman true*" ${DESTDIR} "*) 1788c8a0e2f4SThomas Veerman # DESTDIR is about to be removed 1789c8a0e2f4SThomas Veerman ;; 1790c8a0e2f4SThomas Veerman *) 179184d9c625SLionel Sambuc if [ -e "${DESTDIR}/METALOG" ] && \ 1792c8a0e2f4SThomas Veerman [ "${MKUNPRIVED}" = "no" ] ; then 1793c8a0e2f4SThomas Veerman if $do_expertmode; then 1794c8a0e2f4SThomas Veerman warning "A previous build.sh run specified -U." 1795c8a0e2f4SThomas Veerman else 1796c8a0e2f4SThomas Veerman bomb "A previous build.sh run specified -U; you must specify it again now." 1797c8a0e2f4SThomas Veerman fi 1798c8a0e2f4SThomas Veerman fi 1799c8a0e2f4SThomas Veerman ;; 1800c8a0e2f4SThomas Veerman esac 1801c8a0e2f4SThomas Veerman 1802c8a0e2f4SThomas Veerman # live-image and install-image targets require binary sets 1803c8a0e2f4SThomas Veerman # (actually DESTDIR/etc/mtree/set.* files) built with MKUNPRIVED. 1804c8a0e2f4SThomas Veerman # If release operation is specified with live-image or install-image, 1805c8a0e2f4SThomas Veerman # the release op should be performed with -U for later image ops. 1806c8a0e2f4SThomas Veerman # 1807c8a0e2f4SThomas Veerman if ${do_release} && ( ${do_live_image} || ${do_install_image} ) && \ 1808c8a0e2f4SThomas Veerman [ "${MKUNPRIVED}" = "no" ] ; then 1809c8a0e2f4SThomas Veerman bomb "-U must be specified on building release to create images later." 1810c8a0e2f4SThomas Veerman fi 1811c8a0e2f4SThomas Veerman} 1812c8a0e2f4SThomas Veerman 1813c8a0e2f4SThomas Veerman 1814c8a0e2f4SThomas Veermancreatemakewrapper() 1815c8a0e2f4SThomas Veerman{ 1816c8a0e2f4SThomas Veerman # Remove the target directories. 1817c8a0e2f4SThomas Veerman # 1818c8a0e2f4SThomas Veerman if ${do_removedirs}; then 1819c8a0e2f4SThomas Veerman for f in ${removedirs}; do 1820c8a0e2f4SThomas Veerman statusmsg "Removing ${f}" 1821c8a0e2f4SThomas Veerman ${runcmd} rm -r -f "${f}" 1822c8a0e2f4SThomas Veerman done 1823c8a0e2f4SThomas Veerman fi 1824c8a0e2f4SThomas Veerman 1825c8a0e2f4SThomas Veerman # Recreate $TOOLDIR. 1826c8a0e2f4SThomas Veerman # 1827c8a0e2f4SThomas Veerman ${runcmd} mkdir -p "${TOOLDIR}/bin" || 1828c8a0e2f4SThomas Veerman bomb "mkdir of '${TOOLDIR}/bin' failed" 1829c8a0e2f4SThomas Veerman 1830c8a0e2f4SThomas Veerman # If we did not previously rebuild ${toolprefix}make, then 1831c8a0e2f4SThomas Veerman # check whether $make is still valid and the same as the output 1832c8a0e2f4SThomas Veerman # from print_tooldir_make. If not, then rebuild make now. A 1833c8a0e2f4SThomas Veerman # possible reason for this being necessary is that the actual 1834c8a0e2f4SThomas Veerman # value of TOOLDIR might be different from the value guessed 1835c8a0e2f4SThomas Veerman # before the top level obj dir was created. 1836c8a0e2f4SThomas Veerman # 1837c8a0e2f4SThomas Veerman if ! ${done_rebuildmake} && \ 1838c8a0e2f4SThomas Veerman ( [ ! -x "$make" ] || [ "$make" != "$(print_tooldir_make)" ] ) 1839c8a0e2f4SThomas Veerman then 1840c8a0e2f4SThomas Veerman rebuildmake 1841c8a0e2f4SThomas Veerman fi 1842c8a0e2f4SThomas Veerman 1843c8a0e2f4SThomas Veerman # Install ${toolprefix}make if it was built. 1844c8a0e2f4SThomas Veerman # 1845c8a0e2f4SThomas Veerman if ${done_rebuildmake}; then 1846c8a0e2f4SThomas Veerman ${runcmd} rm -f "${TOOLDIR}/bin/${toolprefix}make" 1847c8a0e2f4SThomas Veerman ${runcmd} cp "${make}" "${TOOLDIR}/bin/${toolprefix}make" || 1848c8a0e2f4SThomas Veerman bomb "Failed to install \$TOOLDIR/bin/${toolprefix}make" 1849c8a0e2f4SThomas Veerman make="${TOOLDIR}/bin/${toolprefix}make" 1850c8a0e2f4SThomas Veerman statusmsg "Created ${make}" 1851c8a0e2f4SThomas Veerman fi 1852c8a0e2f4SThomas Veerman 1853c8a0e2f4SThomas Veerman # Build a ${toolprefix}make wrapper script, usable by hand as 1854c8a0e2f4SThomas Veerman # well as by build.sh. 1855c8a0e2f4SThomas Veerman # 1856c8a0e2f4SThomas Veerman if [ -z "${makewrapper}" ]; then 1857c8a0e2f4SThomas Veerman makewrapper="${TOOLDIR}/bin/${toolprefix}make-${makewrappermachine:-${MACHINE}}" 1858c8a0e2f4SThomas Veerman [ -z "${BUILDID}" ] || makewrapper="${makewrapper}-${BUILDID}" 1859c8a0e2f4SThomas Veerman fi 1860c8a0e2f4SThomas Veerman 1861c8a0e2f4SThomas Veerman ${runcmd} rm -f "${makewrapper}" 1862c8a0e2f4SThomas Veerman if [ "${runcmd}" = "echo" ]; then 1863c8a0e2f4SThomas Veerman echo 'cat <<EOF >'${makewrapper} 1864c8a0e2f4SThomas Veerman makewrapout= 1865c8a0e2f4SThomas Veerman else 1866c8a0e2f4SThomas Veerman makewrapout=">>\${makewrapper}" 1867c8a0e2f4SThomas Veerman fi 1868c8a0e2f4SThomas Veerman 1869c8a0e2f4SThomas Veerman case "${KSH_VERSION:-${SH_VERSION}}" in 1870c8a0e2f4SThomas Veerman *PD\ KSH*|*MIRBSD\ KSH*) 1871c8a0e2f4SThomas Veerman set +o braceexpand 1872c8a0e2f4SThomas Veerman ;; 1873c8a0e2f4SThomas Veerman esac 1874c8a0e2f4SThomas Veerman 1875c8a0e2f4SThomas Veerman eval cat <<EOF ${makewrapout} 1876c8a0e2f4SThomas Veerman#! ${HOST_SH} 1877c8a0e2f4SThomas Veerman# Set proper variables to allow easy "make" building of a NetBSD subtree. 1878*0a6a1f1dSLionel Sambuc# Generated from: \$NetBSD: build.sh,v 1.308 2015/06/27 06:00:28 matt Exp $ 1879c8a0e2f4SThomas Veerman# with these arguments: ${_args} 1880c8a0e2f4SThomas Veerman# 1881c8a0e2f4SThomas Veerman 1882c8a0e2f4SThomas VeermanEOF 1883c8a0e2f4SThomas Veerman { 1884*0a6a1f1dSLionel Sambuc sorted_vars="$(for var in ${makeenv}; do echo "${var}" ; done \ 1885*0a6a1f1dSLionel Sambuc | sort -u )" 1886*0a6a1f1dSLionel Sambuc for var in ${sorted_vars}; do 1887*0a6a1f1dSLionel Sambuc eval val=\"\${${var}}\" 1888*0a6a1f1dSLionel Sambuc eval is_set=\"\${${var}+set}\" 1889*0a6a1f1dSLionel Sambuc if [ -z "${is_set}" ]; then 1890*0a6a1f1dSLionel Sambuc echo "unset ${var}" 1891c8a0e2f4SThomas Veerman else 1892*0a6a1f1dSLionel Sambuc qval="$(shell_quote "${val}")" 1893*0a6a1f1dSLionel Sambuc echo "${var}=${qval}; export ${var}" 1894c8a0e2f4SThomas Veerman fi 1895c8a0e2f4SThomas Veerman done 1896c8a0e2f4SThomas Veerman 1897c8a0e2f4SThomas Veerman eval cat <<EOF 1898c8a0e2f4SThomas VeermanMAKEWRAPPERMACHINE=${makewrappermachine:-${MACHINE}}; export MAKEWRAPPERMACHINE 1899c8a0e2f4SThomas VeermanUSETOOLS=yes; export USETOOLS 1900d19d7d58SLionel Sambuc# LSC We are cross compiling, so do not install to root! 1901791aa4e1SThomas VeermanMKINSTALLBOOT=no; export MKINSTALLBOOT 1902c8a0e2f4SThomas VeermanEOF 1903c8a0e2f4SThomas Veerman } | eval sort -u "${makewrapout}" 1904c8a0e2f4SThomas Veerman eval cat <<EOF "${makewrapout}" 1905c8a0e2f4SThomas Veerman 1906c8a0e2f4SThomas Veermanexec "\${TOOLDIR}/bin/${toolprefix}make" \${1+"\$@"} 1907c8a0e2f4SThomas VeermanEOF 1908c8a0e2f4SThomas Veerman [ "${runcmd}" = "echo" ] && echo EOF 1909c8a0e2f4SThomas Veerman ${runcmd} chmod +x "${makewrapper}" 1910c8a0e2f4SThomas Veerman statusmsg2 "Updated makewrapper:" "${makewrapper}" 1911c8a0e2f4SThomas Veerman} 1912c8a0e2f4SThomas Veerman 1913c8a0e2f4SThomas Veermanmake_in_dir() 1914c8a0e2f4SThomas Veerman{ 1915c8a0e2f4SThomas Veerman dir="$1" 1916c8a0e2f4SThomas Veerman op="$2" 1917c8a0e2f4SThomas Veerman ${runcmd} cd "${dir}" || 1918c8a0e2f4SThomas Veerman bomb "Failed to cd to \"${dir}\"" 1919c8a0e2f4SThomas Veerman ${runcmd} "${makewrapper}" ${parallel} ${op} || 1920c8a0e2f4SThomas Veerman bomb "Failed to make ${op} in \"${dir}\"" 1921c8a0e2f4SThomas Veerman ${runcmd} cd "${TOP}" || 1922c8a0e2f4SThomas Veerman bomb "Failed to cd back to \"${TOP}\"" 1923c8a0e2f4SThomas Veerman} 1924c8a0e2f4SThomas Veerman 1925c8a0e2f4SThomas Veermanbuildtools() 1926c8a0e2f4SThomas Veerman{ 19279152e1c5SLionel Sambuc if [ "${MKOBJDIRS}" != "no" ]; then 19289152e1c5SLionel Sambuc ${runcmd} "${makewrapper}" ${parallel} obj-tools || 19299152e1c5SLionel Sambuc bomb "Failed to make obj-tools" 19309152e1c5SLionel Sambuc fi 1931c8a0e2f4SThomas Veerman if [ "${MKUPDATE}" = "no" ]; then 1932c8a0e2f4SThomas Veerman make_in_dir tools cleandir 1933c8a0e2f4SThomas Veerman fi 193484d9c625SLionel Sambuc make_in_dir tools build_install 1935c8a0e2f4SThomas Veerman statusmsg "Tools built to ${TOOLDIR}" 1936c8a0e2f4SThomas Veerman} 1937c8a0e2f4SThomas Veerman 1938c8a0e2f4SThomas Veermangetkernelconf() 1939c8a0e2f4SThomas Veerman{ 1940c8a0e2f4SThomas Veerman kernelconf="$1" 1941c8a0e2f4SThomas Veerman if [ "${MKOBJDIRS}" != "no" ]; then 1942c8a0e2f4SThomas Veerman # The correct value of KERNOBJDIR might 1943c8a0e2f4SThomas Veerman # depend on a prior "make obj" in 1944c8a0e2f4SThomas Veerman # ${KERNSRCDIR}/${KERNARCHDIR}/compile. 1945c8a0e2f4SThomas Veerman # 1946c8a0e2f4SThomas Veerman KERNSRCDIR="$(getmakevar KERNSRCDIR)" 1947c8a0e2f4SThomas Veerman KERNARCHDIR="$(getmakevar KERNARCHDIR)" 1948c8a0e2f4SThomas Veerman make_in_dir "${KERNSRCDIR}/${KERNARCHDIR}/compile" obj 1949c8a0e2f4SThomas Veerman fi 1950c8a0e2f4SThomas Veerman KERNCONFDIR="$(getmakevar KERNCONFDIR)" 1951c8a0e2f4SThomas Veerman KERNOBJDIR="$(getmakevar KERNOBJDIR)" 1952c8a0e2f4SThomas Veerman case "${kernelconf}" in 1953c8a0e2f4SThomas Veerman */*) 1954c8a0e2f4SThomas Veerman kernelconfpath="${kernelconf}" 1955c8a0e2f4SThomas Veerman kernelconfname="${kernelconf##*/}" 1956c8a0e2f4SThomas Veerman ;; 1957c8a0e2f4SThomas Veerman *) 1958c8a0e2f4SThomas Veerman kernelconfpath="${KERNCONFDIR}/${kernelconf}" 1959c8a0e2f4SThomas Veerman kernelconfname="${kernelconf}" 1960c8a0e2f4SThomas Veerman ;; 1961c8a0e2f4SThomas Veerman esac 1962c8a0e2f4SThomas Veerman kernelbuildpath="${KERNOBJDIR}/${kernelconfname}" 1963c8a0e2f4SThomas Veerman} 1964c8a0e2f4SThomas Veerman 196584d9c625SLionel Sambucdiskimage() 196684d9c625SLionel Sambuc{ 196784d9c625SLionel Sambuc ARG="$(echo $1 | tr '[:lower:]' '[:upper:]')" 196884d9c625SLionel Sambuc [ -f "${DESTDIR}/etc/mtree/set.base" ] || 196984d9c625SLionel Sambuc bomb "The release binaries must be built first" 197084d9c625SLionel Sambuc kerneldir="${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/kernel" 197184d9c625SLionel Sambuc kernel="${kerneldir}/netbsd-${ARG}.gz" 197284d9c625SLionel Sambuc [ -f "${kernel}" ] || 197384d9c625SLionel Sambuc bomb "The kernel ${kernel} must be built first" 197484d9c625SLionel Sambuc make_in_dir "${NETBSDSRCDIR}/etc" "smp_${1}" 197584d9c625SLionel Sambuc} 197684d9c625SLionel Sambuc 1977c8a0e2f4SThomas Veermanbuildkernel() 1978c8a0e2f4SThomas Veerman{ 1979c8a0e2f4SThomas Veerman if ! ${do_tools} && ! ${buildkernelwarned:-false}; then 1980c8a0e2f4SThomas Veerman # Building tools every time we build a kernel is clearly 1981c8a0e2f4SThomas Veerman # unnecessary. We could try to figure out whether rebuilding 1982c8a0e2f4SThomas Veerman # the tools is necessary this time, but it doesn't seem worth 1983c8a0e2f4SThomas Veerman # the trouble. Instead, we say it's the user's responsibility 1984c8a0e2f4SThomas Veerman # to rebuild the tools if necessary. 1985c8a0e2f4SThomas Veerman # 1986c8a0e2f4SThomas Veerman statusmsg "Building kernel without building new tools" 1987c8a0e2f4SThomas Veerman buildkernelwarned=true 1988c8a0e2f4SThomas Veerman fi 1989c8a0e2f4SThomas Veerman getkernelconf $1 1990c8a0e2f4SThomas Veerman statusmsg2 "Building kernel:" "${kernelconf}" 1991c8a0e2f4SThomas Veerman statusmsg2 "Build directory:" "${kernelbuildpath}" 1992c8a0e2f4SThomas Veerman ${runcmd} mkdir -p "${kernelbuildpath}" || 1993c8a0e2f4SThomas Veerman bomb "Cannot mkdir: ${kernelbuildpath}" 1994c8a0e2f4SThomas Veerman if [ "${MKUPDATE}" = "no" ]; then 1995c8a0e2f4SThomas Veerman make_in_dir "${kernelbuildpath}" cleandir 1996c8a0e2f4SThomas Veerman fi 1997c8a0e2f4SThomas Veerman [ -x "${TOOLDIR}/bin/${toolprefix}config" ] \ 1998c8a0e2f4SThomas Veerman || bomb "${TOOLDIR}/bin/${toolprefix}config does not exist. You need to \"$0 tools\" first." 1999*0a6a1f1dSLionel Sambuc CONFIGOPTS=$(getmakevar CONFIGOPTS) 2000*0a6a1f1dSLionel Sambuc ${runcmd} "${TOOLDIR}/bin/${toolprefix}config" ${CONFIGOPTS} \ 2001*0a6a1f1dSLionel Sambuc -b "${kernelbuildpath}" -s "${TOP}/sys" ${configopts} \ 2002*0a6a1f1dSLionel Sambuc "${kernelconfpath}" || 2003c8a0e2f4SThomas Veerman bomb "${toolprefix}config failed for ${kernelconf}" 2004c8a0e2f4SThomas Veerman make_in_dir "${kernelbuildpath}" depend 2005c8a0e2f4SThomas Veerman make_in_dir "${kernelbuildpath}" all 2006c8a0e2f4SThomas Veerman 2007c8a0e2f4SThomas Veerman if [ "${runcmd}" != "echo" ]; then 2008c8a0e2f4SThomas Veerman statusmsg "Kernels built from ${kernelconf}:" 2009c8a0e2f4SThomas Veerman kernlist=$(awk '$1 == "config" { print $2 }' ${kernelconfpath}) 2010c8a0e2f4SThomas Veerman for kern in ${kernlist:-netbsd}; do 2011c8a0e2f4SThomas Veerman [ -f "${kernelbuildpath}/${kern}" ] && \ 2012c8a0e2f4SThomas Veerman echo " ${kernelbuildpath}/${kern}" 2013c8a0e2f4SThomas Veerman done | tee -a "${results}" 2014c8a0e2f4SThomas Veerman fi 2015c8a0e2f4SThomas Veerman} 2016c8a0e2f4SThomas Veerman 2017c8a0e2f4SThomas Veermanreleasekernel() 2018c8a0e2f4SThomas Veerman{ 2019c8a0e2f4SThomas Veerman getkernelconf $1 2020c8a0e2f4SThomas Veerman kernelreldir="${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/kernel" 2021c8a0e2f4SThomas Veerman ${runcmd} mkdir -p "${kernelreldir}" 2022c8a0e2f4SThomas Veerman kernlist=$(awk '$1 == "config" { print $2 }' ${kernelconfpath}) 2023c8a0e2f4SThomas Veerman for kern in ${kernlist:-netbsd}; do 2024c8a0e2f4SThomas Veerman builtkern="${kernelbuildpath}/${kern}" 2025c8a0e2f4SThomas Veerman [ -f "${builtkern}" ] || continue 2026c8a0e2f4SThomas Veerman releasekern="${kernelreldir}/${kern}-${kernelconfname}.gz" 2027c8a0e2f4SThomas Veerman statusmsg2 "Kernel copy:" "${releasekern}" 2028c8a0e2f4SThomas Veerman if [ "${runcmd}" = "echo" ]; then 2029c8a0e2f4SThomas Veerman echo "gzip -c -9 < ${builtkern} > ${releasekern}" 2030c8a0e2f4SThomas Veerman else 2031c8a0e2f4SThomas Veerman gzip -c -9 < "${builtkern}" > "${releasekern}" 2032c8a0e2f4SThomas Veerman fi 2033c8a0e2f4SThomas Veerman done 2034c8a0e2f4SThomas Veerman} 2035c8a0e2f4SThomas Veerman 2036*0a6a1f1dSLionel Sambucbuildkernels() 2037*0a6a1f1dSLionel Sambuc{ 2038*0a6a1f1dSLionel Sambuc allkernels=$( runcmd= make_in_dir etc '-V ${ALL_KERNELS}' ) 2039*0a6a1f1dSLionel Sambuc for k in $allkernels; do 2040*0a6a1f1dSLionel Sambuc buildkernel "${k}" 2041*0a6a1f1dSLionel Sambuc done 2042*0a6a1f1dSLionel Sambuc} 2043*0a6a1f1dSLionel Sambuc 2044c8a0e2f4SThomas Veermanbuildmodules() 2045c8a0e2f4SThomas Veerman{ 2046c8a0e2f4SThomas Veerman setmakeenv MKBINUTILS no 2047c8a0e2f4SThomas Veerman if ! ${do_tools} && ! ${buildmoduleswarned:-false}; then 2048c8a0e2f4SThomas Veerman # Building tools every time we build modules is clearly 2049c8a0e2f4SThomas Veerman # unnecessary as well as a kernel. 2050c8a0e2f4SThomas Veerman # 2051c8a0e2f4SThomas Veerman statusmsg "Building modules without building new tools" 2052c8a0e2f4SThomas Veerman buildmoduleswarned=true 2053c8a0e2f4SThomas Veerman fi 2054c8a0e2f4SThomas Veerman 2055c8a0e2f4SThomas Veerman statusmsg "Building kernel modules for NetBSD/${MACHINE} ${DISTRIBVER}" 2056c8a0e2f4SThomas Veerman if [ "${MKOBJDIRS}" != "no" ]; then 2057d19d7d58SLionel Sambuc make_in_dir sys/modules obj 2058c8a0e2f4SThomas Veerman fi 2059c8a0e2f4SThomas Veerman if [ "${MKUPDATE}" = "no" ]; then 2060c8a0e2f4SThomas Veerman make_in_dir sys/modules cleandir 2061c8a0e2f4SThomas Veerman fi 2062d19d7d58SLionel Sambuc make_in_dir sys/modules dependall 2063d19d7d58SLionel Sambuc make_in_dir sys/modules install 2064c8a0e2f4SThomas Veerman 2065c8a0e2f4SThomas Veerman statusmsg "Successful build of kernel modules for NetBSD/${MACHINE} ${DISTRIBVER}" 2066c8a0e2f4SThomas Veerman} 2067c8a0e2f4SThomas Veerman 2068c8a0e2f4SThomas Veermaninstallmodules() 2069c8a0e2f4SThomas Veerman{ 2070c8a0e2f4SThomas Veerman dir="$1" 2071c8a0e2f4SThomas Veerman ${runcmd} "${makewrapper}" INSTALLMODULESDIR="${dir}" installmodules || 2072c8a0e2f4SThomas Veerman bomb "Failed to make installmodules to ${dir}" 2073c8a0e2f4SThomas Veerman statusmsg "Successful installmodules to ${dir}" 2074c8a0e2f4SThomas Veerman} 2075c8a0e2f4SThomas Veerman 2076c8a0e2f4SThomas Veermaninstallworld() 2077c8a0e2f4SThomas Veerman{ 2078c8a0e2f4SThomas Veerman dir="$1" 2079c8a0e2f4SThomas Veerman ${runcmd} "${makewrapper}" INSTALLWORLDDIR="${dir}" installworld || 2080c8a0e2f4SThomas Veerman bomb "Failed to make installworld to ${dir}" 2081c8a0e2f4SThomas Veerman statusmsg "Successful installworld to ${dir}" 2082c8a0e2f4SThomas Veerman} 2083c8a0e2f4SThomas Veerman 2084c8a0e2f4SThomas Veerman# Run rump build&link tests. 2085c8a0e2f4SThomas Veerman# 2086c8a0e2f4SThomas Veerman# To make this feasible for running without having to install includes and 2087c8a0e2f4SThomas Veerman# libraries into destdir (i.e. quick), we only run ld. This is possible 2088c8a0e2f4SThomas Veerman# since the rump kernel is a closed namespace apart from calls to rumpuser. 2089c8a0e2f4SThomas Veerman# Therefore, if ld complains only about rumpuser symbols, rump kernel 2090c8a0e2f4SThomas Veerman# linking was successful. 2091c8a0e2f4SThomas Veerman# 2092c8a0e2f4SThomas Veerman# We test that rump links with a number of component configurations. 2093c8a0e2f4SThomas Veerman# These attempt to mimic what is encountered in the full build. 2094c8a0e2f4SThomas Veerman# See list below. The list should probably be either autogenerated 2095c8a0e2f4SThomas Veerman# or managed elsewhere; keep it here until a better idea arises. 2096c8a0e2f4SThomas Veerman# 2097c8a0e2f4SThomas Veerman# Above all, note that THIS IS NOT A SUBSTITUTE FOR A FULL BUILD. 2098c8a0e2f4SThomas Veerman# 2099c8a0e2f4SThomas Veerman 2100c8a0e2f4SThomas VeermanRUMP_LIBSETS=' 2101c8a0e2f4SThomas Veerman -lrump, 2102c8a0e2f4SThomas Veerman -lrumpvfs -lrump, 2103c8a0e2f4SThomas Veerman -lrumpvfs -lrumpdev -lrump, 2104c8a0e2f4SThomas Veerman -lrumpnet -lrump, 2105c8a0e2f4SThomas Veerman -lrumpkern_tty -lrumpvfs -lrump, 2106c8a0e2f4SThomas Veerman -lrumpfs_tmpfs -lrumpvfs -lrump, 2107c8a0e2f4SThomas Veerman -lrumpfs_ffs -lrumpfs_msdos -lrumpvfs -lrumpdev_disk -lrumpdev -lrump, 2108c8a0e2f4SThomas Veerman -lrumpnet_virtif -lrumpnet_netinet -lrumpnet_net -lrumpnet -lrump, 2109c8a0e2f4SThomas Veerman -lrumpnet_sockin -lrumpfs_smbfs -lrumpdev_netsmb 2110c8a0e2f4SThomas Veerman -lrumpkern_crypto -lrumpdev -lrumpnet -lrumpvfs -lrump, 2111c8a0e2f4SThomas Veerman -lrumpnet_sockin -lrumpfs_nfs -lrumpnet -lrumpvfs -lrump, 2112c8a0e2f4SThomas Veerman -lrumpdev_cgd -lrumpdev_raidframe -lrumpdev_disk -lrumpdev_rnd 2113c8a0e2f4SThomas Veerman -lrumpdev_dm -lrumpdev -lrumpvfs -lrumpkern_crypto -lrump' 2114c8a0e2f4SThomas Veermandorump() 2115c8a0e2f4SThomas Veerman{ 2116c8a0e2f4SThomas Veerman local doclean="" 2117c8a0e2f4SThomas Veerman local doobjs="" 2118c8a0e2f4SThomas Veerman 2119c8a0e2f4SThomas Veerman # we cannot link libs without building csu, and that leads to lossage 2120c8a0e2f4SThomas Veerman [ "${1}" != "rumptest" ] && bomb 'build.sh rump not yet functional. ' \ 2121c8a0e2f4SThomas Veerman 'did you mean "rumptest"?' 2122c8a0e2f4SThomas Veerman 212384d9c625SLionel Sambuc export RUMPKERN_ONLY=1 2124c8a0e2f4SThomas Veerman # create obj and distrib dirs 2125c8a0e2f4SThomas Veerman if [ "${MKOBJDIRS}" != "no" ]; then 2126c8a0e2f4SThomas Veerman make_in_dir "${NETBSDSRCDIR}/etc/mtree" obj 2127c8a0e2f4SThomas Veerman make_in_dir "${NETBSDSRCDIR}/sys/rump" obj 2128c8a0e2f4SThomas Veerman fi 2129c8a0e2f4SThomas Veerman ${runcmd} "${makewrapper}" ${parallel} do-distrib-dirs \ 2130c8a0e2f4SThomas Veerman || bomb 'could not create distrib-dirs' 2131c8a0e2f4SThomas Veerman 2132c8a0e2f4SThomas Veerman [ "${MKUPDATE}" = "no" ] && doclean="cleandir" 2133c8a0e2f4SThomas Veerman targlist="${doclean} ${doobjs} dependall install" 2134c8a0e2f4SThomas Veerman # optimize: for test we build only static libs (3x test speedup) 2135c8a0e2f4SThomas Veerman if [ "${1}" = "rumptest" ] ; then 2136c8a0e2f4SThomas Veerman setmakeenv NOPIC 1 2137c8a0e2f4SThomas Veerman setmakeenv NOPROFILE 1 2138c8a0e2f4SThomas Veerman fi 2139c8a0e2f4SThomas Veerman for cmd in ${targlist} ; do 2140c8a0e2f4SThomas Veerman make_in_dir "${NETBSDSRCDIR}/sys/rump" ${cmd} 2141c8a0e2f4SThomas Veerman done 2142c8a0e2f4SThomas Veerman 2143c8a0e2f4SThomas Veerman # if we just wanted to build & install rump, we're done 2144c8a0e2f4SThomas Veerman [ "${1}" != "rumptest" ] && return 2145c8a0e2f4SThomas Veerman 2146c8a0e2f4SThomas Veerman ${runcmd} cd "${NETBSDSRCDIR}/sys/rump/librump/rumpkern" \ 2147c8a0e2f4SThomas Veerman || bomb "cd to rumpkern failed" 2148c8a0e2f4SThomas Veerman md_quirks=`${runcmd} "${makewrapper}" -V '${_SYMQUIRK}'` 2149c8a0e2f4SThomas Veerman # one little, two little, three little backslashes ... 2150c8a0e2f4SThomas Veerman md_quirks="$(echo ${md_quirks} | sed 's,\\,\\\\,g'";s/'//g" )" 2151c8a0e2f4SThomas Veerman ${runcmd} cd "${TOP}" || bomb "cd to ${TOP} failed" 2152c8a0e2f4SThomas Veerman tool_ld=`${runcmd} "${makewrapper}" -V '${LD}'` 2153c8a0e2f4SThomas Veerman 2154c8a0e2f4SThomas Veerman local oIFS="${IFS}" 2155c8a0e2f4SThomas Veerman IFS="," 2156c8a0e2f4SThomas Veerman for set in ${RUMP_LIBSETS} ; do 2157c8a0e2f4SThomas Veerman IFS="${oIFS}" 2158c8a0e2f4SThomas Veerman ${runcmd} ${tool_ld} -nostdlib -L${DESTDIR}/usr/lib \ 2159c8a0e2f4SThomas Veerman -static --whole-archive ${set} 2>&1 -o /tmp/rumptest.$$ | \ 2160c8a0e2f4SThomas Veerman awk -v quirks="${md_quirks}" ' 2161c8a0e2f4SThomas Veerman /undefined reference/ && 2162c8a0e2f4SThomas Veerman !/more undefined references.*follow/{ 2163c8a0e2f4SThomas Veerman if (match($NF, 216484d9c625SLionel Sambuc "`(rumpuser_|rumpcomp_|__" quirks ")") == 0) 2165c8a0e2f4SThomas Veerman fails[NR] = $0 2166c8a0e2f4SThomas Veerman } 2167c8a0e2f4SThomas Veerman /cannot find -l/{fails[NR] = $0} 2168c8a0e2f4SThomas Veerman /cannot open output file/{fails[NR] = $0} 2169c8a0e2f4SThomas Veerman END{ 2170c8a0e2f4SThomas Veerman for (x in fails) 2171c8a0e2f4SThomas Veerman print fails[x] 2172c8a0e2f4SThomas Veerman exit x!=0 2173c8a0e2f4SThomas Veerman }' 2174c8a0e2f4SThomas Veerman [ $? -ne 0 ] && bomb "Testlink of rump failed: ${set}" 2175c8a0e2f4SThomas Veerman done 2176c8a0e2f4SThomas Veerman statusmsg "Rump build&link tests successful" 2177c8a0e2f4SThomas Veerman} 2178c8a0e2f4SThomas Veerman 2179c8a0e2f4SThomas Veermanmain() 2180c8a0e2f4SThomas Veerman{ 2181c8a0e2f4SThomas Veerman initdefaults 2182c8a0e2f4SThomas Veerman _args=$@ 2183c8a0e2f4SThomas Veerman parseoptions "$@" 2184c8a0e2f4SThomas Veerman 2185c8a0e2f4SThomas Veerman sanitycheck 2186c8a0e2f4SThomas Veerman 2187c8a0e2f4SThomas Veerman build_start=$(date) 2188c8a0e2f4SThomas Veerman statusmsg2 "${progname} command:" "$0 $*" 2189c8a0e2f4SThomas Veerman statusmsg2 "${progname} started:" "${build_start}" 2190c8a0e2f4SThomas Veerman statusmsg2 "MINIX version:" "${DISTRIBVER}" 2191c8a0e2f4SThomas Veerman statusmsg2 "MACHINE:" "${MACHINE}" 2192c8a0e2f4SThomas Veerman statusmsg2 "MACHINE_ARCH:" "${MACHINE_ARCH}" 2193c8a0e2f4SThomas Veerman statusmsg2 "Build platform:" "${uname_s} ${uname_r} ${uname_m}" 2194c8a0e2f4SThomas Veerman statusmsg2 "HOST_SH:" "${HOST_SH}" 2195*0a6a1f1dSLionel Sambuc if [ -n "${BUILDID}" ]; then 2196*0a6a1f1dSLionel Sambuc statusmsg2 "BUILDID:" "${BUILDID}" 2197*0a6a1f1dSLionel Sambuc fi 2198*0a6a1f1dSLionel Sambuc if [ -n "${BUILDINFO}" ]; then 2199*0a6a1f1dSLionel Sambuc printf "%b\n" "${BUILDINFO}" | \ 2200*0a6a1f1dSLionel Sambuc while read -r line ; do 2201*0a6a1f1dSLionel Sambuc [ -s "${line}" ] && continue 2202*0a6a1f1dSLionel Sambuc statusmsg2 "BUILDINFO:" "${line}" 2203*0a6a1f1dSLionel Sambuc done 2204*0a6a1f1dSLionel Sambuc fi 2205c8a0e2f4SThomas Veerman 2206c8a0e2f4SThomas Veerman rebuildmake 2207c8a0e2f4SThomas Veerman validatemakeparams 2208c8a0e2f4SThomas Veerman createmakewrapper 2209c8a0e2f4SThomas Veerman 2210c8a0e2f4SThomas Veerman # Perform the operations. 2211c8a0e2f4SThomas Veerman # 2212c8a0e2f4SThomas Veerman for op in ${operations}; do 2213c8a0e2f4SThomas Veerman case "${op}" in 2214c8a0e2f4SThomas Veerman 2215c8a0e2f4SThomas Veerman makewrapper) 2216c8a0e2f4SThomas Veerman # no-op 2217c8a0e2f4SThomas Veerman ;; 2218c8a0e2f4SThomas Veerman 2219c8a0e2f4SThomas Veerman tools) 2220c8a0e2f4SThomas Veerman buildtools 2221c8a0e2f4SThomas Veerman ;; 2222c8a0e2f4SThomas Veerman 2223c8a0e2f4SThomas Veerman sets) 2224c8a0e2f4SThomas Veerman statusmsg "Building sets from pre-populated ${DESTDIR}" 2225c8a0e2f4SThomas Veerman ${runcmd} "${makewrapper}" ${parallel} ${op} || 2226c8a0e2f4SThomas Veerman bomb "Failed to make ${op}" 2227c8a0e2f4SThomas Veerman setdir=${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets 2228c8a0e2f4SThomas Veerman statusmsg "Built sets to ${setdir}" 2229c8a0e2f4SThomas Veerman ;; 2230c8a0e2f4SThomas Veerman 223184d9c625SLionel Sambuc cleandir|obj|build|distribution|release|sourcesets|syspkgs|show-params) 2232c8a0e2f4SThomas Veerman ${runcmd} "${makewrapper}" ${parallel} ${op} || 2233c8a0e2f4SThomas Veerman bomb "Failed to make ${op}" 2234c8a0e2f4SThomas Veerman statusmsg "Successful make ${op}" 2235c8a0e2f4SThomas Veerman ;; 2236c8a0e2f4SThomas Veerman 2237c8a0e2f4SThomas Veerman iso-image|iso-image-source) 2238c8a0e2f4SThomas Veerman ${runcmd} "${makewrapper}" ${parallel} \ 2239c8a0e2f4SThomas Veerman CDEXTRA="$CDEXTRA" ${op} || 2240c8a0e2f4SThomas Veerman bomb "Failed to make ${op}" 2241c8a0e2f4SThomas Veerman statusmsg "Successful make ${op}" 2242c8a0e2f4SThomas Veerman ;; 2243c8a0e2f4SThomas Veerman 2244c8a0e2f4SThomas Veerman live-image|install-image) 2245c8a0e2f4SThomas Veerman # install-image and live-image require mtree spec files 2246c8a0e2f4SThomas Veerman # built with UNPRIVED. Assume UNPRIVED build has been 2247c8a0e2f4SThomas Veerman # performed if METALOG file is created in DESTDIR. 2248c8a0e2f4SThomas Veerman if [ ! -e "${DESTDIR}/METALOG" ] ; then 2249c8a0e2f4SThomas Veerman bomb "The release binaries must have been built with -U to create images." 2250c8a0e2f4SThomas Veerman fi 2251c8a0e2f4SThomas Veerman ${runcmd} "${makewrapper}" ${parallel} ${op} || 2252c8a0e2f4SThomas Veerman bomb "Failed to make ${op}" 2253c8a0e2f4SThomas Veerman statusmsg "Successful make ${op}" 2254c8a0e2f4SThomas Veerman ;; 2255c8a0e2f4SThomas Veerman kernel=*) 2256c8a0e2f4SThomas Veerman arg=${op#*=} 2257c8a0e2f4SThomas Veerman buildkernel "${arg}" 2258c8a0e2f4SThomas Veerman ;; 2259*0a6a1f1dSLionel Sambuc kernel.gdb=*) 2260*0a6a1f1dSLionel Sambuc arg=${op#*=} 2261*0a6a1f1dSLionel Sambuc configopts="-D DEBUG=-g" 2262*0a6a1f1dSLionel Sambuc buildkernel "${arg}" 2263*0a6a1f1dSLionel Sambuc ;; 2264c8a0e2f4SThomas Veerman releasekernel=*) 2265c8a0e2f4SThomas Veerman arg=${op#*=} 2266c8a0e2f4SThomas Veerman releasekernel "${arg}" 2267c8a0e2f4SThomas Veerman ;; 2268c8a0e2f4SThomas Veerman 2269*0a6a1f1dSLionel Sambuc kernels) 2270*0a6a1f1dSLionel Sambuc buildkernels 2271*0a6a1f1dSLionel Sambuc ;; 2272*0a6a1f1dSLionel Sambuc 227384d9c625SLionel Sambuc disk-image=*) 227484d9c625SLionel Sambuc arg=${op#*=} 227584d9c625SLionel Sambuc diskimage "${arg}" 227684d9c625SLionel Sambuc ;; 227784d9c625SLionel Sambuc 2278c8a0e2f4SThomas Veerman modules) 2279c8a0e2f4SThomas Veerman buildmodules 2280c8a0e2f4SThomas Veerman ;; 2281c8a0e2f4SThomas Veerman 2282c8a0e2f4SThomas Veerman installmodules=*) 2283c8a0e2f4SThomas Veerman arg=${op#*=} 2284c8a0e2f4SThomas Veerman if [ "${arg}" = "/" ] && \ 228584d9c625SLionel Sambuc ( ( [ "${uname_s}" != "NetBSD" ] && [ "${uname_s}" != "Minix" ] ) || \ 2286c8a0e2f4SThomas Veerman [ "${uname_m}" != "${MACHINE}" ] ); then 2287c8a0e2f4SThomas Veerman bomb "'${op}' must != / for cross builds." 2288c8a0e2f4SThomas Veerman fi 2289c8a0e2f4SThomas Veerman installmodules "${arg}" 2290c8a0e2f4SThomas Veerman ;; 2291c8a0e2f4SThomas Veerman 2292c8a0e2f4SThomas Veerman install=*) 2293c8a0e2f4SThomas Veerman arg=${op#*=} 2294c8a0e2f4SThomas Veerman if [ "${arg}" = "/" ] && \ 229584d9c625SLionel Sambuc ( ( [ "${uname_s}" != "NetBSD" ] && [ "${uname_s}" != "Minix" ] ) || \ 2296c8a0e2f4SThomas Veerman [ "${uname_m}" != "${MACHINE}" ] ); then 2297c8a0e2f4SThomas Veerman bomb "'${op}' must != / for cross builds." 2298c8a0e2f4SThomas Veerman fi 2299c8a0e2f4SThomas Veerman installworld "${arg}" 2300c8a0e2f4SThomas Veerman ;; 2301c8a0e2f4SThomas Veerman 2302c8a0e2f4SThomas Veerman rump|rumptest) 2303c8a0e2f4SThomas Veerman dorump "${op}" 2304c8a0e2f4SThomas Veerman ;; 2305c8a0e2f4SThomas Veerman 2306c8a0e2f4SThomas Veerman *) 2307c8a0e2f4SThomas Veerman bomb "Unknown operation \`${op}'" 2308c8a0e2f4SThomas Veerman ;; 2309c8a0e2f4SThomas Veerman 2310c8a0e2f4SThomas Veerman esac 2311c8a0e2f4SThomas Veerman done 2312c8a0e2f4SThomas Veerman 2313c8a0e2f4SThomas Veerman statusmsg2 "${progname} ended:" "$(date)" 2314c8a0e2f4SThomas Veerman if [ -s "${results}" ]; then 2315c8a0e2f4SThomas Veerman echo "===> Summary of results:" 2316c8a0e2f4SThomas Veerman sed -e 's/^===>//;s/^/ /' "${results}" 2317c8a0e2f4SThomas Veerman echo "===> ." 2318c8a0e2f4SThomas Veerman fi 2319c8a0e2f4SThomas Veerman} 2320c8a0e2f4SThomas Veerman 2321c8a0e2f4SThomas Veermanmain "$@" 2322