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 47do_prep_image=true 48 49# Pull in legacy stuff for now automatically 50. "${topdir}/legacy.sh" 51 52set +e 53args=`getopt BKXWbc:fhiIknqvw $*` 54if [ $? -ne 0 ] ; then 55 usage 56 exit 2 57fi 58set -e 59 60set -- $args 61for i 62do 63 case "$i" 64 in 65 -B) 66 do_installworld=false 67 do_installkernel=false 68 shift 69 ;; 70 -K) 71 do_installkernel=false 72 shift 73 ;; 74 -X) 75 do_native_xtools=true 76 shift 77 ;; 78 -W) 79 do_installworld=false 80 shift 81 ;; 82 -b) 83 do_world=false 84 do_kernel=false 85 shift 86 ;; 87 -c) 88 # Make config file path available to the config file 89 # itself so that it can access additional files relative 90 # to its own location. 91 NANO_CONFIG=$2 92 . "$2" 93 shift 94 shift 95 ;; 96 -f) 97 do_copyout_partition=false 98 shift 99 ;; 100 -h) 101 usage 102 ;; 103 -i) 104 do_image=false 105 shift 106 ;; 107 -k) 108 do_kernel=false 109 shift 110 ;; 111 -n) 112 do_clean=false 113 shift 114 ;; 115 -q) 116 PPLEVEL=$(($PPLEVEL - 1)) 117 shift 118 ;; 119 -v) 120 PPLEVEL=$(($PPLEVEL + 1)) 121 shift 122 ;; 123 -w) 124 do_world=false 125 shift 126 ;; 127 -I) 128 do_world=false 129 do_kernel=false 130 do_installworld=false 131 do_installkernel=false 132 do_prep_image=false 133 do_image=true 134 shift 135 ;; 136 --) 137 shift 138 break 139 esac 140done 141 142if [ $# -gt 0 ] ; then 143 echo "$0: Extraneous arguments supplied" 144 usage 145fi 146 147####################################################################### 148# And then it is as simple as that... 149 150# File descriptor 3 is used for logging output, see pprint 151exec 3>&1 152set_defaults_and_export 153 154if [ ! -d "${NANO_TOOLS}" ]; then 155 echo "NANO_TOOLS directory does not exist" 1>&2 156 exit 1 157fi 158 159if ! $do_clean; then 160 NANO_PMAKE="${NANO_PMAKE} -DNO_CLEAN" 161fi 162 163pprint 1 "NanoBSD image ${NANO_NAME} build starting" 164 165run_early_customize 166 167if $do_world ; then 168 if $do_clean ; then 169 clean_build 170 else 171 pprint 2 "Using existing build tree (as instructed)" 172 fi 173 make_conf_build 174 build_world 175else 176 pprint 2 "Skipping buildworld (as instructed)" 177fi 178 179if $do_kernel ; then 180 if ! $do_world ; then 181 make_conf_build 182 fi 183 build_kernel 184else 185 pprint 2 "Skipping buildkernel (as instructed)" 186fi 187 188if $do_installworld ; then 189 clean_world 190 make_conf_install 191 install_world 192 install_etc 193else 194 pprint 2 "Skipping installworld (as instructed)" 195fi 196 197if ${do_native_xtools} ; then 198 native_xtools 199fi 200if ${do_prep_image} ; then 201 setup_nanobsd_etc 202fi 203if $do_installkernel ; then 204 install_kernel 205else 206 pprint 2 "Skipping installkernel (as instructed)" 207fi 208 209if $do_prep_image ; then 210 run_customize 211 setup_nanobsd 212 prune_usr 213 run_late_customize 214 fixup_before_diskimage 215else 216 pprint 2 "Skipping image prep (as instructed)" 217fi 218if $do_image ; then 219 create_diskimage 220else 221 pprint 2 "Skipping image build (as instructed)" 222fi 223last_orders 224 225pprint 1 "NanoBSD image ${NANO_NAME} completed" 226