]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/tools/nanobsd/nanobsd.sh
Merge llvm trunk r300422 and resolve conflicts.
[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 # $FreeBSD$
28 #
29
30 set -e
31
32 nanobsd_sh=`realpath $0`
33 topdir=`dirname ${nanobsd_sh}`
34 . "${topdir}/defaults.sh"
35
36 #######################################################################
37 # Parse arguments
38
39 do_clean=true
40 do_kernel=true
41 do_installkernel=true
42 do_world=true
43 do_installworld=true
44 do_image=true
45 do_copyout_partition=true
46 do_native_xtools=false
47
48 # Pull in legacy stuff for now automatically
49 . "${topdir}/legacy.sh"
50
51 set +e
52 args=`getopt BKXWbc:fhiknqvw $*`
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_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
130 done
131
132 if [ $# -gt 0 ] ; then
133         echo "$0: Extraneous arguments supplied"
134         usage
135 fi
136
137 #######################################################################
138 # And then it is as simple as that...
139
140 # File descriptor 3 is used for logging output, see pprint
141 exec 3>&1
142 set_defaults_and_export
143
144 if [ ! -d "${NANO_TOOLS}" ]; then
145         echo "NANO_TOOLS directory does not exist" 1>&2
146         exit 1
147 fi
148
149 if ! $do_clean; then
150         NANO_PMAKE="${NANO_PMAKE} -DNO_CLEAN"
151 fi
152
153 pprint 1 "NanoBSD image ${NANO_NAME} build starting"
154
155 run_early_customize
156
157 if $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
165 else
166         pprint 2 "Skipping buildworld (as instructed)"
167 fi
168
169 if $do_kernel ; then
170         if ! $do_world ; then
171                 make_conf_build
172         fi
173         build_kernel
174 else
175         pprint 2 "Skipping buildkernel (as instructed)"
176 fi
177
178 if $do_installworld ; then
179     clean_world
180     make_conf_install
181     install_world
182     install_etc
183 else
184     pprint 2 "Skipping installworld (as instructed)"
185 fi
186
187 if $do_native_xtools ; then
188         native_xtools
189 fi
190 setup_nanobsd_etc
191 if $do_installkernel ; then
192         install_kernel
193 else
194         pprint 2 "Skipping installkernel (as instructed)"
195 fi
196
197 run_customize
198 setup_nanobsd
199 prune_usr
200 run_late_customize
201 fixup_before_diskimage
202 if $do_image ; then
203         create_diskimage
204 else
205         pprint 2 "Skipping image build (as instructed)"
206 fi
207 last_orders
208
209 pprint 1 "NanoBSD image ${NANO_NAME} completed"