]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/tools/nanobsd/nanobsd.sh
Merge llvm-project main llvmorg-18-init-16864-g3b3ee1f53424
[FreeBSD/FreeBSD.git] / tools / tools / nanobsd / nanobsd.sh
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 #
28
29 set -e
30
31 nanobsd_sh=`realpath $0`
32 topdir=`dirname ${nanobsd_sh}`
33 . "${topdir}/defaults.sh"
34
35 #######################################################################
36 # Parse arguments
37
38 do_clean=true
39 do_kernel=true
40 do_installkernel=true
41 do_world=true
42 do_code=true
43 do_installworld=true
44 do_image=true
45 do_native_xtools=false
46 do_prep_image=true
47
48 # Pull in legacy stuff for now automatically
49 . "${topdir}/legacy.sh"
50
51 set +e
52 args=`getopt BKXWbc:fhiIknqvw $*`
53 if [ $? -ne 0 ] ; then
54         usage
55         exit 2
56 fi
57 set -e
58
59 set -- $args
60 for i
61 do
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_code=false
97                 do_image=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
140 done
141
142 if [ $# -gt 0 ] ; then
143         echo "$0: Extraneous arguments supplied"
144         usage
145 fi
146
147 #######################################################################
148 # And then it is as simple as that...
149
150 # File descriptor 3 is used for logging output, see pprint
151 exec 3>&1
152 set_defaults_and_export
153
154 if [ ! -d "${NANO_TOOLS}" ]; then
155         echo "NANO_TOOLS directory does not exist" 1>&2
156         exit 1
157 fi
158
159 if ! $do_clean; then
160         NANO_PMAKE="${NANO_PMAKE} -DNO_CLEAN"
161 fi
162
163 pprint 1 "NanoBSD image ${NANO_NAME} build starting"
164
165 run_early_customize
166
167 if $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
175 else
176         pprint 2 "Skipping buildworld (as instructed)"
177 fi
178
179 if $do_kernel ; then
180         if ! $do_world ; then
181                 make_conf_build
182         fi
183         build_kernel
184 else
185         pprint 2 "Skipping buildkernel (as instructed)"
186 fi
187
188 if $do_installworld ; then
189     clean_world
190     make_conf_install
191     install_world
192     install_etc
193 else
194     pprint 2 "Skipping installworld (as instructed)"
195 fi
196
197 if ${do_native_xtools} ; then
198         native_xtools
199 fi
200 if ${do_prep_image} ; then
201         setup_nanobsd_etc
202 fi
203 if $do_installkernel ; then
204         install_kernel
205 else
206         pprint 2 "Skipping installkernel (as instructed)"
207 fi
208
209 if $do_prep_image ; then
210         run_customize
211         setup_nanobsd
212         prune_usr
213         run_late_customize
214         fixup_before_diskimage
215 else
216         pprint 2 "Skipping image prep (as instructed)"
217 fi
218 if $do_code ; then
219         calculate_partitioning
220         create_code_slice
221         if $do_image ; then
222                 create_diskimage
223         else
224                 pprint 2 "Skipping image build (as instructed)"
225         fi
226 else
227         pprint 2 "Skipping code and image build (as instructed)"
228 fi
229 last_orders
230
231 pprint 1 "NanoBSD image ${NANO_NAME} completed"