diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..f75c272 --- /dev/null +++ b/build.sh @@ -0,0 +1,2321 @@ +#! /usr/bin/env sh +# $NetBSD: build.sh,v 1.308 2015/06/27 06:00:28 matt Exp $ +# +# Copyright (c) 2001-2011 The NetBSD Foundation, Inc. +# All rights reserved. +# +# This code is derived from software contributed to The NetBSD Foundation +# by Todd Vierling and Luke Mewburn. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# +# Top level build wrapper, to build or cross-build NetBSD. +# + +# +# {{{ Begin shell feature tests. +# +# We try to determine whether or not this script is being run under +# a shell that supports the features that we use. If not, we try to +# re-exec the script under another shell. If we can't find another +# suitable shell, then we print a message and exit. +# + +errmsg='' # error message, if not empty +shelltest=false # if true, exit after testing the shell +re_exec_allowed=true # if true, we may exec under another shell + +# Parse special command line options in $1. These special options are +# for internal use only, are not documented, and are not valid anywhere +# other than $1. +case "$1" in +"--shelltest") + shelltest=true + re_exec_allowed=false + shift + ;; +"--no-re-exec") + re_exec_allowed=false + shift + ;; +esac + +# Solaris /bin/sh, and other SVR4 shells, do not support "!". +# This is the first feature that we test, because subsequent +# tests use "!". +# +if test -z "$errmsg"; then + if ( eval '! false' ) >/dev/null 2>&1 ; then + : + else + errmsg='Shell does not support "!".' + fi +fi + +# Does the shell support functions? +# +if test -z "$errmsg"; then + if ! ( + eval 'somefunction() { : ; }' + ) >/dev/null 2>&1 + then + errmsg='Shell does not support functions.' + fi +fi + +# Does the shell support the "local" keyword for variables in functions? +# +# Local variables are not required by SUSv3, but some scripts run during +# the NetBSD build use them. +# +# ksh93 fails this test; it uses an incompatible syntax involving the +# keywords 'function' and 'typeset'. +# +if test -z "$errmsg"; then + if ! ( + eval 'f() { local v=2; }; v=1; f && test x"$v" = x"1"' + ) >/dev/null 2>&1 + then + errmsg='Shell does not support the "local" keyword in functions.' + fi +fi + +# Does the shell support ${var%suffix}, ${var#prefix}, and their variants? +# +# We don't bother testing for ${var+value}, ${var-value}, or their variants, +# since shells without those are sure to fail other tests too. +# +if test -z "$errmsg"; then + if ! ( + eval 'var=a/b/c ; + test x"${var#*/};${var##*/};${var%/*};${var%%/*}" = \ + x"b/c;c;a/b;a" ;' + ) >/dev/null 2>&1 + then + errmsg='Shell does not support "${var%suffix}" or "${var#prefix}".' + fi +fi + +# Does the shell support IFS? +# +# zsh in normal mode (as opposed to "emulate sh" mode) fails this test. +# +if test -z "$errmsg"; then + if ! ( + eval 'IFS=: ; v=":a b::c" ; set -- $v ; IFS=+ ; + test x"$#;$1,$2,$3,$4;$*" = x"4;,a b,,c;+a b++c"' + ) >/dev/null 2>&1 + then + errmsg='Shell does not support IFS word splitting.' + fi +fi + +# Does the shell support ${1+"$@"}? +# +# Some versions of zsh fail this test, even in "emulate sh" mode. +# +if test -z "$errmsg"; then + if ! ( + eval 'set -- "a a a" "b b b"; set -- ${1+"$@"}; + test x"$#;$1;$2" = x"2;a a a;b b b";' + ) >/dev/null 2>&1 + then + errmsg='Shell does not support ${1+"$@"}.' + fi +fi + +# Does the shell support $(...) command substitution? +# +if test -z "$errmsg"; then + if ! ( + eval 'var=$(echo abc); test x"$var" = x"abc"' + ) >/dev/null 2>&1 + then + errmsg='Shell does not support "$(...)" command substitution.' + fi +fi + +# Does the shell support $(...) command substitution with +# unbalanced parentheses? +# +# Some shells known to fail this test are: NetBSD /bin/ksh (as of 2009-12), +# bash-3.1, pdksh-5.2.14, zsh-4.2.7 in "emulate sh" mode. +# +if test -z "$errmsg"; then + if ! ( + eval 'var=$(case x in x) echo abc;; esac); test x"$var" = x"abc"' + ) >/dev/null 2>&1 + then + # XXX: This test is ignored because so many shells fail it; instead, + # the NetBSD build avoids using the problematic construct. + : ignore 'Shell does not support "$(...)" with unbalanced ")".' + fi +fi + +# Does the shell support getopts or getopt? +# +if test -z "$errmsg"; then + if ! ( + eval 'type getopts || type getopt' + ) >/dev/null 2>&1 + then + errmsg='Shell does not support getopts or getopt.' + fi +fi + +# +# If shelltest is true, exit now, reporting whether or not the shell is good. +# +if $shelltest; then + if test -n "$errmsg"; then + echo >&2 "$0: $errmsg" + exit 1 + else + exit 0 + fi +fi + +# +# If the shell was bad, try to exec a better shell, or report an error. +# +# Loops are broken by passing an extra "--no-re-exec" flag to the new +# instance of this script. +# +if test -n "$errmsg"; then + if $re_exec_allowed; then + for othershell in \ + "${HOST_SH}" /usr/xpg4/bin/sh ksh ksh88 mksh pdksh dash bash + # NOTE: some shells known not to work are: + # any shell using csh syntax; + # Solaris /bin/sh (missing many modern features); + # ksh93 (incompatible syntax for local variables); + # zsh (many differences, unless run in compatibility mode). + do + test -n "$othershell" || continue + if eval 'type "$othershell"' >/dev/null 2>&1 \ + && "$othershell" "$0" --shelltest >/dev/null 2>&1 + then + cat <&2 < $@" | tee -a "${results}" +} + +statusmsg2() +{ + local msg + + msg="${1}" + shift + case "${msg}" in + ????????????????*) ;; + ??????????*) msg="${msg} ";; + ?????*) msg="${msg} ";; + *) msg="${msg} ";; + esac + case "${msg}" in + ?????????????????????*) ;; + ????????????????????) msg="${msg} ";; + ???????????????????) msg="${msg} ";; + ??????????????????) msg="${msg} ";; + ?????????????????) msg="${msg} ";; + ????????????????) msg="${msg} ";; + esac + statusmsg "${msg}$*" +} + +warning() +{ + statusmsg "Warning: $@" +} + +# Find a program in the PATH, and print the result. If not found, +# print a default. If $2 is defined (even if it is an empty string), +# then that is the default; otherwise, $1 is used as the default. +find_in_PATH() +{ + local prog="$1" + local result="${2-"$1"}" + local oldIFS="${IFS}" + local dir + IFS=":" + for dir in ${PATH}; do + if [ -x "${dir}/${prog}" ]; then + result="${dir}/${prog}" + break + fi + done + IFS="${oldIFS}" + echo "${result}" +} + +# Try to find a working POSIX shell, and set HOST_SH to refer to it. +# Assumes that uname_s, uname_m, and PWD have been set. +set_HOST_SH() +{ + # Even if ${HOST_SH} is already defined, we still do the + # sanity checks at the end. + + # Solaris has /usr/xpg4/bin/sh. + # + [ -z "${HOST_SH}" ] && [ x"${uname_s}" = x"SunOS" ] && \ + [ -x /usr/xpg4/bin/sh ] && HOST_SH="/usr/xpg4/bin/sh" + + # Try to get the name of the shell that's running this script, + # by parsing the output from "ps". We assume that, if the host + # system's ps command supports -o comm at all, it will do so + # in the usual way: a one-line header followed by a one-line + # result, possibly including trailing white space. And if the + # host system's ps command doesn't support -o comm, we assume + # that we'll get an error message on stderr and nothing on + # stdout. (We don't try to use ps -o 'comm=' to suppress the + # header line, because that is less widely supported.) + # + # If we get the wrong result here, the user can override it by + # specifying HOST_SH in the environment. + # + [ -z "${HOST_SH}" ] && HOST_SH="$( + (ps -p $$ -o comm | sed -ne "2s/[ ${tab}]*\$//p") 2>/dev/null )" + + # If nothing above worked, use "sh". We will later find the + # first directory in the PATH that has a "sh" program. + # + [ -z "${HOST_SH}" ] && HOST_SH="sh" + + # If the result so far is not an absolute path, try to prepend + # PWD or search the PATH. + # + case "${HOST_SH}" in + /*) : + ;; + */*) HOST_SH="${PWD}/${HOST_SH}" + ;; + *) HOST_SH="$(find_in_PATH "${HOST_SH}")" + ;; + esac + + # If we don't have an absolute path by now, bomb. + # + case "${HOST_SH}" in + /*) : + ;; + *) bomb "HOST_SH=\"${HOST_SH}\" is not an absolute path." + ;; + esac + + # If HOST_SH is not executable, bomb. + # + [ -x "${HOST_SH}" ] || + bomb "HOST_SH=\"${HOST_SH}\" is not executable." + + # If HOST_SH fails tests, bomb. + # ("$0" may be a path that is no longer valid, because we have + # performed "cd $(dirname $0)", so don't use $0 here.) + # + "${HOST_SH}" build.sh --shelltest || + bomb "HOST_SH=\"${HOST_SH}\" failed functionality tests." +} + +# initdefaults -- +# Set defaults before parsing command line options. +# +initdefaults() +{ + makeenv= + makewrapper= + makewrappermachine= + runcmd= + operations= + removedirs= + + [ -d usr.bin/make ] || cd "$(dirname $0)" + [ -d usr.bin/make ] || + bomb "build.sh must be run from the top source level" + [ -f share/mk/bsd.own.mk ] || + bomb "src/share/mk is missing; please re-fetch the source tree" + + # Set various environment variables to known defaults, + # to minimize (cross-)build problems observed "in the field". + # + # LC_ALL=C must be set before we try to parse the output from + # any command. Other variables are set (or unset) here, before + # we parse command line arguments. + # + # These variables can be overridden via "-V var=value" if + # you know what you are doing. + # + unsetmakeenv INFODIR + unsetmakeenv LESSCHARSET + unsetmakeenv MAKEFLAGS + unsetmakeenv TERMINFO + setmakeenv LC_ALL C + + # Find information about the build platform. This should be + # kept in sync with _HOST_OSNAME, _HOST_OSREL, and _HOST_ARCH + # variables in share/mk/bsd.sys.mk. + # + # Note that "uname -p" is not part of POSIX, but we want uname_p + # to be set to the host MACHINE_ARCH, if possible. On systems + # where "uname -p" fails, prints "unknown", or prints a string + # that does not look like an identifier, fall back to using the + # output from "uname -m" instead. + # + uname_s=$(uname -s 2>/dev/null) + uname_r=$(uname -r 2>/dev/null) + uname_m=$(uname -m 2>/dev/null) + uname_p=$(uname -p 2>/dev/null || echo "unknown") + case "${uname_p}" in + ''|unknown|*[^-_A-Za-z0-9]*) uname_p="${uname_m}" ;; + esac + + id_u=$(id -u 2>/dev/null || /usr/xpg4/bin/id -u 2>/dev/null) + + # If $PWD is a valid name of the current directory, POSIX mandates + # that pwd return it by default which causes problems in the + # presence of symlinks. Unsetting PWD is simpler than changing + # every occurrence of pwd to use -P. + # + # XXX Except that doesn't work on Solaris. Or many Linuces. + # + unset PWD + TOP=$(/bin/pwd -P 2>/dev/null || /bin/pwd 2>/dev/null) + + # The user can set HOST_SH in the environment, or we try to + # guess an appropriate value. Then we set several other + # variables from HOST_SH. + # + set_HOST_SH + setmakeenv HOST_SH "${HOST_SH}" + setmakeenv BSHELL "${HOST_SH}" + setmakeenv CONFIG_SHELL "${HOST_SH}" + + # Set defaults. + # + toolprefix=nb + + # Some systems have a small ARG_MAX. -X prevents make(1) from + # exporting variables in the environment redundantly. + # + case "${uname_s}" in + Darwin | FreeBSD | CYGWIN*) + MAKEFLAGS="-X ${MAKEFLAGS}" + ;; + esac + + # do_{operation}=true if given operation is requested. + # + do_expertmode=false + do_rebuildmake=false + do_removedirs=false + do_tools=false + do_cleandir=false + do_obj=false + do_build=false + do_distribution=false + do_release=false + do_kernel=false + do_releasekernel=false + do_kernels=false + do_modules=false + do_installmodules=false + do_install=false + do_sets=false + do_sourcesets=false + do_syspkgs=false + do_iso_image=false + do_iso_image_source=false + do_live_image=false + do_install_image=false + do_disk_image=false + do_show_params=false + do_rump=false + + # done_{operation}=true if given operation has been done. + # + done_rebuildmake=false + + # Create scratch directory + # + tmpdir="${TMPDIR-/tmp}/nbbuild$$" + mkdir "${tmpdir}" || bomb "Cannot mkdir: ${tmpdir}" + trap "cd /; rm -r -f \"${tmpdir}\"" 0 + results="${tmpdir}/build.sh.results" + + # Set source directories + # + setmakeenv NETBSDSRCDIR "${TOP}" + + # Make sure KERNOBJDIR is an absolute path if defined + # + case "${KERNOBJDIR}" in + ''|/*) ;; + *) KERNOBJDIR="${TOP}/${KERNOBJDIR}" + setmakeenv KERNOBJDIR "${KERNOBJDIR}" + ;; + esac + + # Find the version of NetBSD + # + DISTRIBVER="$(${HOST_SH} ${TOP}/sys/conf/osrelease.sh)" + + # Set the BUILDSEED to NetBSD-"N" + # + setmakeenv BUILDSEED "MINIX-$(${HOST_SH} ${TOP}/sys/conf/osrelease.sh -m)" + + # Set MKARZERO to "yes" + # + setmakeenv MKARZERO "yes" + +} + +# valid_MACHINE_ARCH -- A multi-line string, listing all valid +# MACHINE/MACHINE_ARCH pairs. +# +# Each line contains a MACHINE and MACHINE_ARCH value, an optional ALIAS +# which may be used to refer to the MACHINE/MACHINE_ARCH pair, and an +# optional DEFAULT or NO_DEFAULT keyword. +# +# When a MACHINE corresponds to multiple possible values of +# MACHINE_ARCH, then this table should list all allowed combinations. +# If the MACHINE is associated with a default MACHINE_ARCH (to be +# used when the user specifies the MACHINE but fails to specify the +# MACHINE_ARCH), then one of the lines should have the "DEFAULT" +# keyword. If there is no default MACHINE_ARCH for a particular +# MACHINE, then there should be a line with the "NO_DEFAULT" keyword, +# and with a blank MACHINE_ARCH. +# +valid_MACHINE_ARCH=' +MACHINE=acorn26 MACHINE_ARCH=arm +MACHINE=acorn32 MACHINE_ARCH=arm +MACHINE=algor MACHINE_ARCH=mips64el ALIAS=algor64 +MACHINE=algor MACHINE_ARCH=mipsel DEFAULT +MACHINE=alpha MACHINE_ARCH=alpha +MACHINE=amd64 MACHINE_ARCH=x86_64 +MACHINE=amiga MACHINE_ARCH=m68k +MACHINE=amigappc MACHINE_ARCH=powerpc +MACHINE=arc MACHINE_ARCH=mips64el ALIAS=arc64 +MACHINE=arc MACHINE_ARCH=mipsel DEFAULT +MACHINE=atari MACHINE_ARCH=m68k +MACHINE=bebox MACHINE_ARCH=powerpc +MACHINE=cats MACHINE_ARCH=arm ALIAS=ocats +MACHINE=cats MACHINE_ARCH=earmv4 ALIAS=ecats DEFAULT +MACHINE=cesfic MACHINE_ARCH=m68k +MACHINE=cobalt MACHINE_ARCH=mips64el ALIAS=cobalt64 +MACHINE=cobalt MACHINE_ARCH=mipsel DEFAULT +MACHINE=dreamcast MACHINE_ARCH=sh3el +MACHINE=emips MACHINE_ARCH=mipseb +MACHINE=epoc32 MACHINE_ARCH=arm +MACHINE=evbarm MACHINE_ARCH=arm ALIAS=evboarm-el +MACHINE=evbarm MACHINE_ARCH=armeb ALIAS=evboarm-eb +MACHINE=evbarm MACHINE_ARCH=earm ALIAS=evbearm-el DEFAULT +MACHINE=evbarm MACHINE_ARCH=earmeb ALIAS=evbearm-eb +MACHINE=evbarm MACHINE_ARCH=earmhf ALIAS=evbearmhf-el +MACHINE=evbarm MACHINE_ARCH=earmhfeb ALIAS=evbearmhf-eb +MACHINE=evbarm MACHINE_ARCH=earmv4 ALIAS=evbearmv4-el +MACHINE=evbarm MACHINE_ARCH=earmv4eb ALIAS=evbearmv4-eb +MACHINE=evbarm MACHINE_ARCH=earmv5 ALIAS=evbearmv5-el +MACHINE=evbarm MACHINE_ARCH=earmv5eb ALIAS=evbearmv5-eb +MACHINE=evbarm MACHINE_ARCH=earmv6 ALIAS=evbearmv6-el +MACHINE=evbarm MACHINE_ARCH=earmv6hf ALIAS=evbearmv6hf-el +MACHINE=evbarm MACHINE_ARCH=earmv6eb ALIAS=evbearmv6-eb +MACHINE=evbarm MACHINE_ARCH=earmv6hfeb ALIAS=evbearmv6hf-eb +MACHINE=evbarm MACHINE_ARCH=earmv7 ALIAS=evbearmv7-el +MACHINE=evbarm MACHINE_ARCH=earmv7eb ALIAS=evbearmv7-eb +MACHINE=evbarm MACHINE_ARCH=earmv7hf ALIAS=evbearmv7hf-el +MACHINE=evbarm MACHINE_ARCH=earmv7hfeb ALIAS=evbearmv7hf-eb +MACHINE=evbarm64 MACHINE_ARCH=aarch64 ALIAS=evbarm64-el DEFAULT +MACHINE=evbarm64 MACHINE_ARCH=aarch64eb ALIAS=evbarm64-eb +MACHINE=evbcf MACHINE_ARCH=coldfire +MACHINE=evbmips MACHINE_ARCH= NO_DEFAULT +MACHINE=evbmips MACHINE_ARCH=mips64eb ALIAS=evbmips64-eb +MACHINE=evbmips MACHINE_ARCH=mips64el ALIAS=evbmips64-el +MACHINE=evbmips MACHINE_ARCH=mipseb ALIAS=evbmips-eb +MACHINE=evbmips MACHINE_ARCH=mipsel ALIAS=evbmips-el +MACHINE=evbppc MACHINE_ARCH=powerpc DEFAULT +MACHINE=evbppc MACHINE_ARCH=powerpc64 ALIAS=evbppc64 +MACHINE=evbsh3 MACHINE_ARCH= NO_DEFAULT +MACHINE=evbsh3 MACHINE_ARCH=sh3eb ALIAS=evbsh3-eb +MACHINE=evbsh3 MACHINE_ARCH=sh3el ALIAS=evbsh3-el +MACHINE=ews4800mips MACHINE_ARCH=mipseb +MACHINE=hp300 MACHINE_ARCH=m68k +MACHINE=hppa MACHINE_ARCH=hppa +MACHINE=hpcarm MACHINE_ARCH=arm ALIAS=hpcoarm +MACHINE=hpcarm MACHINE_ARCH=earmv4 ALIAS=hpcearm DEFAULT +MACHINE=hpcmips MACHINE_ARCH=mipsel +MACHINE=hpcsh MACHINE_ARCH=sh3el +MACHINE=i386 MACHINE_ARCH=i386 +MACHINE=ia64 MACHINE_ARCH=ia64 +MACHINE=ibmnws MACHINE_ARCH=powerpc +MACHINE=iyonix MACHINE_ARCH=arm ALIAS=oiyonix +MACHINE=iyonix MACHINE_ARCH=earm ALIAS=eiyonix DEFAULT +MACHINE=landisk MACHINE_ARCH=sh3el +MACHINE=luna68k MACHINE_ARCH=m68k +MACHINE=mac68k MACHINE_ARCH=m68k +MACHINE=macppc MACHINE_ARCH=powerpc DEFAULT +MACHINE=macppc MACHINE_ARCH=powerpc64 ALIAS=macppc64 +MACHINE=mipsco MACHINE_ARCH=mipseb +MACHINE=mmeye MACHINE_ARCH=sh3eb +MACHINE=mvme68k MACHINE_ARCH=m68k +MACHINE=mvmeppc MACHINE_ARCH=powerpc +MACHINE=netwinder MACHINE_ARCH=arm ALIAS=onetwinder +MACHINE=netwinder MACHINE_ARCH=earmv4 ALIAS=enetwinder DEFAULT +MACHINE=news68k MACHINE_ARCH=m68k +MACHINE=newsmips MACHINE_ARCH=mipseb +MACHINE=next68k MACHINE_ARCH=m68k +MACHINE=ofppc MACHINE_ARCH=powerpc DEFAULT +MACHINE=ofppc MACHINE_ARCH=powerpc64 ALIAS=ofppc64 +MACHINE=or1k MACHINE_ARCH=or1k +MACHINE=playstation2 MACHINE_ARCH=mipsel +MACHINE=pmax MACHINE_ARCH=mips64el ALIAS=pmax64 +MACHINE=pmax MACHINE_ARCH=mipsel DEFAULT +MACHINE=prep MACHINE_ARCH=powerpc +MACHINE=riscv MACHINE_ARCH=riscv64 ALIAS=riscv64 DEFAULT +MACHINE=riscv MACHINE_ARCH=riscv32 ALIAS=riscv32 +MACHINE=rs6000 MACHINE_ARCH=powerpc +MACHINE=sandpoint MACHINE_ARCH=powerpc +MACHINE=sbmips MACHINE_ARCH= NO_DEFAULT +MACHINE=sbmips MACHINE_ARCH=mips64eb ALIAS=sbmips64-eb +MACHINE=sbmips MACHINE_ARCH=mips64el ALIAS=sbmips64-el +MACHINE=sbmips MACHINE_ARCH=mipseb ALIAS=sbmips-eb +MACHINE=sbmips MACHINE_ARCH=mipsel ALIAS=sbmips-el +MACHINE=sgimips MACHINE_ARCH=mips64eb ALIAS=sgimips64 +MACHINE=sgimips MACHINE_ARCH=mipseb DEFAULT +MACHINE=shark MACHINE_ARCH=arm ALIAS=oshark +MACHINE=shark MACHINE_ARCH=earmv4 ALIAS=eshark DEFAULT +MACHINE=sparc MACHINE_ARCH=sparc +MACHINE=sparc64 MACHINE_ARCH=sparc64 +MACHINE=sun2 MACHINE_ARCH=m68000 +MACHINE=sun3 MACHINE_ARCH=m68k +MACHINE=vax MACHINE_ARCH=vax +MACHINE=x68k MACHINE_ARCH=m68k +MACHINE=zaurus MACHINE_ARCH=arm ALIAS=ozaurus +MACHINE=zaurus MACHINE_ARCH=earm ALIAS=ezaurus DEFAULT +' + +# getarch -- find the default MACHINE_ARCH for a MACHINE, +# or convert an alias to a MACHINE/MACHINE_ARCH pair. +# +# Saves the original value of MACHINE in makewrappermachine before +# alias processing. +# +# Sets MACHINE and MACHINE_ARCH if the input MACHINE value is +# recognised as an alias, or recognised as a machine that has a default +# MACHINE_ARCH (or that has only one possible MACHINE_ARCH). +# +# Leaves MACHINE and MACHINE_ARCH unchanged if MACHINE is recognised +# as being associated with multiple MACHINE_ARCH values with no default. +# +# Bombs if MACHINE is not recognised. +# +getarch() +{ + local IFS + local found="" + local line + + IFS="${nl}" + makewrappermachine="${MACHINE}" + for line in ${valid_MACHINE_ARCH}; do + line="${line%%#*}" # ignore comments + line="$( IFS=" ${tab}" ; echo $line )" # normalise white space + case "${line} " in + " ") + # skip blank lines or comment lines + continue + ;; + *" ALIAS=${MACHINE} "*) + # Found a line with a matching ALIAS=. + found="$line" + break + ;; + "MACHINE=${MACHINE} "*" NO_DEFAULT"*) + # Found an explicit "NO_DEFAULT" for this MACHINE. + found="$line" + break + ;; + "MACHINE=${MACHINE} "*" DEFAULT"*) + # Found an explicit "DEFAULT" for this MACHINE. + found="$line" + break + ;; + "MACHINE=${MACHINE} "*) + # Found a line for this MACHINE. If it's the + # first such line, then tentatively accept it. + # If it's not the first matching line, then + # remember that there was more than one match. + case "$found" in + '') found="$line" ;; + *) found="MULTIPLE_MATCHES" ;; + esac + ;; + esac + done + + case "$found" in + *NO_DEFAULT*|*MULTIPLE_MATCHES*) + # MACHINE is OK, but MACHINE_ARCH is still unknown + return + ;; + "MACHINE="*" MACHINE_ARCH="*) + # Obey the MACHINE= and MACHINE_ARCH= parts of the line. + IFS=" " + for frag in ${found}; do + case "$frag" in + MACHINE=*|MACHINE_ARCH=*) + eval "$frag" + ;; + esac + done + ;; + *) + bomb "Unknown target MACHINE: ${MACHINE}" + ;; + esac +} + +# validatearch -- check that the MACHINE/MACHINE_ARCH pair is supported. +# +# Bombs if the pair is not supported. +# +validatearch() +{ + local IFS + local line + local foundpair=false foundmachine=false foundarch=false + + case "${MACHINE_ARCH}" in + "") + bomb "No MACHINE_ARCH provided" + ;; + esac + + IFS="${nl}" + for line in ${valid_MACHINE_ARCH}; do + line="${line%%#*}" # ignore comments + line="$( IFS=" ${tab}" ; echo $line )" # normalise white space + case "${line} " in + " ") + # skip blank lines or comment lines + continue + ;; + "MACHINE=${MACHINE} MACHINE_ARCH=${MACHINE_ARCH} "*) + foundpair=true + ;; + "MACHINE=${MACHINE} "*) + foundmachine=true + ;; + *"MACHINE_ARCH=${MACHINE_ARCH} "*) + foundarch=true + ;; + esac + done + + case "${foundpair}:${foundmachine}:${foundarch}" in + true:*) + : OK + ;; + *:false:*) + bomb "Unknown target MACHINE: ${MACHINE}" + ;; + *:*:false) + bomb "Unknown target MACHINE_ARCH: ${MACHINE_ARCH}" + ;; + *) + bomb "MACHINE_ARCH '${MACHINE_ARCH}' does not support MACHINE '${MACHINE}'" + ;; + esac +} + +# listarch -- list valid MACHINE/MACHINE_ARCH/ALIAS values, +# optionally restricted to those where the MACHINE and/or MACHINE_ARCH +# match specifed glob patterns. +# +listarch() +{ + local machglob="$1" archglob="$2" + local IFS + local wildcard="*" + local line xline frag + local line_matches_machine line_matches_arch + local found=false + + # Empty machglob or archglob should match anything + : "${machglob:=${wildcard}}" + : "${archglob:=${wildcard}}" + + IFS="${nl}" + for line in ${valid_MACHINE_ARCH}; do + line="${line%%#*}" # ignore comments + xline="$( IFS=" ${tab}" ; echo $line )" # normalise white space + [ -z "${xline}" ] && continue # skip blank or comment lines + + line_matches_machine=false + line_matches_arch=false + + IFS=" " + for frag in ${xline}; do + case "${frag}" in + MACHINE=${machglob}) + line_matches_machine=true ;; + ALIAS=${machglob}) + line_matches_machine=true ;; + MACHINE_ARCH=${archglob}) + line_matches_arch=true ;; + esac + done + + if $line_matches_machine && $line_matches_arch; then + found=true + echo "$line" + fi + done + if ! $found; then + echo >&2 "No match for" \ + "MACHINE=${machglob} MACHINE_ARCH=${archglob}" + return 1 + fi + return 0 +} + +# nobomb_getmakevar -- +# Given the name of a make variable in $1, print make's idea of the +# value of that variable, or return 1 if there's an error. +# +nobomb_getmakevar() +{ + [ -x "${make}" ] || return 1 + "${make}" -m ${TOP}/share/mk -s -B -f- _x_ < +.include +EOF +} + +# bomb_getmakevar -- +# Given the name of a make variable in $1, print make's idea of the +# value of that variable, or bomb if there's an error. +# +bomb_getmakevar() +{ + [ -x "${make}" ] || bomb "bomb_getmakevar $1: ${make} is not executable" + nobomb_getmakevar "$1" || bomb "bomb_getmakevar $1: ${make} failed" +} + +# getmakevar -- +# Given the name of a make variable in $1, print make's idea of the +# value of that variable, or print a literal '$' followed by the +# variable name if ${make} is not executable. This is intended for use in +# messages that need to be readable even if $make hasn't been built, +# such as when build.sh is run with the "-n" option. +# +getmakevar() +{ + if [ -x "${make}" ]; then + bomb_getmakevar "$1" + else + echo "\$$1" + fi +} + +setmakeenv() +{ + eval "$1='$2'; export $1" + makeenv="${makeenv} $1" +} + +unsetmakeenv() +{ + eval "unset $1" + makeenv="${makeenv} $1" +} + +# Given a variable name in $1, modify the variable in place as follows: +# For each space-separated word in the variable, call resolvepath. +resolvepaths() +{ + local var="$1" + local val + eval val=\"\${${var}}\" + local newval='' + local word + for word in ${val}; do + resolvepath word + newval="${newval}${newval:+ }${word}" + done + eval ${var}=\"\${newval}\" +} + +# Given a variable name in $1, modify the variable in place as follows: +# Convert possibly-relative path to absolute path by prepending +# ${TOP} if necessary. Also delete trailing "/", if any. +resolvepath() +{ + local var="$1" + local val + eval val=\"\${${var}}\" + case "${val}" in + /) + ;; + /*) + val="${val%/}" + ;; + *) + val="${TOP}/${val%/}" + ;; + esac + eval ${var}=\"\${val}\" +} + +usage() +{ + if [ -n "$*" ]; then + echo "" + echo "${progname}: $*" + fi + cat <<_usage_ + +Usage: ${progname} [-EhnorUuxy] [-a arch] [-B buildid] [-C cdextras] + [-D dest] [-j njob] [-M obj] [-m mach] [-N noisy] + [-O obj] [-R release] [-S seed] [-T tools] + [-V var=[value]] [-w wrapper] [-X x11src] [-Y extsrcsrc] + [-Z var] + operation [...] + + Build operations (all imply "obj" and "tools"): + build Run "make build". + distribution Run "make distribution" (includes DESTDIR/etc/ files). + release Run "make release" (includes kernels & distrib media). + + Other operations: + help Show this message and exit. + makewrapper Create ${toolprefix}make-\${MACHINE} wrapper and ${toolprefix}make. + Always performed. + cleandir Run "make cleandir". [Default unless -u is used] + obj Run "make obj". [Default unless -o is used] + tools Build and install tools. + install=idir Run "make installworld" to \`idir' to install all sets + except \`etc'. Useful after "distribution" or "release" + kernel=conf Build kernel with config file \`conf' + kernel.gdb=conf Build kernel (including netbsd.gdb) with config + file \`conf' + releasekernel=conf Install kernel built by kernel=conf to RELEASEDIR. + kernels Build all kernels + installmodules=idir Run "make installmodules" to \`idir' to install all + kernel modules. + modules Build kernel modules. + rumptest Do a linktest for rump (for developers). + sets Create binary sets in + RELEASEDIR/RELEASEMACHINEDIR/binary/sets. + DESTDIR should be populated beforehand. + sourcesets Create source sets in RELEASEDIR/source/sets. + syspkgs Create syspkgs in + RELEASEDIR/RELEASEMACHINEDIR/binary/syspkgs. + iso-image Create CD-ROM image in RELEASEDIR/images. + iso-image-source Create CD-ROM image with source in RELEASEDIR/images. + live-image Create bootable live image in + RELEASEDIR/RELEASEMACHINEDIR/installation/liveimage. + install-image Create bootable installation image in + RELEASEDIR/RELEASEMACHINEDIR/installation/installimage. + disk-image=target Create bootable disk image in + RELEASEDIR/RELEASEMACHINEDIR/binary/gzimg/target.img.gz. + params Display various make(1) parameters. + list-arch Display a list of valid MACHINE/MACHINE_ARCH values, + and exit. The list may be narrowed by passing glob + patterns or exact values in MACHINE or MACHINE_ARCH. + + Options: + -a arch Set MACHINE_ARCH to arch. [Default: deduced from MACHINE] + -B buildid Set BUILDID to buildid. + -C cdextras Append cdextras to CDEXTRA variable for inclusion on CD-ROM. + -D dest Set DESTDIR to dest. [Default: destdir.MACHINE] + -E Set "expert" mode; disables various safety checks. + Should not be used without expert knowledge of the build system. + -h Print this help message. + -j njob Run up to njob jobs in parallel; see make(1) -j. + -M obj Set obj root directory to obj; sets MAKEOBJDIRPREFIX. + Unsets MAKEOBJDIR. + -m mach Set MACHINE to mach. Some mach values are actually + aliases that set MACHINE/MACHINE_ARCH pairs. + [Default: deduced from the host system if the host + OS is NetBSD] + -N noisy Set the noisyness (MAKEVERBOSE) level of the build: + 0 Minimal output ("quiet") + 1 Describe what is occurring + 2 Describe what is occurring and echo the actual command + 3 Ignore the effect of the "@" prefix in make commands + 4 Trace shell commands using the shell's -x flag + [Default: 2] + -n Show commands that would be executed, but do not execute them. + -O obj Set obj root directory to obj; sets a MAKEOBJDIR pattern. + Unsets MAKEOBJDIRPREFIX. + -o Set MKOBJDIRS=no; do not create objdirs at start of build. + -R release Set RELEASEDIR to release. [Default: releasedir] + -r Remove contents of TOOLDIR and DESTDIR before building. + -S seed Set BUILDSEED to seed. [Default: NetBSD-majorversion] + -T tools Set TOOLDIR to tools. If unset, and TOOLDIR is not set in + the environment, ${toolprefix}make will be (re)built + unconditionally. + -U Set MKUNPRIVED=yes; build without requiring root privileges, + install from an UNPRIVED build with proper file permissions. + -u Set MKUPDATE=yes; do not run "make cleandir" first. + Without this, everything is rebuilt, including the tools. + -V var=[value] Set variable \`var' to \`value'. + -w wrapper Create ${toolprefix}make script as wrapper. + [Default: \${TOOLDIR}/bin/${toolprefix}make-\${MACHINE}] + -X x11src Set X11SRCDIR to x11src. [Default: /usr/xsrc] + -x Set MKX11=yes; build X11 from X11SRCDIR + -Y extsrcsrc Set EXTSRCSRCDIR to extsrcsrc. [Default: /usr/extsrc] + -y Set MKEXTSRC=yes; build extsrc from EXTSRCSRCDIR + -Z var Unset ("zap") variable \`var'. + +_usage_ + exit 1 +} + +parseoptions() +{ + opts='a:B:C:D:Ehj:M:m:N:nO:oR:rS:T:UuV:w:X:xY:yZ:' + opt_a=false + opt_m=false + + if type getopts >/dev/null 2>&1; then + # Use POSIX getopts. + # + getoptcmd='getopts ${opts} opt && opt=-${opt}' + optargcmd=':' + optremcmd='shift $((${OPTIND} -1))' + else + type getopt >/dev/null 2>&1 || + bomb "Shell does not support getopts or getopt" + + # Use old-style getopt(1) (doesn't handle whitespace in args). + # + args="$(getopt ${opts} $*)" + [ $? = 0 ] || usage + set -- ${args} + + getoptcmd='[ $# -gt 0 ] && opt="$1" && shift' + optargcmd='OPTARG="$1"; shift' + optremcmd=':' + fi + + # Parse command line options. + # + while eval ${getoptcmd}; do + case ${opt} in + + -a) + eval ${optargcmd} + MACHINE_ARCH=${OPTARG} + opt_a=true + ;; + + -B) + eval ${optargcmd} + BUILDID=${OPTARG} + ;; + + -C) + eval ${optargcmd}; resolvepaths OPTARG + CDEXTRA="${CDEXTRA}${CDEXTRA:+ }${OPTARG}" + ;; + + -D) + eval ${optargcmd}; resolvepath OPTARG + setmakeenv DESTDIR "${OPTARG}" + ;; + + -E) + do_expertmode=true + ;; + + -j) + eval ${optargcmd} + parallel="-j ${OPTARG}" + ;; + + -M) + eval ${optargcmd}; resolvepath OPTARG + case "${OPTARG}" in + \$*) usage "-M argument must not begin with '\$'" + ;; + *\$*) # can use resolvepath, but can't set TOP_objdir + resolvepath OPTARG + ;; + *) resolvepath OPTARG + TOP_objdir="${OPTARG}${TOP}" + ;; + esac + unsetmakeenv MAKEOBJDIR + setmakeenv MAKEOBJDIRPREFIX "${OPTARG}" + ;; + + # -m overrides MACHINE_ARCH unless "-a" is specified + -m) + eval ${optargcmd} + MACHINE="${OPTARG}" + opt_m=true + ;; + + -N) + eval ${optargcmd} + case "${OPTARG}" in + 0|1|2|3|4) + setmakeenv MAKEVERBOSE "${OPTARG}" + ;; + *) + usage "'${OPTARG}' is not a valid value for -N" + ;; + esac + ;; + + -n) + runcmd=echo + ;; + + -O) + eval ${optargcmd} + case "${OPTARG}" in + *\$*) usage "-O argument must not contain '\$'" + ;; + *) resolvepath OPTARG + TOP_objdir="${OPTARG}" + ;; + esac + unsetmakeenv MAKEOBJDIRPREFIX + setmakeenv MAKEOBJDIR "\${.CURDIR:C,^$TOP,$OPTARG,}" + ;; + + -o) + MKOBJDIRS=no + ;; + + -R) + eval ${optargcmd}; resolvepath OPTARG + setmakeenv RELEASEDIR "${OPTARG}" + ;; + + -r) + do_removedirs=true + do_rebuildmake=true + ;; + + -S) + eval ${optargcmd} + setmakeenv BUILDSEED "${OPTARG}" + ;; + + -T) + eval ${optargcmd}; resolvepath OPTARG + TOOLDIR="${OPTARG}" + export TOOLDIR + ;; + + -U) + setmakeenv MKUNPRIVED yes + ;; + + -u) + setmakeenv MKUPDATE yes + ;; + + -V) + eval ${optargcmd} + case "${OPTARG}" in + # XXX: consider restricting which variables can be changed? + [a-zA-Z_][a-zA-Z_0-9]*=*) + setmakeenv "${OPTARG%%=*}" "${OPTARG#*=}" + ;; + *) + usage "-V argument must be of the form 'var=[value]'" + ;; + esac + ;; + + -w) + eval ${optargcmd}; resolvepath OPTARG + makewrapper="${OPTARG}" + ;; + + -X) + eval ${optargcmd}; resolvepath OPTARG + setmakeenv X11SRCDIR "${OPTARG}" + ;; + + -x) + setmakeenv MKX11 yes + ;; + + -Y) + eval ${optargcmd}; resolvepath OPTARG + setmakeenv EXTSRCSRCDIR "${OPTARG}" + ;; + + -y) + setmakeenv MKEXTSRC yes + ;; + + -Z) + eval ${optargcmd} + # XXX: consider restricting which variables can be unset? + unsetmakeenv "${OPTARG}" + ;; + + --) + break + ;; + + -'?'|-h) + usage + ;; + + esac + done + + # Validate operations. + # + eval ${optremcmd} + while [ $# -gt 0 ]; do + op=$1; shift + operations="${operations} ${op}" + + case "${op}" in + + help) + usage + ;; + + list-arch) + listarch "${MACHINE}" "${MACHINE_ARCH}" + exit $? + ;; + + show-params) + op=show_params # used as part of a variable name + ;; + + kernel=*|releasekernel=*|kernel.gdb=*) + arg=${op#*=} + op=${op%%=*} + [ -n "${arg}" ] || + bomb "Must supply a kernel name with \`${op}=...'" + ;; + + disk-image=*) + arg=${op#*=} + op=disk_image + [ -n "${arg}" ] || + bomb "Must supply a target name with \`${op}=...'" + + ;; + + install=*|installmodules=*) + arg=${op#*=} + op=${op%%=*} + [ -n "${arg}" ] || + bomb "Must supply a directory with \`install=...'" + ;; + + build|\ + cleandir|\ + distribution|\ + install-image|\ + iso-image-source|\ + iso-image|\ + kernels|\ + live-image|\ + makewrapper|\ + modules|\ + obj|\ + params|\ + release|\ + rump|\ + rumptest|\ + sets|\ + sourcesets|\ + syspkgs|\ + tools) + ;; + + *) + usage "Unknown operation \`${op}'" + ;; + + esac + # ${op} may contain chars that are not allowed in variable + # names. Replace them with '_' before setting do_${op}. + op="$( echo "$op" | tr -s '.-' '__')" + eval do_${op}=true + done + [ -n "${operations}" ] || usage "Missing operation to perform." + + # Set up MACHINE*. On a NetBSD host, these are allowed to be unset. + # + if [ -z "${MACHINE}" ]; then + [ "${uname_s}" = "Minix" ] || + bomb "MACHINE must be set, or -m must be used, for cross builds." + MACHINE=${uname_m} + fi + if $opt_m && ! $opt_a; then + # Settings implied by the command line -m option + # override MACHINE_ARCH from the environment (if any). + getarch + fi + [ -n "${MACHINE_ARCH}" ] || getarch + validatearch + + # Set up default make(1) environment. + # + makeenv="${makeenv} TOOLDIR MACHINE MACHINE_ARCH MAKEFLAGS" + [ -z "${BUILDID}" ] || makeenv="${makeenv} BUILDID" + [ -z "${BUILDINFO}" ] || makeenv="${makeenv} BUILDINFO" + MAKEFLAGS="-de -m ${TOP}/share/mk ${MAKEFLAGS}" + MAKEFLAGS="${MAKEFLAGS} MKOBJDIRS=${MKOBJDIRS-yes}" + export MAKEFLAGS MACHINE MACHINE_ARCH + setmakeenv USETOOLS "yes" + setmakeenv MAKEWRAPPERMACHINE "${makewrappermachine:-${MACHINE}}" +} + +# sanitycheck -- +# Sanity check after parsing command line options, before rebuildmake. +# +sanitycheck() +{ + # Install as non-root is a bad idea. + # + if ${do_install} && [ "$id_u" -ne 0 ] ; then + if ${do_expertmode}; then + warning "Will install as an unprivileged user." + else + bomb "-E must be set for install as an unprivileged user." + fi + fi + + # If the PATH contains any non-absolute components (including, + # but not limited to, "." or ""), then complain. As an exception, + # allow "" or "." as the last component of the PATH. This is fatal + # if expert mode is not in effect. + # + local path="${PATH}" + path="${path%:}" # delete trailing ":" + path="${path%:.}" # delete trailing ":." + case ":${path}:/" in + *:[!/]*) + if ${do_expertmode}; then + warning "PATH contains non-absolute components" + else + bomb "PATH environment variable must not" \ + "contain non-absolute components" + fi + ;; + esac +} + +# print_tooldir_make -- +# Try to find and print a path to an existing +# ${TOOLDIR}/bin/${toolprefix}make, for use by rebuildmake() before a +# new version of ${toolprefix}make has been built. +# +# * If TOOLDIR was set in the environment or on the command line, use +# that value. +# * Otherwise try to guess what TOOLDIR would be if not overridden by +# /etc/mk.conf, and check whether the resulting directory contains +# a copy of ${toolprefix}make (this should work for everybody who +# doesn't override TOOLDIR via /etc/mk.conf); +# * Failing that, search for ${toolprefix}make, nbmake, bmake, or make, +# in the PATH (this might accidentally find a version of make that +# does not understand the syntax used by NetBSD make, and that will +# lead to failure in the next step); +# * If a copy of make was found above, try to use it with +# nobomb_getmakevar to find the correct value for TOOLDIR, and believe the +# result only if it's a directory that already exists; +# * If a value of TOOLDIR was found above, and if +# ${TOOLDIR}/bin/${toolprefix}make exists, print that value. +# +print_tooldir_make() +{ + local possible_TOP_OBJ + local possible_TOOLDIR + local possible_make + local tooldir_make + + if [ -n "${TOOLDIR}" ]; then + echo "${TOOLDIR}/bin/${toolprefix}make" + return 0 + fi + + # Set host_ostype to something like "NetBSD-4.5.6-i386". This + # is intended to match the HOST_OSTYPE variable in . + # + local host_ostype="${uname_s}-$( + echo "${uname_r}" | sed -e 's/([^)]*)//g' -e 's/ /_/g' + )-$( + echo "${uname_p}" | sed -e 's/([^)]*)//g' -e 's/ /_/g' + )" + + # Look in a few potential locations for + # ${possible_TOOLDIR}/bin/${toolprefix}make. + # If we find it, then set possible_make. + # + # In the usual case (without interference from environment + # variables or /etc/mk.conf), should set TOOLDIR to + # "${_SRC_TOP_OBJ_}/tooldir.${host_ostype}". + # + # In practice it's difficult to figure out the correct value + # for _SRC_TOP_OBJ_. In the easiest case, when the -M or -O + # options were passed to build.sh, then ${TOP_objdir} will be + # the correct value. We also try a few other possibilities, but + # we do not replicate all the logic of . + # + for possible_TOP_OBJ in \ + "${TOP_objdir}" \ + "${MAKEOBJDIRPREFIX:+${MAKEOBJDIRPREFIX}${TOP}}" \ + "${TOP}" \ + "${TOP}/obj" \ + "${TOP}/obj.${MACHINE}" + do + [ -n "${possible_TOP_OBJ}" ] || continue + possible_TOOLDIR="${possible_TOP_OBJ}/tooldir.${host_ostype}" + possible_make="${possible_TOOLDIR}/bin/${toolprefix}make" + if [ -x "${possible_make}" ]; then + break + else + unset possible_make + fi + done + + # If the above didn't work, search the PATH for a suitable + # ${toolprefix}make, nbmake, bmake, or make. + # + : ${possible_make:=$(find_in_PATH ${toolprefix}make '')} + : ${possible_make:=$(find_in_PATH nbmake '')} + : ${possible_make:=$(find_in_PATH bmake '')} + : ${possible_make:=$(find_in_PATH make '')} + + # At this point, we don't care whether possible_make is in the + # correct TOOLDIR or not; we simply want it to be usable by + # getmakevar to help us find the correct TOOLDIR. + # + # Use ${possible_make} with nobomb_getmakevar to try to find + # the value of TOOLDIR. Believe the result only if it's + # a directory that already exists and contains bin/${toolprefix}make. + # + if [ -x "${possible_make}" ]; then + possible_TOOLDIR="$( + make="${possible_make}" \ + nobomb_getmakevar TOOLDIR 2>/dev/null + )" + if [ $? = 0 ] && [ -n "${possible_TOOLDIR}" ] \ + && [ -d "${possible_TOOLDIR}" ]; + then + tooldir_make="${possible_TOOLDIR}/bin/${toolprefix}make" + if [ -x "${tooldir_make}" ]; then + echo "${tooldir_make}" + return 0 + fi + fi + fi + return 1 +} + +# rebuildmake -- +# Rebuild nbmake in a temporary directory if necessary. Sets $make +# to a path to the nbmake executable. Sets done_rebuildmake=true +# if nbmake was rebuilt. +# +# There is a cyclic dependency between building nbmake and choosing +# TOOLDIR: TOOLDIR may be affected by settings in /etc/mk.conf, so we +# would like to use getmakevar to get the value of TOOLDIR; but we can't +# use getmakevar before we have an up to date version of nbmake; we +# might already have an up to date version of nbmake in TOOLDIR, but we +# don't yet know where TOOLDIR is. +# +# The default value of TOOLDIR also depends on the location of the top +# level object directory, so $(getmakevar TOOLDIR) invoked before or +# after making the top level object directory may produce different +# results. +# +# Strictly speaking, we should do the following: +# +# 1. build a new version of nbmake in a temporary directory; +# 2. use the temporary nbmake to create the top level obj directory; +# 3. use $(getmakevar TOOLDIR) with the temporary nbmake to +# get the correct value of TOOLDIR; +# 4. move the temporary nbmake to ${TOOLDIR}/bin/nbmake. +# +# However, people don't like building nbmake unnecessarily if their +# TOOLDIR has not changed since an earlier build. We try to avoid +# rebuilding a temporary version of nbmake by taking some shortcuts to +# guess a value for TOOLDIR, looking for an existing version of nbmake +# in that TOOLDIR, and checking whether that nbmake is newer than the +# sources used to build it. +# +rebuildmake() +{ + make="$(print_tooldir_make)" + if [ -n "${make}" ] && [ -x "${make}" ]; then + for f in usr.bin/make/*.[ch] usr.bin/make/lst.lib/*.[ch]; do + if [ "${f}" -nt "${make}" ]; then + statusmsg "${make} outdated" \ + "(older than ${f}), needs building." + do_rebuildmake=true + break + fi + done + else + statusmsg "No \$TOOLDIR/bin/${toolprefix}make, needs building." + do_rebuildmake=true + fi + + # Build bootstrap ${toolprefix}make if needed. + if ${do_rebuildmake}; then + statusmsg "Bootstrapping ${toolprefix}make" + ${runcmd} cd "${tmpdir}" + ${runcmd} env CC="${HOST_CC-cc}" CPPFLAGS="${HOST_CPPFLAGS}" \ + CFLAGS="${HOST_CFLAGS--O}" LDFLAGS="${HOST_LDFLAGS}" \ + ${HOST_SH} "${TOP}/tools/make/configure" || + ( cp ${tmpdir}/config.log ${tmpdir}-config.log + bomb "Configure of ${toolprefix}make failed, see ${tmpdir}-config.log for details" ) + ${runcmd} ${HOST_SH} buildmake.sh || + bomb "Build of ${toolprefix}make failed" + make="${tmpdir}/${toolprefix}make" + ${runcmd} cd "${TOP}" + ${runcmd} rm -f usr.bin/make/*.o usr.bin/make/lst.lib/*.o + done_rebuildmake=true + fi +} + +# validatemakeparams -- +# Perform some late sanity checks, after rebuildmake, +# but before createmakewrapper or any real work. +# +# Creates the top-level obj directory, because that +# is needed by some of the sanity checks. +# +# Prints status messages reporting the values of several variables. +# +validatemakeparams() +{ + # MAKECONF (which defaults to /etc/mk.conf in share/mk/bsd.own.mk) + # can affect many things, so mention it in an early status message. + # + MAKECONF=$(getmakevar MAKECONF) + if [ -e "${MAKECONF}" ]; then + statusmsg2 "MAKECONF file:" "${MAKECONF}" + else + statusmsg2 "MAKECONF file:" "${MAKECONF} (File not found)" + fi + + # Normalise MKOBJDIRS, MKUNPRIVED, and MKUPDATE. + # These may be set as build.sh options or in "mk.conf". + # Don't export them as they're only used for tests in build.sh. + # + MKOBJDIRS=$(getmakevar MKOBJDIRS) + MKUNPRIVED=$(getmakevar MKUNPRIVED) + MKUPDATE=$(getmakevar MKUPDATE) + + # Non-root should always use either the -U or -E flag. + # + if ! ${do_expertmode} && \ + [ "$id_u" -ne 0 ] && \ + [ "${MKUNPRIVED}" = "no" ] ; then + bomb "-U or -E must be set for build as an unprivileged user." + fi + + if [ "${runcmd}" = "echo" ]; then + TOOLCHAIN_MISSING=no + EXTERNAL_TOOLCHAIN="" + else + TOOLCHAIN_MISSING=$(bomb_getmakevar TOOLCHAIN_MISSING) + EXTERNAL_TOOLCHAIN=$(bomb_getmakevar EXTERNAL_TOOLCHAIN) + fi + if [ "${TOOLCHAIN_MISSING}" = "yes" ] && \ + [ -z "${EXTERNAL_TOOLCHAIN}" ]; then + ${runcmd} echo "ERROR: build.sh (in-tree cross-toolchain) is not yet available for" + ${runcmd} echo " MACHINE: ${MACHINE}" + ${runcmd} echo " MACHINE_ARCH: ${MACHINE_ARCH}" + ${runcmd} echo "" + ${runcmd} echo "All builds for this platform should be done via a traditional make" + ${runcmd} echo "If you wish to use an external cross-toolchain, set" + ${runcmd} echo " EXTERNAL_TOOLCHAIN=" + ${runcmd} echo "in either the environment or mk.conf and rerun" + ${runcmd} echo " ${progname} $*" + exit 1 + fi + + if [ "${MKOBJDIRS}" != "no" ]; then + # Create the top-level object directory. + # + # "make obj NOSUBDIR=" can handle most cases, but it + # can't handle the case where MAKEOBJDIRPREFIX is set + # while the corresponding directory does not exist + # (rules in would abort the build). We + # therefore have to handle the MAKEOBJDIRPREFIX case + # without invoking "make obj". The MAKEOBJDIR case + # could be handled either way, but we choose to handle + # it similarly to MAKEOBJDIRPREFIX. + # + if [ -n "${TOP_obj}" ]; then + # It must have been set by the "-M" or "-O" + # command line options, so there's no need to + # use getmakevar + : + elif [ -n "$MAKEOBJDIRPREFIX" ]; then + TOP_obj="$(getmakevar MAKEOBJDIRPREFIX)${TOP}" + elif [ -n "$MAKEOBJDIR" ]; then + TOP_obj="$(getmakevar MAKEOBJDIR)" + fi + if [ -n "$TOP_obj" ]; then + ${runcmd} mkdir -p "${TOP_obj}" || + bomb "Can't create top level object directory" \ + "${TOP_obj}" + else + ${runcmd} "${make}" -m ${TOP}/share/mk obj NOSUBDIR= || + bomb "Can't create top level object directory" \ + "using make obj" + fi + + # make obj in tools to ensure that the objdir for "tools" + # is available. + # + ${runcmd} cd tools + ${runcmd} "${make}" -m ${TOP}/share/mk obj NOSUBDIR= || + bomb "Failed to make obj in tools" + ${runcmd} cd "${TOP}" + fi + + # Find TOOLDIR, DESTDIR, and RELEASEDIR, according to getmakevar, + # and bomb if they have changed from the values we had from the + # command line or environment. + # + # This must be done after creating the top-level object directory. + # + for var in TOOLDIR DESTDIR RELEASEDIR + do + eval oldval=\"\$${var}\" + newval="$(getmakevar $var)" + if ! $do_expertmode; then + : ${_SRC_TOP_OBJ_:=$(getmakevar _SRC_TOP_OBJ_)} + case "$var" in + DESTDIR) + : ${newval:=${_SRC_TOP_OBJ_}/destdir.${MACHINE}} + makeenv="${makeenv} DESTDIR" + ;; + RELEASEDIR) + : ${newval:=${_SRC_TOP_OBJ_}/releasedir} + makeenv="${makeenv} RELEASEDIR" + ;; + esac + fi + if [ -n "$oldval" ] && [ "$oldval" != "$newval" ]; then + bomb "Value of ${var} has changed" \ + "(was \"${oldval}\", now \"${newval}\")" + fi + eval ${var}=\"\${newval}\" + eval export ${var} + statusmsg2 "${var} path:" "${newval}" + done + + # RELEASEMACHINEDIR is just a subdir name, e.g. "i386". + RELEASEMACHINEDIR=$(getmakevar RELEASEMACHINEDIR) + + # Check validity of TOOLDIR and DESTDIR. + # + if [ -z "${TOOLDIR}" ] || [ "${TOOLDIR}" = "/" ]; then + bomb "TOOLDIR '${TOOLDIR}' invalid" + fi + removedirs="${TOOLDIR}" + + if [ -z "${DESTDIR}" ] || [ "${DESTDIR}" = "/" ]; then + if ${do_distribution} || ${do_release} || \ + ( [ "${uname_s}" != "NetBSD" ] && [ "${uname_s}" != "Minix" ] ) || \ + [ "${uname_m}" != "${MACHINE}" ]; then + bomb "DESTDIR must != / for cross builds, or ${progname} 'distribution' or 'release'." + fi + if ! ${do_expertmode}; then + bomb "DESTDIR must != / for non -E (expert) builds" + fi + statusmsg "WARNING: Building to /, in expert mode." + statusmsg " This may cause your system to break! Reasons include:" + statusmsg " - your kernel is not up to date" + statusmsg " - the libraries or toolchain have changed" + statusmsg " YOU HAVE BEEN WARNED!" + else + removedirs="${removedirs} ${DESTDIR}" + fi + if ${do_releasekernel} && [ -z "${RELEASEDIR}" ]; then + bomb "Must set RELEASEDIR with \`releasekernel=...'" + fi + + # If a previous build.sh run used -U (and therefore created a + # METALOG file), then most subsequent build.sh runs must also + # use -U. If DESTDIR is about to be removed, then don't perform + # this check. + # + case "${do_removedirs} ${removedirs} " in + true*" ${DESTDIR} "*) + # DESTDIR is about to be removed + ;; + *) + if [ -e "${DESTDIR}/METALOG" ] && \ + [ "${MKUNPRIVED}" = "no" ] ; then + if $do_expertmode; then + warning "A previous build.sh run specified -U." + else + bomb "A previous build.sh run specified -U; you must specify it again now." + fi + fi + ;; + esac + + # live-image and install-image targets require binary sets + # (actually DESTDIR/etc/mtree/set.* files) built with MKUNPRIVED. + # If release operation is specified with live-image or install-image, + # the release op should be performed with -U for later image ops. + # + if ${do_release} && ( ${do_live_image} || ${do_install_image} ) && \ + [ "${MKUNPRIVED}" = "no" ] ; then + bomb "-U must be specified on building release to create images later." + fi +} + + +createmakewrapper() +{ + # Remove the target directories. + # + if ${do_removedirs}; then + for f in ${removedirs}; do + statusmsg "Removing ${f}" + ${runcmd} rm -r -f "${f}" + done + fi + + # Recreate $TOOLDIR. + # + ${runcmd} mkdir -p "${TOOLDIR}/bin" || + bomb "mkdir of '${TOOLDIR}/bin' failed" + + # If we did not previously rebuild ${toolprefix}make, then + # check whether $make is still valid and the same as the output + # from print_tooldir_make. If not, then rebuild make now. A + # possible reason for this being necessary is that the actual + # value of TOOLDIR might be different from the value guessed + # before the top level obj dir was created. + # + if ! ${done_rebuildmake} && \ + ( [ ! -x "$make" ] || [ "$make" != "$(print_tooldir_make)" ] ) + then + rebuildmake + fi + + # Install ${toolprefix}make if it was built. + # + if ${done_rebuildmake}; then + ${runcmd} rm -f "${TOOLDIR}/bin/${toolprefix}make" + ${runcmd} cp "${make}" "${TOOLDIR}/bin/${toolprefix}make" || + bomb "Failed to install \$TOOLDIR/bin/${toolprefix}make" + make="${TOOLDIR}/bin/${toolprefix}make" + statusmsg "Created ${make}" + fi + + # Build a ${toolprefix}make wrapper script, usable by hand as + # well as by build.sh. + # + if [ -z "${makewrapper}" ]; then + makewrapper="${TOOLDIR}/bin/${toolprefix}make-${makewrappermachine:-${MACHINE}}" + [ -z "${BUILDID}" ] || makewrapper="${makewrapper}-${BUILDID}" + fi + + ${runcmd} rm -f "${makewrapper}" + if [ "${runcmd}" = "echo" ]; then + echo 'cat <'${makewrapper} + makewrapout= + else + makewrapout=">>\${makewrapper}" + fi + + case "${KSH_VERSION:-${SH_VERSION}}" in + *PD\ KSH*|*MIRBSD\ KSH*) + set +o braceexpand + ;; + esac + + eval cat < ${releasekern}" + else + gzip -c -9 < "${builtkern}" > "${releasekern}" + fi + done +} + +buildkernels() +{ + allkernels=$( runcmd= make_in_dir etc '-V ${ALL_KERNELS}' ) + for k in $allkernels; do + buildkernel "${k}" + done +} + +buildmodules() +{ + setmakeenv MKBINUTILS no + if ! ${do_tools} && ! ${buildmoduleswarned:-false}; then + # Building tools every time we build modules is clearly + # unnecessary as well as a kernel. + # + statusmsg "Building modules without building new tools" + buildmoduleswarned=true + fi + + statusmsg "Building kernel modules for NetBSD/${MACHINE} ${DISTRIBVER}" + if [ "${MKOBJDIRS}" != "no" ]; then + make_in_dir sys/modules obj + fi + if [ "${MKUPDATE}" = "no" ]; then + make_in_dir sys/modules cleandir + fi + make_in_dir sys/modules dependall + make_in_dir sys/modules install + + statusmsg "Successful build of kernel modules for NetBSD/${MACHINE} ${DISTRIBVER}" +} + +installmodules() +{ + dir="$1" + ${runcmd} "${makewrapper}" INSTALLMODULESDIR="${dir}" installmodules || + bomb "Failed to make installmodules to ${dir}" + statusmsg "Successful installmodules to ${dir}" +} + +installworld() +{ + dir="$1" + ${runcmd} "${makewrapper}" INSTALLWORLDDIR="${dir}" installworld || + bomb "Failed to make installworld to ${dir}" + statusmsg "Successful installworld to ${dir}" +} + +# Run rump build&link tests. +# +# To make this feasible for running without having to install includes and +# libraries into destdir (i.e. quick), we only run ld. This is possible +# since the rump kernel is a closed namespace apart from calls to rumpuser. +# Therefore, if ld complains only about rumpuser symbols, rump kernel +# linking was successful. +# +# We test that rump links with a number of component configurations. +# These attempt to mimic what is encountered in the full build. +# See list below. The list should probably be either autogenerated +# or managed elsewhere; keep it here until a better idea arises. +# +# Above all, note that THIS IS NOT A SUBSTITUTE FOR A FULL BUILD. +# + +RUMP_LIBSETS=' + -lrump, + -lrumpvfs -lrump, + -lrumpvfs -lrumpdev -lrump, + -lrumpnet -lrump, + -lrumpkern_tty -lrumpvfs -lrump, + -lrumpfs_tmpfs -lrumpvfs -lrump, + -lrumpfs_ffs -lrumpfs_msdos -lrumpvfs -lrumpdev_disk -lrumpdev -lrump, + -lrumpnet_virtif -lrumpnet_netinet -lrumpnet_net -lrumpnet -lrump, + -lrumpnet_sockin -lrumpfs_smbfs -lrumpdev_netsmb + -lrumpkern_crypto -lrumpdev -lrumpnet -lrumpvfs -lrump, + -lrumpnet_sockin -lrumpfs_nfs -lrumpnet -lrumpvfs -lrump, + -lrumpdev_cgd -lrumpdev_raidframe -lrumpdev_disk -lrumpdev_rnd + -lrumpdev_dm -lrumpdev -lrumpvfs -lrumpkern_crypto -lrump' +dorump() +{ + local doclean="" + local doobjs="" + + # we cannot link libs without building csu, and that leads to lossage + [ "${1}" != "rumptest" ] && bomb 'build.sh rump not yet functional. ' \ + 'did you mean "rumptest"?' + + export RUMPKERN_ONLY=1 + # create obj and distrib dirs + if [ "${MKOBJDIRS}" != "no" ]; then + make_in_dir "${NETBSDSRCDIR}/etc/mtree" obj + make_in_dir "${NETBSDSRCDIR}/sys/rump" obj + fi + ${runcmd} "${makewrapper}" ${parallel} do-distrib-dirs \ + || bomb 'could not create distrib-dirs' + + [ "${MKUPDATE}" = "no" ] && doclean="cleandir" + targlist="${doclean} ${doobjs} dependall install" + # optimize: for test we build only static libs (3x test speedup) + if [ "${1}" = "rumptest" ] ; then + setmakeenv NOPIC 1 + setmakeenv NOPROFILE 1 + fi + for cmd in ${targlist} ; do + make_in_dir "${NETBSDSRCDIR}/sys/rump" ${cmd} + done + + # if we just wanted to build & install rump, we're done + [ "${1}" != "rumptest" ] && return + + ${runcmd} cd "${NETBSDSRCDIR}/sys/rump/librump/rumpkern" \ + || bomb "cd to rumpkern failed" + md_quirks=`${runcmd} "${makewrapper}" -V '${_SYMQUIRK}'` + # one little, two little, three little backslashes ... + md_quirks="$(echo ${md_quirks} | sed 's,\\,\\\\,g'";s/'//g" )" + ${runcmd} cd "${TOP}" || bomb "cd to ${TOP} failed" + tool_ld=`${runcmd} "${makewrapper}" -V '${LD}'` + + local oIFS="${IFS}" + IFS="," + for set in ${RUMP_LIBSETS} ; do + IFS="${oIFS}" + ${runcmd} ${tool_ld} -nostdlib -L${DESTDIR}/usr/lib \ + -static --whole-archive ${set} 2>&1 -o /tmp/rumptest.$$ | \ + awk -v quirks="${md_quirks}" ' + /undefined reference/ && + !/more undefined references.*follow/{ + if (match($NF, + "`(rumpuser_|rumpcomp_|__" quirks ")") == 0) + fails[NR] = $0 + } + /cannot find -l/{fails[NR] = $0} + /cannot open output file/{fails[NR] = $0} + END{ + for (x in fails) + print fails[x] + exit x!=0 + }' + [ $? -ne 0 ] && bomb "Testlink of rump failed: ${set}" + done + statusmsg "Rump build&link tests successful" +} + +main() +{ + initdefaults + _args=$@ + parseoptions "$@" + + sanitycheck + + build_start=$(date) + statusmsg2 "${progname} command:" "$0 $*" + statusmsg2 "${progname} started:" "${build_start}" + statusmsg2 "MINIX version:" "${DISTRIBVER}" + statusmsg2 "MACHINE:" "${MACHINE}" + statusmsg2 "MACHINE_ARCH:" "${MACHINE_ARCH}" + statusmsg2 "Build platform:" "${uname_s} ${uname_r} ${uname_m}" + statusmsg2 "HOST_SH:" "${HOST_SH}" + if [ -n "${BUILDID}" ]; then + statusmsg2 "BUILDID:" "${BUILDID}" + fi + if [ -n "${BUILDINFO}" ]; then + printf "%b\n" "${BUILDINFO}" | \ + while read -r line ; do + [ -s "${line}" ] && continue + statusmsg2 "BUILDINFO:" "${line}" + done + fi + + rebuildmake + validatemakeparams + createmakewrapper + + # Perform the operations. + # + for op in ${operations}; do + case "${op}" in + + makewrapper) + # no-op + ;; + + tools) + buildtools + ;; + + sets) + statusmsg "Building sets from pre-populated ${DESTDIR}" + ${runcmd} "${makewrapper}" ${parallel} ${op} || + bomb "Failed to make ${op}" + setdir=${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets + statusmsg "Built sets to ${setdir}" + ;; + + cleandir|obj|build|distribution|release|sourcesets|syspkgs|show-params) + ${runcmd} "${makewrapper}" ${parallel} ${op} || + bomb "Failed to make ${op}" + statusmsg "Successful make ${op}" + ;; + + iso-image|iso-image-source) + ${runcmd} "${makewrapper}" ${parallel} \ + CDEXTRA="$CDEXTRA" ${op} || + bomb "Failed to make ${op}" + statusmsg "Successful make ${op}" + ;; + + live-image|install-image) + # install-image and live-image require mtree spec files + # built with UNPRIVED. Assume UNPRIVED build has been + # performed if METALOG file is created in DESTDIR. + if [ ! -e "${DESTDIR}/METALOG" ] ; then + bomb "The release binaries must have been built with -U to create images." + fi + ${runcmd} "${makewrapper}" ${parallel} ${op} || + bomb "Failed to make ${op}" + statusmsg "Successful make ${op}" + ;; + kernel=*) + arg=${op#*=} + buildkernel "${arg}" + ;; + kernel.gdb=*) + arg=${op#*=} + configopts="-D DEBUG=-g" + buildkernel "${arg}" + ;; + releasekernel=*) + arg=${op#*=} + releasekernel "${arg}" + ;; + + kernels) + buildkernels + ;; + + disk-image=*) + arg=${op#*=} + diskimage "${arg}" + ;; + + modules) + buildmodules + ;; + + installmodules=*) + arg=${op#*=} + if [ "${arg}" = "/" ] && \ + ( ( [ "${uname_s}" != "NetBSD" ] && [ "${uname_s}" != "Minix" ] ) || \ + [ "${uname_m}" != "${MACHINE}" ] ); then + bomb "'${op}' must != / for cross builds." + fi + installmodules "${arg}" + ;; + + install=*) + arg=${op#*=} + if [ "${arg}" = "/" ] && \ + ( ( [ "${uname_s}" != "NetBSD" ] && [ "${uname_s}" != "Minix" ] ) || \ + [ "${uname_m}" != "${MACHINE}" ] ); then + bomb "'${op}' must != / for cross builds." + fi + installworld "${arg}" + ;; + + rump|rumptest) + dorump "${op}" + ;; + + *) + bomb "Unknown operation \`${op}'" + ;; + + esac + done + + statusmsg2 "${progname} ended:" "$(date)" + if [ -s "${results}" ]; then + echo "===> Summary of results:" + sed -e 's/^===>//;s/^/ /' "${results}" + echo "===> ." + fi +} + +main "$@" diff --git a/build/bin/.gitignore b/build/bin/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/build/bin/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/build/lib/.gitignore b/build/lib/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/build/lib/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/build/libexec/.gitignore b/build/libexec/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/build/libexec/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/libexec/ld.elf_so/Makefile b/libexec/ld.elf_so/Makefile new file mode 100644 index 0000000..db85020 --- /dev/null +++ b/libexec/ld.elf_so/Makefile @@ -0,0 +1,46 @@ +# $Id: Makefile 119 2016-01-14 03:06:36Z reddawg $ +# Application Makefile (C) 2002-2004 The UbixOS Project + +# Include Global 'Source' Options +include ../../Makefile.incl +include ../Makefile.incl + +#Linker +LD = ld + +#Binary File Name +OUTPUT = ld.so + +#Delete Program +REMOVE = rm -f + +#Objects +OBJS = main.o findlibrary.o findfunc.o addlibrary.o entry.o + +# Link The Binary +$(OUTPUT) : $(OBJS) + $(CC) -m32 -nostdlib -shared -Wl,-soname,$(OUTPUT) -Wl,-m,elf_i386_fbsd -e _ld -o ../../build/libexec/$(OUTPUT) $(OBJS) $(LIBRARIES) $(SUBS) +# strip $(OUTPUT) + +# Compile the source files +.cpp.o: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.cc.o: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.cc.s: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.c.o: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.c.s: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.S.o: + $(CC) -Wall $(CFLAGS) $(INCLUDES) -c -o $@ $< + +# Clean Up The junk +clean: + $(REMOVE) $(OBJS) ../../build/bin/$(OUTPUT) diff --git a/libexec/ld.elf_so/addlibrary.c b/libexec/ld.elf_so/addlibrary.c new file mode 100644 index 0000000..e527520 --- /dev/null +++ b/libexec/ld.elf_so/addlibrary.c @@ -0,0 +1,161 @@ +#include +#include +#include "ld.h" + +ldLibrary *ldAddLibrary(const char *lib) { + int i = 0x0; + int x = 0x0; + int rel = 0x0; + uInt32 *reMap = 0x0; + char *newLoc = 0x0; + FILE *linkerFd = 0x0; + char tmpFile[1024]; + ldLibrary *tmpLib = 0x0; + + if ((tmpLib = (ldLibrary *)malloc(sizeof(ldLibrary))) == 0x0) { + printf("malloc failed: tmpLib\n"); + exit(0x1); + } + if (tmpLib->output == 0x0) { + /* Hack because we have no ld path set */ + sprintf(tmpFile,"sys:/lib/%s",lib); + linkerFd = fopen(tmpFile,"rb"); + if (linkerFd->fd == 0x0) { + printf("Could not open library: %s\n",lib); + exit(-1); + } + //if ((tmpLib->output = (char *)malloc((linkerFd->size+0x4000))) == 0x0) { + //if ((tmpLib->output = (char *)malloc(0x111000)) == 0x0) { + if ((tmpLib->output = (char *)getPage((0x111000/0x1000),2)) == 0x0) { + printf("malloc failed: tmpLib->output\n"); + exit(0x1); + } + sprintf(tmpLib->name,lib); + } + printf("Base: {0x%X}\n",tmpLib->output); + if (tmpLib->linkerHeader == 0x0) { + fseek(linkerFd,0x0,0x0); + if ((tmpLib->linkerHeader = (elfHeader *)malloc(sizeof(elfHeader))) == 0x0) { + printf("malloc failed: tmpLib->linkerHeader\n"); + exit(0x1); + } + fread(tmpLib->linkerHeader,sizeof(elfHeader),1,linkerFd); + } + if (tmpLib->linkerProgramHeader == 0x0) { + if ((tmpLib->linkerProgramHeader = (elfProgramHeader *)malloc(sizeof(elfProgramHeader)*tmpLib->linkerHeader->ePhnum)) == 0x0) { + printf("malloc failed: tmpLib->linkerProgramHeader\n"); + exit(0x1); + } + fseek(linkerFd,tmpLib->linkerHeader->ePhoff,0); + fread(tmpLib->linkerProgramHeader,sizeof(elfProgramHeader),tmpLib->linkerHeader->ePhnum,linkerFd); + + for (i=0;ilinkerHeader->ePhnum;i++) { + switch (tmpLib->linkerProgramHeader[i].phType) { + case PT_LOAD: + case PT_DYNAMIC: + newLoc = (char *)tmpLib->linkerProgramHeader[i].phVaddr + (uInt32)tmpLib->output; + fseek(linkerFd,tmpLib->linkerProgramHeader[i].phOffset,0); + fread(newLoc,tmpLib->linkerProgramHeader[i].phFilesz,1,linkerFd); + break; + case PT_GNU_STACK: + /* Tells us if the stack should be executable. Failsafe to + executable until we add checking */ + printf("NOT DEF1\n"); + break; + case PT_PAX_FLAGS: + /* Not sure... */ + printf("NOT DEF2\n"); + break; + default: + printf("Unhandled Header (ld.so) : %08x\n", tmpLib->linkerProgramHeader[i].phType); + break; + } + } + } + + if (tmpLib->linkerSectionHeader == 0x0) { + if ((tmpLib->linkerSectionHeader = (elfSectionHeader *)malloc(sizeof(elfSectionHeader)*tmpLib->linkerHeader->eShnum)) == 0x0) { + printf("malloc failed: tmpLib->linkerSectionHeader\n"); + exit(0x1); + } + fseek(linkerFd,tmpLib->linkerHeader->eShoff,0); + fread(tmpLib->linkerSectionHeader,sizeof(elfSectionHeader),tmpLib->linkerHeader->eShnum,linkerFd); + + if (tmpLib->linkerShStr == 0x0) { + tmpLib->linkerShStr = (char *)malloc(tmpLib->linkerSectionHeader[tmpLib->linkerHeader->eShstrndx].shSize); + fseek(linkerFd,tmpLib->linkerSectionHeader[tmpLib->linkerHeader->eShstrndx].shOffset,0); + fread(tmpLib->linkerShStr,tmpLib->linkerSectionHeader[tmpLib->linkerHeader->eShstrndx].shSize,1,linkerFd); + } + + for (i = 0x0;i < tmpLib->linkerHeader->eShnum;i++) { + switch (tmpLib->linkerSectionHeader[i].shType) { + case 3: + if (!strcmp((tmpLib->linkerShStr + tmpLib->linkerSectionHeader[i].shName),".dynstr")) { + if (tmpLib->linkerDynStr == 0x0) { + if ((tmpLib->linkerDynStr = (char *)malloc(tmpLib->linkerSectionHeader[i].shSize)) == 0x0) { + printf("malloc failed: tmpLib->linkerDynStr\n"); + exit(0x1); + } + fseek(linkerFd,tmpLib->linkerSectionHeader[i].shOffset,0); + fread(tmpLib->linkerDynStr,tmpLib->linkerSectionHeader[i].shSize,1,linkerFd); + } + } + break; + case 9: + if ((tmpLib->linkerElfRel = (elfPltInfo *)malloc(tmpLib->linkerSectionHeader[i].shSize)) == 0x0) { + printf("malloc failed: tmpLib->linkerElfRel\n"); + exit(0x1); + } + fseek(linkerFd,tmpLib->linkerSectionHeader[i].shOffset,0x0); + fread(tmpLib->linkerElfRel,tmpLib->linkerSectionHeader[i].shSize,1,linkerFd); + + for (x=0x0;xlinkerSectionHeader[i].shSize/sizeof(elfPltInfo);x++) { + rel = ELF32_R_SYM(tmpLib->linkerElfRel[x].pltInfo); + reMap = (uInt32 *)((uInt32)tmpLib->output + tmpLib->linkerElfRel[x].pltOffset); + switch (ELF32_R_TYPE(tmpLib->linkerElfRel[x].pltInfo)) { + case R_386_32: + *reMap += ((uInt32)tmpLib->output + tmpLib->linkerRelSymTab[rel].dynValue); + //printf("[0x%X]",*reMap); + break; + case R_386_PC32: + *reMap += ((uInt32)tmpLib->output + tmpLib->linkerRelSymTab[rel].dynValue) - (uInt32)reMap; + break; + case R_386_RELATIVE: + *reMap += (uInt32)tmpLib->output; + break; + case R_386_JMP_SLOT: + *reMap += (uInt32)tmpLib->output; + break; + case R_386_GLOB_DAT: + *reMap = ((uInt32)tmpLib->output + tmpLib->linkerRelSymTab[rel].dynValue); + break; + default: + printf("Unhandled sym: [0x%X]\n", ELF32_R_TYPE(tmpLib->linkerElfRel[x].pltInfo)); + while (1); + break; + } + } + free(tmpLib->linkerElfRel); + break; + case 11: + if (tmpLib->linkerRelSymTab == 0x0) { + tmpLib->linkerRelSymTab = (elfDynSym *)malloc(tmpLib->linkerSectionHeader[i].shSize); + fseek(linkerFd,tmpLib->linkerSectionHeader[i].shOffset,0); + fread(tmpLib->linkerRelSymTab,tmpLib->linkerSectionHeader[i].shSize,1,linkerFd); + tmpLib->sym = i; + } + break; + } + } + } + if (libs != 0x0) + libs->prev = tmpLib; + tmpLib->prev = 0x0; + tmpLib->next = libs; + libs = tmpLib; + + if (linkerFd) { + fclose(linkerFd); + } + return(tmpLib); + } diff --git a/libexec/ld.elf_so/elf.h b/libexec/ld.elf_so/elf.h new file mode 100644 index 0000000..d344299 --- /dev/null +++ b/libexec/ld.elf_so/elf.h @@ -0,0 +1,186 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id: elf.h 89 2016-01-12 00:20:40Z reddawg $ + +**************************************************************************************/ + +#ifndef _ELF_H +#define _ELF_H + +#include + +#define elfExecutable 0x002 +#define elfLibrary 0x003 + +#define R_386_NONE 0 /* none none */ +#define R_386_32 1 /* word32 S + A */ +#define R_386_PC32 2 /* word32 S + A - P */ +#define R_386_GOT32 3 /* word32 G + A - P */ +#define R_386_PLT32 4 /* word32 L + A - P */ +#define R_386_COPY 5 /* none none */ +#define R_386_GLOB_DAT 6 /* word32 S */ +#define R_386_JMP_SLOT 7 /* word32 S */ +#define R_386_RELATIVE 8 /* word32 B + A */ +#define R_386_GOTOFF 9 /* word32 S + A - GOT */ +#define R_386_GOTPC 10 /* word32 GOT + A - P */ + + +/* Elf Types */ +#define ET_NONE 0 // No file type +#define ET_REL 1 // Relocatable file +#define ET_EXEC 2 // Executable file +#define ET_DYN 3 // Shared object file +#define ET_CORE 4 // Core file +#define ET_LOPROC 0xff00 // Processor-specific +#define ET_HIPROC 0xffff +/* End Elf Types */ + +/* Elf Machine Types */ +#define EM_NONE 0 // No machine +#define EM_M32 1 // AT&T WE 32100 +#define EM_SPARC 2 // SPARC +#define EM_386 3 // Intel 80386 +#define EM_68K 4 // Motorola 68000 +#define EM_88K 5 // Motorola 88000 +#define EM_860 7 // Intel 80860 +#define EM_MIPS 8 // MIPS RS3000 +/* End Elf Machines Types */ + +/* Elf Version */ +#define EV_NONE 0 // Invalid version +#define EV_CURRENT 1 // Current version +/* End Elf Version */ + +/* Elf Program Header Types */ +#define PT_NULL 0 +#define PT_LOAD 1 +#define PT_DYNAMIC 2 +#define PT_INTERP 3 +#define PT_NOTE 4 +#define PT_SHLIB 5 +#define PT_PHDR 6 +#define PT_LOOS 0x60000000 +#define PT_HIOS 0x6fffffff +#define PT_LOPROC 0x70000000 +#define PT_HIPROC 0x7fffffff +#define PT_GNU_EH_FRAME 0x6474e550 +#define PT_GNU_STACK (PT_LOOS + 0x474e551) +#define PT_GNU_RELRO (PT_LOOS + 0x474e552) +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580) +/* End Elf Program Header Types */ + +typedef struct { + uInt8 eIdent[16]; /* File identification. */ + uInt16 eType; /* File type. */ + uInt16 eMachine; /* Machine architecture. */ + uInt32 eVersion; /* ELF format version. */ + uInt32 eEntry; /* Entry point. */ + uInt32 ePhoff; /* Program Header file offset. */ + uInt32 eShoff; /* Section header file offset. */ + uInt32 eFlags; /* Architecture-specific flags. */ + uInt16 eEhsize; /* Size of ELF header in bytes. */ + uInt16 ePhentsize; /* Size of program header entry. */ + uInt16 ePhnum; /* Number of program header entries. */ + uInt16 eShentsize; /* Size of section header entry. */ + uInt16 eShnum; /* Number of section header entries. */ + uInt16 eShstrndx; /* Section name strings section. */ + } elfHeader; + +typedef struct { + uInt32 phType; /* Entry type. */ + uInt32 phOffset; /* File offset of contents. */ + uInt32 phVaddr; /* Virtual address in memory image. */ + uInt32 phPaddr; /* Physical address (not used). */ + uInt32 phFilesz; /* Size of contents in file. */ + uInt32 phMemsz; /* Size of contents in memory. */ + uInt32 phFlags; /* Access permission flags. */ + uInt32 phAlign; /* Alignment in memory and file. */ + } elfProgramHeader; + +typedef struct { + uInt32 shName; /* Section name (index into the section header string table). */ + uInt32 shType; /* Section type. */ + uInt32 shFlags; /* Section flags. */ + uInt32 shAddr; /* Address in memory image. */ + uInt32 shOffset; /* Offset in file. */ + uInt32 shSize; /* Size in bytes. */ + uInt32 shLink; /* Index of a related section. */ + uInt32 shInfo; /* Depends on section type. */ + uInt32 shAddralign; /* Alignment in bytes. */ + uInt32 shEntsize; /* Size of each entry in section. */ + } elfSectionHeader; + +typedef struct { + uInt32 pltOffset; + uInt32 pltInfo; + } elfPltInfo; + +typedef struct { + uInt32 dynName; + uInt32 dynValue; + uInt32 dynSize; + uInt8 dynInfo; + uInt8 dynOther; + uInt16 dynShndx; + } elfDynSym; + +typedef struct { + uInt32 dynVal; + uInt32 dynPtr; + } elfDynamic; + + +char *elfGetShType(int); +char *elfGetPhType(int); +char *elfGetRelType(int); + +#define ELF32_R_SYM(i) ((i)>>8) +#define ELF32_R_TYPE(i) ((unsigned char)(i)) +#define ELF32_R_INFO(s, t) ((s)<<8+(unsigned char)(t)) + +/* New Stuff */ +#define SHT_NULL 0 +#define SHT_PROGBITS 1 +#define SHT_SYMTAB 2 +#define SHT_STRTAB 3 +#define SHT_RELA 4 +#define SHT_HASH 5 +#define SHT_DYNAMIC 6 +#define SHT_NOTE 7 +#define SHT_NOBITS 8 +#define SHT_REL 9 +#define SHT_SHLIB 10 +#define SHT_DYNSYM 11 +#define SHT_LOPROC 0x70000000 +#define SHT_HIPROC 0x7fffffff +#define SHT_LOUSER 0x80000000 +#define SHT_HIUSER 0xffffffff + +typedef struct { + long d_tag; + union { + uInt32 d_val; + uInt32 d_ptr; + } d_un; + } Elf32_Dyn; + + +#endif + diff --git a/libexec/ld.elf_so/entry.S b/libexec/ld.elf_so/entry.S new file mode 100644 index 0000000..5b7ba32 --- /dev/null +++ b/libexec/ld.elf_so/entry.S @@ -0,0 +1,57 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id: entry.S 89 2016-01-12 00:20:40Z reddawg $ + +*****************************************************************************************/ + +.globl _ld +.text +.code32 + +_ld: + call ld + add $8,%esp + push %eax + ret + +/*** + $Log: entry.S,v $ + Revision 1.1.1.1 2006/06/01 12:46:09 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:28 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:14:00 reddawg + no message + + Revision 1.1 2004/06/17 11:58:10 reddawg + ld.so: Made a few changes to the way it functions hopefully it will + improve some of its performance. + + END + ***/ + diff --git a/libexec/ld.elf_so/findfunc.c b/libexec/ld.elf_so/findfunc.c new file mode 100644 index 0000000..527000c --- /dev/null +++ b/libexec/ld.elf_so/findfunc.c @@ -0,0 +1,32 @@ +#include +#include +#include "ld.h" + +uInt32 ldFindFunc(const char *func,const char *lib) { + int i = 0x0; + int x = 0x0; + uInt32 *funcPtr = 0x0; + ldLibrary *libPtr = 0x0; + + for (x = 0; x < lib_c;x++) { + libPtr = ldFindLibrary(lib + lib_s[x]); + if (libPtr == 0x0) { + libPtr = ldAddLibrary(lib + lib_s[x]); + } + + for (i=0x0;ilinkerSectionHeader[libPtr->sym].shSize/sizeof(elfDynSym);i++) { + if (!strcmp(func,(libPtr->linkerDynStr + libPtr->linkerRelSymTab[i].dynName))) { + funcPtr = (uInt32 *)((uInt32)(libPtr->linkerRelSymTab[i].dynValue) + (uInt32)libPtr->output); + if (funcPtr == 0x0) { + printf("[%s:0x%X]\n",func,funcPtr); + } + return((uInt32)funcPtr); + break; + } + } + } + + printf("ERROR COULDN'T FIND FUNCTION: %s:%s\n",func,lib); + return(0x0); + } + diff --git a/libexec/ld.elf_so/findlibrary.c b/libexec/ld.elf_so/findlibrary.c new file mode 100644 index 0000000..f071e7d --- /dev/null +++ b/libexec/ld.elf_so/findlibrary.c @@ -0,0 +1,13 @@ +#include +#include "ld.h" + +ldLibrary *ldFindLibrary(const char *lib) { + ldLibrary *tmpLibs = 0x0; + + for (tmpLibs = libs;tmpLibs != 0x0;tmpLibs = tmpLibs->next) { + if (!strcmp(tmpLibs->name,lib)) { + return(tmpLibs); + } + } + return(0x0); + } diff --git a/libexec/ld.elf_so/ld.h b/libexec/ld.elf_so/ld.h new file mode 100644 index 0000000..0255e4d --- /dev/null +++ b/libexec/ld.elf_so/ld.h @@ -0,0 +1,31 @@ +#include +#include +#include "elf.h" + +typedef struct ldLibrary_s { + struct ldLibrary_s *next; + struct ldLibrary_s *prev; + char name[256]; + elfHeader *linkerHeader; + elfSectionHeader *linkerSectionHeader; + elfProgramHeader *linkerProgramHeader; + elfDynSym *linkerRelSymTab; + elfPltInfo *linkerElfRel; + char *linkerShStr; + char *linkerDynStr; + char *output; + int sym; + } ldLibrary; + +extern ldLibrary *libs; +extern int lib_c; +extern int lib_s[10]; + +uInt32 ldFindFunc(const char *,const char *); +ldLibrary *ldFindLibrary(const char *); +ldLibrary *ldAddLibrary(const char *); + +/*** + END + ***/ + diff --git a/libexec/ld.elf_so/main.c b/libexec/ld.elf_so/main.c new file mode 100644 index 0000000..ee9f78b --- /dev/null +++ b/libexec/ld.elf_so/main.c @@ -0,0 +1,159 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id: main.c 122 2016-01-14 03:45:52Z reddawg $ + + *****************************************************************************************/ + +#include +#include +#include +#include "ld.h" + +ldLibrary *libs = 0x0; +int lib_c = 0x0; +int lib_s[10]; + +static elfHeader *binaryHeader = 0x0; +static elfSectionHeader *binarySectionHeader = 0x0; +static char *binaryShStr = 0x0; +static char *binaryDynStr = 0x0; +static elfDynSym *binaryRelSymTab = 0x0; +static Elf32_Dyn *binaryElf32_Dyn = 0x0; +static elfPltInfo *binaryElfRelDyn = 0x0; +static elfPltInfo *binaryElfRel = 0x0; + +uInt32 ld( uInt32 got2, uInt32 entry ) { + int i = 0x0; + int x = 0x0; + int y = 0x0; + int rel = 0x0; + int relDyn = 0x0; + uInt32 *reMap = 0x0; + FILE *binaryFd = 0x0; + + if ( binaryHeader == 0x0 ) { + binaryFd = malloc( sizeof(FILE) ); + binaryFd->fd = (uInt32) got2; + fseek( binaryFd, 0x0, 0x0 ); + binaryHeader = (elfHeader *) malloc( sizeof(elfHeader) ); + fread( binaryHeader, sizeof(elfHeader), 1, binaryFd ); + } + + if ( binarySectionHeader == 0x0 ) { + binarySectionHeader = (elfSectionHeader *) malloc( sizeof(elfSectionHeader) * binaryHeader->eShnum ); + fseek( binaryFd, binaryHeader->eShoff, 0 ); + fread( binarySectionHeader, sizeof(elfSectionHeader), binaryHeader->eShnum, binaryFd ); + + if ( binaryShStr == 0x0 ) { + binaryShStr = (char *) malloc( binarySectionHeader[binaryHeader->eShstrndx].shSize ); + fseek( binaryFd, binarySectionHeader[binaryHeader->eShstrndx].shOffset, 0 ); + fread( binaryShStr, binarySectionHeader[binaryHeader->eShstrndx].shSize, 1, binaryFd ); + } + + for ( i = 0x0; i < binaryHeader->eShnum ; i++ ) { + switch ( binarySectionHeader[i].shType ) { + case 3: + if ( !strcmp( ( binaryShStr + binarySectionHeader[i].shName ), ".dynstr" ) ) { + if ( binaryDynStr == 0x0 ) { + binaryDynStr = (char *) malloc( binarySectionHeader[i].shSize ); + fseek( binaryFd, binarySectionHeader[i].shOffset, 0 ); + fread( binaryDynStr, binarySectionHeader[i].shSize, 1, binaryFd ); + } + } + break; + case SHT_DYNAMIC: + binaryElf32_Dyn = (Elf32_Dyn *) malloc( binarySectionHeader[i].shSize ); + fseek( binaryFd, binarySectionHeader[i].shOffset, 0 ); + fread( binaryElf32_Dyn, binarySectionHeader[i].shSize, 1, binaryFd ); + for ( x = 0; x < binarySectionHeader[i].shSize / sizeof(Elf32_Dyn) ; x++ ) { + if ( binaryElf32_Dyn[x].d_tag == 1 ) { + lib_s[lib_c] = binaryElf32_Dyn[x].d_un.d_ptr; + lib_c++; + } + } + break; + case SHT_REL: + // if (!strcmp(binaryShStr + binarySectionHeader[i].shName,".rel.dyn")) + // relDyn = i; + // else + rel = i; + break; + case 11: + if ( binaryRelSymTab == 0x0 ) { + binaryRelSymTab = (elfDynSym *) malloc( binarySectionHeader[i].shSize ); + fseek( binaryFd, binarySectionHeader[i].shOffset, 0 ); + fread( binaryRelSymTab, binarySectionHeader[i].shSize, 1, binaryFd ); + } + break; + } + } + } + + /* + if ((binaryElfRelDyn == 0x0) && (relDyn != 0)) { + binaryElfRelDyn = (elfPltInfo *)malloc(binarySectionHeader[i].shSize); + fseek(binaryFd,binarySectionHeader[relDyn].shOffset,0x0); + fread(binaryElfRelDyn,binarySectionHeader[relDyn].shSize,1,binaryFd); + + for (x = 0;x < binarySectionHeader[relDyn].shSize / sizeof(elfPltInfo);x++) { + switch (ELF32_R_TYPE(binaryElfRelDyn[x].pltInfo)) { + case R_386_COPY: + printf("COPY"); + reMap = (uInt32 *)binaryElfRelDyn[x].pltOffset; + *reMap = 0x1; + break; + default: + //printf("UNHANDLED THING"); + break; + } + printf("y: [%i:0x%X]",y,binaryElfRelDyn[x].pltOffset); + } + } + */ + + if ( binaryElfRel == 0x0 ) { + binaryElfRel = (elfPltInfo *) malloc( binarySectionHeader[rel].shSize ); + fseek( binaryFd, binarySectionHeader[rel].shOffset, 0x0 ); + fread( binaryElfRel, binarySectionHeader[rel].shSize, 1, binaryFd ); + } + + i = ( entry / sizeof(elfPltInfo) ); + x = ELF32_R_SYM( binaryElfRel[i].pltInfo ); + reMap = (uInt32 *) binaryElfRel[i].pltOffset; + *reMap = ldFindFunc( binaryDynStr + binaryRelSymTab[x].dynName, binaryDynStr ); + printf( "\nld(%s)", binaryDynStr + binaryRelSymTab[x].dynName ); + //*reMap = ldFindFunc(binaryDynStr + binaryRelSymTab[x].dynName,(char *)(binaryDynStr + 1)); + + if ( binaryFd ) { + fclose( binaryFd ); + } + + return ( *reMap ); +} + +/*** + END + ***/ diff --git a/share/mk/sys.mk b/share/mk/sys.mk index 712fb44..50f37ce 100644 --- a/share/mk/sys.mk +++ b/share/mk/sys.mk @@ -77,7 +77,7 @@ __ALLSRC1= ${empty(DESTDIR):?${.ALLSRC}:${.ALLSRC:S|^${DESTDIR}|^destdir|}} __ALLSRC2= ${empty(MAKEOBJDIR):?${__ALLSRC1}:${__ALLSRC1:S|^${MAKEOBJDIR}|^obj|}} -__ALLSRC3= ${empty(UBIXBSDSRCDIR):?${__ALLSRC2}:${__ALLSRC2:S|^${UBIXBSDSRCDIR}|^src|}} +__ALLSRC3= ${empty(UBIXSRCDIR):?${__ALLSRC2}:${__ALLSRC2:S|^${UBIXSRCDIR}|^src|}} __BUILDSEED= ${BUILDSEED}/${__ALLSRC3:O}/${.TARGET} _CXXSEED?= ${BUILDSEED:D-frandom-seed=${__BUILDSEED:hash}} diff --git a/share/mk/ubix.cc-analyze.mk b/share/mk/ubix.cc-analyze.mk new file mode 100644 index 0000000..57496af --- /dev/null +++ b/share/mk/ubix.cc-analyze.mk @@ -0,0 +1,38 @@ +.ifndef CC_ANALYZE_SRCS + +CC_ANALYZE_FLAGS+= --analyze + +CC_ANALYZE_CHECKERS+= core deadcode security unix + +.for checker in ${CC_ANALYZE_CHECKERS} +CC_ANALYZE_FLAGS+= -Xanalyzer -analyzer-checker=${checker} +.endfor + +.SUFFIXES: .c .cc .cpp .cxx .C .cc-analyzer + +CC_ANALYZE_CFLAGS= ${CFLAGS:N-Wa,--fatal-warnings} +CC_ANALYZE_CXXFLAGS= ${CXXFLAGS:N-Wa,--fatal-warnings} + +.c.cc-analyzer: + ${TOOL_CC.cc} ${CC_ANALYZE_FLAGS} \ + ${CC_ANALYZE_CFLAGS} ${CPPFLAGS} \ + ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} \ + ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} +.cc.cc-analyzer .cpp.clang-analyzer .cxx.clang-analyzer .C.clang-analyzer: + ${TOOL_CXX.cc} ${CC_ANALYZE_FLAGS} \ + ${CC_ANALYZE_CXXFLAGS} ${CPPFLAGS} \ + ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} \ + ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} + +CC_ANALYZE_SRCS= \ + ${SRCS:M*.[cC]} ${SRCS:M*.cc} \ + ${SRCS:M*.cpp} ${SRCS:M*.cxx} \ + ${DPSRCS:M*.[cC]} ${DPSRCS:M*.cc} \ + ${DPSRCS:M*.cpp} ${DPSRCS:M*.cxx} +.if !empty(CC_ANALYZE_SRCS) +CC_ANALYZE_OUTPUT= ${CC_ANALYZE_SRCS:R:S,$,.cc-analyzer,} +.endif + +analyze: ${CC_ANALYZE_OUTPUT} + +.endif diff --git a/share/mk/ubix.clang-analyze.mk b/share/mk/ubix.clang-analyze.mk deleted file mode 100644 index fee5204..0000000 --- a/share/mk/ubix.clang-analyze.mk +++ /dev/null @@ -1,38 +0,0 @@ -.ifndef CLANG_ANALYZE_SRCS - -CLANG_ANALYZE_FLAGS+= --analyze - -CLANG_ANALYZE_CHECKERS+= core deadcode security unix - -.for checker in ${CLANG_ANALYZE_CHECKERS} -CLANG_ANALYZE_FLAGS+= -Xanalyzer -analyzer-checker=${checker} -.endfor - -.SUFFIXES: .c .cc .cpp .cxx .C .clang-analyzer - -CLANG_ANALYZE_CFLAGS= ${CFLAGS:N-Wa,--fatal-warnings} -CLANG_ANALYZE_CXXFLAGS= ${CXXFLAGS:N-Wa,--fatal-warnings} - -.c.clang-analyzer: - ${TOOL_CC.clang} ${CLANG_ANALYZE_FLAGS} \ - ${CLANG_ANALYZE_CFLAGS} ${CPPFLAGS} \ - ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} \ - ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -.cc.clang-analyzer .cpp.clang-analyzer .cxx.clang-analyzer .C.clang-analyzer: - ${TOOL_CXX.clang} ${CLANG_ANALYZE_FLAGS} \ - ${CLANG_ANALYZE_CXXFLAGS} ${CPPFLAGS} \ - ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} \ - ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} - -CLANG_ANALYZE_SRCS= \ - ${SRCS:M*.[cC]} ${SRCS:M*.cc} \ - ${SRCS:M*.cpp} ${SRCS:M*.cxx} \ - ${DPSRCS:M*.[cC]} ${DPSRCS:M*.cc} \ - ${DPSRCS:M*.cpp} ${DPSRCS:M*.cxx} -.if !empty(CLANG_ANALYZE_SRCS) -CLANG_ANALYZE_OUTPUT= ${CLANG_ANALYZE_SRCS:R:S,$,.clang-analyzer,} -.endif - -analyze: ${CLANG_ANALYZE_OUTPUT} - -.endif diff --git a/share/mk/ubix.host.mk b/share/mk/ubix.host.mk index f6cacb4..60c8427 100644 --- a/share/mk/ubix.host.mk +++ b/share/mk/ubix.host.mk @@ -1,18 +1,18 @@ .if !defined(_UBIX_HOST_MK_) _UBIX_HOST_MK_=1 -.if ${HOST_OSTYPE:C/\-.*//:U} == "Minix" +.if ${HOST_OSTYPE:C/\-.*//:U} == "Ubix" HOST_LDFLAGS?= -static #LSC: Be a bit smarter about the default compiler -.if exists(/usr/pkg/bin/clang) || exists(/usr/bin/clang) -HOST_CC?= clang +.if exists(/usr/pkg/bin/cc) || exists(/usr/bin/cc) +HOST_CC?= cc .endif .if exists(/usr/pkg/bin/gcc) || exists(/usr/bin/gcc) HOST_CC?= gcc .endif -.endif # ${HOST_OSTYPE:C/\-.*//:U} == "Minix" +.endif # ${HOST_OSTYPE:C/\-.*//:U} == "Ubix" # Helpers for cross-compiling HOST_CC?= cc diff --git a/share/mk/ubix.kernobj.mk b/share/mk/ubix.kernobj.mk index 42c4fee..21fddc6 100644 --- a/share/mk/ubix.kernobj.mk +++ b/share/mk/ubix.kernobj.mk @@ -1,7 +1,7 @@ # $UBIXBSD: bsd.kernobj.mk,v 1.14 2013/06/03 07:39:07 mrg Exp $ # KERNSRCDIR Is the location of the top of the kernel src. -# It defaults to `${UBIXBSDSRCDIR}/sys'. +# It defaults to `${UBIXSRCDIR}/sys'. # # KERNARCHDIR Is the location of the machine dependent kernel sources. # It defaults to `arch/${MACHINE}', but may be overridden @@ -23,7 +23,7 @@ .include -KERNSRCDIR?= ${UBIXBSDSRCDIR}/sys +KERNSRCDIR?= ${UBIXSRCDIR}/sys KERNARCHDIR?= arch/${MACHINE} KERNCONFDIRDEFAULT?= ${KERNSRCDIR}/${KERNARCHDIR}/conf KERNCONFDIR?= ${KERNCONFDIRDEFAULT} diff --git a/share/mk/ubix.lib.mk b/share/mk/ubix.lib.mk index d4945f6..eb9870e 100644 --- a/share/mk/ubix.lib.mk +++ b/share/mk/ubix.lib.mk @@ -1,11 +1,11 @@ -# $UBIXBSD: bsd.lib.mk,v 1.362 2015/09/08 16:06:42 uebayasi Exp $ -# @(#)bsd.lib.mk 8.3 (Berkeley) 4/22/94 +# $UBIXBSD: ubix.lib.mk,v 1.362 2015/09/08 16:06:42 uebayasi Exp $ +# @(#)ubix.lib.mk 8.3 (Berkeley) 4/22/94 -.include -.include -.include -# Pull in here so we can override its .c.o rule -.include +.include +.include +.include +# Pull in here so we can override its .c.o rule +.include LIBISMODULE?= no LIBISPRIVATE?= no @@ -75,11 +75,11 @@ # Check for higher installed library versions. .if !defined(NOCHECKVER) && !defined(NOCHECKVER_${LIB}) && \ - exists(${UBIXBSDSRCDIR}/lib/checkver) + exists(${UBIXSRCDIR}/lib/checkver) checkver: @(cd "${.CURDIR}" && \ HOST_SH=${HOST_SH:Q} AWK=${TOOL_AWK:Q} \ - ${HOST_SH} ${UBIXBSDSRCDIR}/lib/checkver -v ${SHLIB_VERSION_FILE} \ + ${HOST_SH} ${UBIXSRCDIR}/lib/checkver -v ${SHLIB_VERSION_FILE} \ -d ${_DEST.OBJ} ${LIB}) .endif .endif # } @@ -212,7 +212,7 @@ SHLIB_SHFLAGS+= -Wl,-plugin=${GOLD_PLUGIN} \ -Wl,-plugin-opt=-disable-opt -SECTIONIFYPASS?=${UBIXBSDSRCDIR}/minix/llvm/bin/sectionify.so +SECTIONIFYPASS?=${UBIXSRCDIR}/minix/llvm/bin/sectionify.so # dcvmoole: the following construction is a hack for libmagicrt. For reasons # not entirely under our control, clang refuses to take .bc objects even when # using the gold linker, saying that LLVM IR code cannot be linked. In order @@ -674,7 +674,7 @@ .if ${LIBISCXX} != "no" LIBCC:= ${CXX} . if ${MKLIBCXX} == "yes" -LIBDPLIBS+= c++ ${.CURDIR}/../../../../../external/bsd/libc++/lib +LIBDPLIBS+= c++ ${.CURDIR}/../../../../../external/ubix/libc++/lib . else LIBDPLIBS+= stdc++ ${.CURDIR}/../../../../../external/gpl3/${EXTERNAL_GCC_SUBDIR}/lib/libstdc++-v3 . endif @@ -745,12 +745,12 @@ # If the number of entries in CLEANFILES is too large, then the -# commands in bsd.clean.mk encounter errors like "exec(/bin/sh) +# commands in ubix.clean.mk encounter errors like "exec(/bin/sh) # failed (Argument list too long)". Avoid that by splitting the # files to clean into several lists using different variable names. -# __cleanuse is an internal target in bsd.clean.mk; the way we +# __cleanuse is an internal target in ubix.clean.mk; the way we # use it here mimics the way it's used by the clean target in -# bsd.clean.mk. +# ubix.clean.mk. # clean: libclean1 libclean2 libclean3 libclean4 libclean5 libclean1: .PHONY .MADE __cleanuse LIBCLEANFILES1 @@ -956,13 +956,13 @@ LINKSOWN?= ${LIBOWN} LINKSGRP?= ${LIBGRP} LINKSMODE?= ${LIBMODE} -.include -.include -.include -.include -.include -.include -.include -.include +.include +.include +.include +.include +.include +.include +.include +.include ${TARGETS}: # ensure existence diff --git a/share/mk/ubix.own.mk b/share/mk/ubix.own.mk index f0a9920..0a6fb0b 100644 --- a/share/mk/ubix.own.mk +++ b/share/mk/ubix.own.mk @@ -18,7 +18,7 @@ MKKYUA?= yes MKMCLINKER?= no -MKCLANGRT?= no +MKCCRT?= no MKGCC?= no MKGCCCMDS?= no MKPROFILE?= no @@ -156,7 +156,7 @@ .if ${MKLLVM:Uno} == "yes" HAVE_LLVM?= yes -MKBINUTILS?= yes # We are installing clang, so trigger binutils. +MKBINUTILS?= yes # We are installing cc, so trigger binutils. .endif # ${MKLLVM:Uno} == "yes" .if ${HAVE_LLVM:Dyes} == "yes" @@ -404,12 +404,12 @@ TOOL_FC.gcc= ${EXTERNAL_TOOLCHAIN}/bin/${MACHINE_GNU_PLATFORM}-g77 TOOL_OBJC.gcc= ${EXTERNAL_TOOLCHAIN}/bin/${MACHINE_GNU_PLATFORM}-gcc -TOOL_CC.clang= ${EXTERNAL_TOOLCHAIN}/bin/${MACHINE_GNU_PLATFORM}-clang -TOOL_CPP.clang= ${EXTERNAL_TOOLCHAIN}/bin/${MACHINE_GNU_PLATFORM}-clang-cpp -TOOL_CXX.clang= ${EXTERNAL_TOOLCHAIN}/bin/${MACHINE_GNU_PLATFORM}-clang++ -TOOL_OBJC.clang= ${EXTERNAL_TOOLCHAIN}/bin/${MACHINE_GNU_PLATFORM}-clang -TOOL_OPT.clang= ${EXTERNAL_TOOLCHAIN}/bin/opt -TOOL_LLC.clang= ${EXTERNAL_TOOLCHAIN}/bin/llc +TOOL_CC.cc= ${EXTERNAL_TOOLCHAIN}/bin/${MACHINE_GNU_PLATFORM}-cc +TOOL_CPP.cc= ${EXTERNAL_TOOLCHAIN}/bin/${MACHINE_GNU_PLATFORM}-cc-cpp +TOOL_CXX.cc= ${EXTERNAL_TOOLCHAIN}/bin/${MACHINE_GNU_PLATFORM}-cc++ +TOOL_OBJC.cc= ${EXTERNAL_TOOLCHAIN}/bin/${MACHINE_GNU_PLATFORM}-cc +TOOL_OPT.cc= ${EXTERNAL_TOOLCHAIN}/bin/opt +TOOL_LLC.cc= ${EXTERNAL_TOOLCHAIN}/bin/llc .else # } { # Define default locations for common tools. .if ${USETOOLS_BINUTILS:Uyes} == "yes" # { @@ -434,12 +434,12 @@ .endif # } # Clang supports C, C++ and Objective C -TOOL_CC.clang= ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-clang -TOOL_CPP.clang= ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-clang-cpp -TOOL_CXX.clang= ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-clang++ -TOOL_OBJC.clang= ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-clang -TOOL_OPT.clang= ${TOOLDIR}/bin/opt -TOOL_LLC.clang= ${TOOLDIR}/bin/llc +TOOL_CC.cc= ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-cc +TOOL_CPP.cc= ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-cc-cpp +TOOL_CXX.cc= ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-cc++ +TOOL_OBJC.cc= ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-cc +TOOL_OPT.cc= ${TOOLDIR}/bin/opt +TOOL_LLC.cc= ${TOOLDIR}/bin/llc # PCC supports C and Fortran TOOL_CC.pcc= ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-pcc @@ -485,7 +485,7 @@ TOOL_CAP_MKDB= ${TOOLDIR}/bin/${_TOOL_PREFIX}cap_mkdb TOOL_CAT= ${TOOLDIR}/bin/${_TOOL_PREFIX}cat TOOL_CKSUM= ${TOOLDIR}/bin/${_TOOL_PREFIX}cksum -TOOL_CLANG_TBLGEN= ${TOOLDIR}/bin/${_TOOL_PREFIX}clang-tblgen +TOOL_CC_TBLGEN= ${TOOLDIR}/bin/${_TOOL_PREFIX}cc-tblgen TOOL_COMPILE_ET= ${TOOLDIR}/bin/${_TOOL_PREFIX}compile_et TOOL_CONFIG= ${TOOLDIR}/bin/${_TOOL_PREFIX}config TOOL_CRUNCHGEN= MAKE=${.MAKE:Q} ${TOOLDIR}/bin/${_TOOL_PREFIX}crunchgen @@ -570,16 +570,16 @@ .else # USETOOLS != yes # } { # Clang supports C, C++ and Objective C -TOOL_CC.clang= clang +TOOL_CC.cc= cc .if defined(__UBIX) -TOOL_CPP.clang= clang -E +TOOL_CPP.cc= cc -E .else -TOOL_CPP.clang= clang-cpp +TOOL_CPP.cc= cc-cpp .endif # defined(__UBIX) -TOOL_CXX.clang= clang++ -TOOL_OBJC.clang= clang -TOOL_OPT.clang= opt -TOOL_LLC.clang= llc +TOOL_CXX.cc= cc++ +TOOL_OBJC.cc= cc +TOOL_OPT.cc= opt +TOOL_LLC.cc= llc # GCC supports C, C++, Fortran and Objective C TOOL_CC.gcc= gcc @@ -604,13 +604,13 @@ .if defined(__UBIX) # LSC: A full path has to be provided, as this is also used as a make # target. -. if exists(/usr/pkg/bin/clang-tblgen) -TOOL_CLANG_TBLGEN= /usr/pkg/bin/clang-tblgen +. if exists(/usr/pkg/bin/cc-tblgen) +TOOL_CC_TBLGEN= /usr/pkg/bin/cc-tblgen . else -TOOL_CLANG_TBLGEN= /usr/bin/clang-tblgen -. endif # exists(/usr/pkg/bin/clang-tblgen) +TOOL_CC_TBLGEN= /usr/bin/cc-tblgen +. endif # exists(/usr/pkg/bin/cc-tblgen) .else -TOOL_CLANG_TBLGEN= clang-tblgen +TOOL_CC_TBLGEN= cc-tblgen .endif # defined(__UBIX) TOOL_COMPILE_ET= compile_et TOOL_CONFIG= config @@ -735,7 +735,7 @@ TOOL_OPT.false= false TOOL_LLC.false= false -AVAILABLE_COMPILER?= ${HAVE_PCC:Dpcc} ${HAVE_LLVM:Dclang} ${HAVE_GCC:Dgcc} ${EXTERNAL_TOOLCHAIN:Dgcc} false +AVAILABLE_COMPILER?= ${HAVE_PCC:Dpcc} ${HAVE_LLVM:Dcc} ${HAVE_GCC:Dgcc} ${EXTERNAL_TOOLCHAIN:Dgcc} false .for _t in CC CPP CXX FC OBJC OPT LLC ACTIVE_${_t}= ${AVAILABLE_COMPILER:@.c.@ ${ !defined(UNSUPPORTED_COMPILER.${.c.}) && defined(TOOL_${_t}.${.c.}) :? ${.c.} : }@:[1]} @@ -1093,10 +1093,10 @@ # Flags to pass to CC for using the old APCS ABI on ARM for compat or stand. ARM_APCS_FLAGS= -mabi=apcs-gnu -mfloat-abi=soft ARM_APCS_FLAGS+=${${ACTIVE_CC} == "gcc":? -marm :} -ARM_APCS_FLAGS+=${${ACTIVE_CC} == "clang":? -target ${MACHINE_GNU_ARCH}--netubixelf -B ${TOOLDIR}/${MACHINE_GNU_PLATFORM}/bin :} +ARM_APCS_FLAGS+=${${ACTIVE_CC} == "cc":? -target ${MACHINE_GNU_ARCH}--netubixelf -B ${TOOLDIR}/${MACHINE_GNU_PLATFORM}/bin :} .endif -GENASSYM_CPPFLAGS+= ${${ACTIVE_CC} == "clang":? -no-integrated-as :} +GENASSYM_CPPFLAGS+= ${${ACTIVE_CC} == "cc":? -no-integrated-as :} TARGETS+= all clean cleandir depend dependall includes \ install lint obj regress tags html analyze diff --git a/share/mk/ubix.prog.mk b/share/mk/ubix.prog.mk index e1f51e4..f5006b6 100644 --- a/share/mk/ubix.prog.mk +++ b/share/mk/ubix.prog.mk @@ -327,13 +327,13 @@ .endif _PROGLDOPTS= -.if ${SHLINKDIR} != "/usr/libexec" # XXX: change or remove if ld.so moves +.if ${SHLINKDIR} != "/ubixos/usr/libexec" # XXX: change or remove if ld.so moves _PROGLDOPTS+= -Wl,-dynamic-linker=${_SHLINKER} .endif -.if ${SHLIBDIR} != "/usr/lib" +.if ${SHLIBDIR} != "/ubixos/usr/lib" _PROGLDOPTS+= -Wl,-rpath,${SHLIBDIR} \ -L=${SHLIBDIR} -.elif ${SHLIBINSTALLDIR} != "/usr/lib" +.elif ${SHLIBINSTALLDIR} != "/ubixos/usr/lib" _PROGLDOPTS+= -Wl,-rpath-link,${DESTDIR}${SHLIBINSTALLDIR} \ -L=${SHLIBINSTALLDIR} .endif @@ -778,7 +778,7 @@ .include .include .include -.include +.include .include ${TARGETS}: # ensure existence diff --git a/share/mk/ubix.shlib.mk b/share/mk/ubix.shlib.mk index 4ffdd87..3033b54 100644 --- a/share/mk/ubix.shlib.mk +++ b/share/mk/ubix.shlib.mk @@ -4,17 +4,17 @@ _UBIX_SHLIB_MK_=1 .if ${MKDYNAMICROOT} == "no" -SHLIBINSTALLDIR?= /usr/lib +SHLIBINSTALLDIR?= /ubixos/usr/lib .else -SHLIBINSTALLDIR?= /lib +SHLIBINSTALLDIR?= /ubixos/lib .endif .if ${MKDYNAMICROOT} == "no" || \ (${BINDIR:Ux} != "/bin" && ${BINDIR:Ux} != "/sbin" && \ ${BINDIR:Ux} != "/libexec" && ${USE_SHLIBDIR:Uno} == "no") -SHLIBDIR?= /usr/lib +SHLIBDIR?= /ubixos/usr/lib .else -SHLIBDIR?= /lib +SHLIBDIR?= /ubixos/lib .endif .if ${USE_SHLIBDIR:Uno} != "no" @@ -24,17 +24,17 @@ .endif .if ${MKDYNAMICROOT} == "no" -SHLINKINSTALLDIR?= /usr/libexec +SHLINKINSTALLDIR?= /ubixos/usr/libexec .else -SHLINKINSTALLDIR?= /libexec +SHLINKINSTALLDIR?= /ubixos/libexec .endif .if ${MKDYNAMICROOT} == "no" || \ (${BINDIR:Ux} != "/bin" && ${BINDIR:Ux} != "/sbin" && \ ${BINDIR:Ux} != "/libexec") -SHLINKDIR?= /usr/libexec +SHLINKDIR?= /ubixos/usr/libexec .else -SHLINKDIR?= /libexec +SHLINKDIR?= /ubixos/libexec .endif .endif # !defined(_UBIX_SHLIB_MK_) diff --git a/share/mk/ubix.sys.mk b/share/mk/ubix.sys.mk index f8985d4..5e335c8 100644 --- a/share/mk/ubix.sys.mk +++ b/share/mk/ubix.sys.mk @@ -25,18 +25,18 @@ .endif # defined(__UBIX) .if ${MKREPRO:Uno} == "yes" -CPPFLAGS+= -Wp,-iremap,${UBIXBSDSRCDIR}:/usr/src +CPPFLAGS+= -Wp,-iremap,${UBIXSRCDIR}:/usr/src CPPFLAGS+= -Wp,-iremap,${DESTDIR}/:/ CPPFLAGS+= -Wp,-iremap,${X11SRCDIR}:/usr/xsrc .endif # UBIXBSD sources use C99 style, with some GCC extensions. -CFLAGS+= ${${ACTIVE_CC} == "clang":? -std=gnu99 :} +CFLAGS+= ${${ACTIVE_CC} == "cc":? -std=gnu99 :} CFLAGS+= ${${ACTIVE_CC} == "gcc":? -std=gnu99 :} CFLAGS+= ${${ACTIVE_CC} == "pcc":? -std=gnu99 :} .if defined(WARNS) -CFLAGS+= ${${ACTIVE_CC} == "clang":? -Wno-sign-compare -Wno-pointer-sign :} +CFLAGS+= ${${ACTIVE_CC} == "cc":? -Wno-sign-compare -Wno-pointer-sign :} .if ${WARNS} > 0 CFLAGS+= -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith #CFLAGS+= -Wmissing-declarations -Wredundant-decls -Wnested-externs @@ -69,7 +69,7 @@ .if ${WARNS} > 2 CFLAGS+= -Wcast-qual -Wwrite-strings CFLAGS+= -Wextra -Wno-unused-parameter -# Readd -Wno-sign-compare to override -Wextra with clang +# Readd -Wno-sign-compare to override -Wextra with cc CFLAGS+= -Wno-sign-compare CXXFLAGS+= -Wabi CXXFLAGS+= -Wold-style-cast @@ -88,7 +88,7 @@ CFLAGS+= ${${ACTIVE_CC} == "gcc":? -Wno-format-zero-length :} .endif .if ${WARNS} > 3 && defined(HAVE_LLVM) -CFLAGS+= ${${ACTIVE_CC} == "clang":? -Wpointer-sign -Wmissing-noreturn :} +CFLAGS+= ${${ACTIVE_CC} == "cc":? -Wpointer-sign -Wmissing-noreturn :} .endif .if (defined(HAVE_GCC) \ && (${MACHINE_ARCH} == "coldfire" || \ @@ -108,7 +108,7 @@ CWARNFLAGS+= ${CWARNFLAGS.${ACTIVE_CC}} CPPFLAGS+= ${AUDIT:D-D__AUDIT__} -_NOWERROR= ${defined(NOGCCERROR) || (${ACTIVE_CC} == "clang" && defined(NOCLANGERROR)):?yes:no} +_NOWERROR= ${defined(NOGCCERROR) || (${ACTIVE_CC} == "cc" && defined(NOCLANGERROR)):?yes:no} .if defined(__UBIX) && ${USE_BITCODE:Uno} == "yes" _NOWERROR= yes .endif # defined(__UBIX) && ${USE_BITCODE} == "yes" @@ -134,7 +134,7 @@ COPTS+= -Wno-error=stack-protector .endif -COPTS+= ${${ACTIVE_CC} == "clang":? --param ssp-buffer-size=1 :} +COPTS+= ${${ACTIVE_CC} == "cc":? --param ssp-buffer-size=1 :} COPTS+= ${${ACTIVE_CC} == "gcc":? --param ssp-buffer-size=1 :} .endif diff --git a/src/build/bin/.gitignore b/src/build/bin/.gitignore deleted file mode 100644 index d6b7ef3..0000000 --- a/src/build/bin/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore diff --git a/src/build/lib/.gitignore b/src/build/lib/.gitignore deleted file mode 100644 index d6b7ef3..0000000 --- a/src/build/lib/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore diff --git a/src/build/libexec/.gitignore b/src/build/libexec/.gitignore deleted file mode 100644 index d6b7ef3..0000000 --- a/src/build/libexec/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore