1#!/bin/sh 2# 3# Copyright (c) 2005 Poul-Henning Kamp. 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# 15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25# SUCH DAMAGE. 26# 27# $FreeBSD$ 28# 29 30set -e 31 32nanobsd_sh=`realpath $0` 33topdir=`dirname ${nanobsd_sh}` 34. "${topdir}/defaults.sh" 35 36####################################################################### 37# Parse arguments 38 39do_clean=true 40do_kernel=true 41do_installkernel=true 42do_world=true 43do_installworld=true 44do_image=true 45do_copyout_partition=true 46do_native_xtools=false 47 48# Pull in legacy stuff for now automatically 49. "${topdir}/legacy.sh" 50 51set +e 52args=`getopt BKXWbc:fhiknqvw $*` 53if [ $? -ne 0 ] ; then 54 usage 55 exit 2 56fi 57set -e 58 59set -- $args 60for i 61do 62 case "$i" 63 in 64 -B) 65 do_installworld=false 66 do_installkernel=false 67 shift 68 ;; 69 -K) 70 do_installkernel=false 71 shift 72 ;; 73 -X) 74 do_native_xtools=true 75 shift 76 ;; 77 -W) 78 do_installworld=false 79 shift 80 ;; 81 -b) 82 do_world=false 83 do_kernel=false 84 shift 85 ;; 86 -c) 87 # Make config file path available to the config file 88 # itself so that it can access additional files relative 89 # to its own location. 90 NANO_CONFIG=$2 91 . "$2" 92 shift 93 shift 94 ;; 95 -f) 96 do_copyout_partition=false 97 shift 98 ;; 99 -h) 100 usage 101 ;; 102 -i) 103 do_image=false 104 shift 105 ;; 106 -k) 107 do_kernel=false 108 shift 109 ;; 110 -n) 111 do_clean=false 112 shift 113 ;; 114 -q) 115 PPLEVEL=$(($PPLEVEL - 1)) 116 shift 117 ;; 118 -v) 119 PPLEVEL=$(($PPLEVEL + 1)) 120 shift 121 ;; 122 -w) 123 do_world=false 124 shift 125 ;; 126 --) 127 shift 128 break 129 esac 130done 131 132if [ $# -gt 0 ] ; then 133 echo "$0: Extraneous arguments supplied" 134 usage 135fi 136 137####################################################################### 138# And then it is as simple as that... 139 140# File descriptor 3 is used for logging output, see pprint 141exec 3>&1 142set_defaults_and_export 143 144if [ ! -d "${NANO_TOOLS}" ]; then 145 echo "NANO_TOOLS directory does not exist" 1>&2 146 exit 1 147fi 148 149if ! $do_clean; then 150 NANO_PMAKE="${NANO_PMAKE} -DNO_CLEAN" 151fi 152 153pprint 1 "NanoBSD image ${NANO_NAME} build starting" 154 155run_early_customize 156 157if $do_world ; then 158 if $do_clean ; then 159 clean_build 160 else 161 pprint 2 "Using existing build tree (as instructed)" 162 fi 163 make_conf_build 164 build_world 165else 166 pprint 2 "Skipping buildworld (as instructed)" 167fi 168 169if $do_kernel ; then 170 if ! $do_world ; then 171 make_conf_build 172 fi 173 build_kernel 174else 175 pprint 2 "Skipping buildkernel (as instructed)" 176fi 177 178if $do_installworld ; then 179 clean_world 180 make_conf_install 181 install_world 182 install_etc 183else 184 pprint 2 "Skipping installworld (as instructed)" 185fi 186 187if $do_native_xtools ; then 188 native_xtools 189fi 190setup_nanobsd_etc 191if $do_installkernel ; then 192 install_kernel 193else 194 pprint 2 "Skipping installkernel (as instructed)" 195fi 196 197run_customize 198setup_nanobsd 199prune_usr 200run_late_customize 201fixup_before_diskimage 202if $do_image ; then 203 create_diskimage 204else 205 pprint 2 "Skipping image build (as instructed)" 206fi 207last_orders 208 209pprint 1 "NanoBSD image ${NANO_NAME} completed" 210