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