Menu

[r9812]: / trunk / build / do_build.sh  Maximize  Restore  History

Download this file

195 lines (176 with data), 5.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/bin/sh
#
# See README for up to date usage examples.
#
cd "$(dirname "$0")/.."
. build/nano_env
. build/functions.sh
# Should we build?
BUILD=true
# 0 - build only what's required (src, ports, diskimage, etc).
# 1 - force src build.
# 2 - nuke obj.* and build from scratch.
if [ -s ${NANO_OBJ}/_.ik -a -s ${NANO_OBJ}/_.iw ]; then
FORCE_BUILD=0
else
FORCE_BUILD=2
fi
# Number of jobs to pass to make. Only applies to src so far.
MAKE_JOBS=$(( 2 * $(sysctl -n kern.smp.cpus) + 1 ))
# Should we update src + ports?
if [ -f $AVATAR_ROOT/FreeBSD/.pulled ]; then
UPDATE=false
else
UPDATE=true
fi
usage() {
cat <<EOF
usage: ${0##*/} [-Bfu] [-j make-jobs] [-- nanobsd-options]
-B - don't build. Will pull the sources and show you the nanobsd.sh invocation
string instead.
-f - if not specified, will pass either -b (if prebuilt) to nanobsd.sh, or
nothing if not prebuilt. If specified once, force a
buildworld / buildkernel (passes -n to nanobsd). If specified twice, this
won't pass any options to nanobsd.sh, which will force a pristine build.
-j - number of make jobs to run; defaults to $MAKE_JOBS.
-u - force an update via csup (warning: there are potential issues with
newly created files via patch -- use with caution).
EOF
exit 1
}
while getopts 'Bfj:u' optch; do
case "$optch" in
B)
BUILD=false
;;
f)
: $(( FORCE_BUILD += 1 ))
;;
j)
echo $OPTARG | egrep -q '^[[:digit:]]+$' && [ $OPTARG -le 0 ]
if [ $? -ne 0 ]; then
usage
fi
MAKE_JOBS=$OPTARG
;;
u)
UPDATE=true
;;
\?)
usage
;;
esac
done
shift $(( $OPTIND - 1 ))
case "$-" in
*x*)
trace="-x"
;;
*)
trace=
;;
esac
set -e
if $BUILD; then
requires_root
fi
if $UPDATE; then
if [ -z "$FREEBSD_CVSUP_HOST" ]; then
error "No sup host defined, please define FREEBSD_CVSUP_HOST and rerun"
fi
mkdir -p $AVATAR_ROOT/FreeBSD
: ${FREEBSD_SRC_REPOSITORY_ROOT=http://svn.freebsd.org/base}
FREEBSD_SRC_URL_REL="releng/8.2"
FREEBSD_SRC_URL_FULL="$FREEBSD_SRC_REPOSITORY_ROOT/$FREEBSD_SRC_URL_REL"
(
cd "$AVATAR_ROOT/FreeBSD"
if [ -d src/.svn ]; then
svn switch $FREEBSD_SRC_URL_FULL src
svn upgrade src >/dev/null 2>&1 || :
svn resolved src
else
svn co $FREEBSD_SRC_URL_FULL src
fi
# Always do this so the csup pulled files are paved over.
svn revert -R src
svn up src
)
SUPFILE=$AVATAR_ROOT/FreeBSD/supfile
cat <<EOF > $SUPFILE
*default host=${FREEBSD_CVSUP_HOST}
*default base=$AVATAR_ROOT/FreeBSD/sup
*default prefix=$AVATAR_ROOT/FreeBSD
*default release=cvs
*default delete use-rel-suffix
*default compress
ports-all date=2011.12.28.00.00.00
EOF
# Nuke newly created files to avoid build errors.
svn_status_ok="$AVATAR_ROOT/FreeBSD/.svn_status_ok"
rm -f "$svn_status_ok"
(
svn status $AVATAR_ROOT/FreeBSD/src
: > "$svn_status_ok"
) | \
awk '$1 == "?" { print $2 }' | \
xargs rm -Rf
[ -f "$svn_status_ok" ]
for file in $(find $AVATAR_ROOT/FreeBSD/ports -name '*.orig' -size 0); do
rm -f "$(echo $file | sed -e 's/.orig$//')"
done
echo "Checking out ports tree from ${FREEBSD_CVSUP_HOST}..."
csup -L 1 $SUPFILE
# Force a repatch.
: > $AVATAR_ROOT/FreeBSD/src-patches
: > $AVATAR_ROOT/FreeBSD/ports-patches
: > $AVATAR_ROOT/FreeBSD/.pulled
fi
_lp=last-patch.$$.log
for patch in $(cd $AVATAR_ROOT/patches && ls freebsd-*.patch); do
if ! grep -q $patch $AVATAR_ROOT/FreeBSD/src-patches; then
echo "Applying patch $patch..."
(cd FreeBSD/src &&
patch -C -f -p0 < $AVATAR_ROOT/patches/$patch >$_lp 2>&1 ||
{ echo "Failed to apply patch: $patch (check $(pwd)/$_lp)";
exit 1; } &&
patch -E -p0 -s < $AVATAR_ROOT/patches/$patch)
echo $patch >> $AVATAR_ROOT/FreeBSD/src-patches
fi
done
for patch in $(cd $AVATAR_ROOT/patches && ls ports-*.patch); do
if ! grep -q $patch $AVATAR_ROOT/FreeBSD/ports-patches; then
echo "Applying patch $patch..."
(cd FreeBSD/ports &&
patch -C -f -p0 < $AVATAR_ROOT/patches/$patch >$_lp 2>&1 ||
{ echo "Failed to apply patch: $patch (check $(pwd)/$_lp)";
exit 1; } &&
patch -E -p0 -s < $AVATAR_ROOT/patches/$patch)
echo $patch >> $AVATAR_ROOT/FreeBSD/ports-patches
fi
done
# HACK: chmod +x the script because:
# 1. It's not in FreeBSD proper, so it will always be touched.
# 2. The mode is 0644 by default, and using a pattern like ${SHELL}
# in the Makefile snippet won't work with csh users because the
# script uses /bin/sh constructs.
if [ -f "$NANO_SRC/include/mk-osreldate.sh.orig" ]; then
chmod +x $NANO_SRC/include/mk-osreldate.sh
fi
# OK, now we can build
cd $NANO_SRC
args="-c ${NANO_CFG_BASE}/freenas-common"
if [ $FORCE_BUILD -eq 0 ]; then
extra_args="$extra_args -b"
elif [ $FORCE_BUILD -eq 1 ]; then
extra_args="$extra_args -n"
fi
cmd="$AVATAR_ROOT/build/nanobsd/nanobsd.sh $args $* $extra_args -j $MAKE_JOBS"
echo $cmd
if ! $BUILD; then
exit 0
fi
if sh $trace $cmd; then
echo "$NANO_LABEL build PASSED"
else
error "$NANO_LABEL build FAILED; please check above log for more details"
fi
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.