1
|
#!/bin/sh
|
2
|
#
|
3
|
# build_freebsd.sh
|
4
|
#
|
5
|
# part of pfSense (https://www.pfsense.org)
|
6
|
# Copyright (c) 2004-2013 BSD Perimeter
|
7
|
# Copyright (c) 2013-2016 Electric Sheep Fencing
|
8
|
# Copyright (c) 2014-2024 Rubicon Communications, LLC (Netgate)
|
9
|
# All rights reserved.
|
10
|
#
|
11
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
12
|
# you may not use this file except in compliance with the License.
|
13
|
# You may obtain a copy of the License at
|
14
|
#
|
15
|
# http://www.apache.org/licenses/LICENSE-2.0
|
16
|
#
|
17
|
# Unless required by applicable law or agreed to in writing, software
|
18
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
19
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
20
|
# See the License for the specific language governing permissions and
|
21
|
# limitations under the License.
|
22
|
|
23
|
export PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin
|
24
|
|
25
|
scripts_path=$(dirname $(realpath $0))
|
26
|
|
27
|
if [ ! -f "${scripts_path}/common.subr" ]; then
|
28
|
echo >&2 "ERROR: common.subr is missing"
|
29
|
exit 1
|
30
|
fi
|
31
|
|
32
|
. ${scripts_path}/common.subr
|
33
|
|
34
|
usage() {
|
35
|
cat >&2 <<END
|
36
|
Usage: $(basename $0) -s srcdir [-o objdir] [-h]
|
37
|
|
38
|
Options:
|
39
|
-s srcdir -- Path to src directory
|
40
|
-o objdir -- Obj directory used to build
|
41
|
-W -- Skip buildworld
|
42
|
-K -- Skip buildkernel
|
43
|
-h -- Show this help and exit
|
44
|
|
45
|
Environment:
|
46
|
__MAKE_CONF -- Path to make.conf
|
47
|
SRCCONF -- Path to src.conf
|
48
|
SRC_ENV_CONF -- Path to src-env.conf
|
49
|
KERNCONF -- Kernel names
|
50
|
MODULES_OVERRIDE -- List of kernel modules to build
|
51
|
TARGET -- Machine hardware name
|
52
|
TARGET_ARCH -- Machine processor architecture name
|
53
|
END
|
54
|
exit 1
|
55
|
}
|
56
|
|
57
|
unset skip_world
|
58
|
unset skip_kernel
|
59
|
while getopts s:o:WKh opt; do
|
60
|
case "$opt" in
|
61
|
s)
|
62
|
srcdir=$OPTARG
|
63
|
;;
|
64
|
o)
|
65
|
objdir=$OPTARG
|
66
|
;;
|
67
|
W)
|
68
|
skip_world=1
|
69
|
;;
|
70
|
K)
|
71
|
skip_kernel=1
|
72
|
;;
|
73
|
*)
|
74
|
usage
|
75
|
;;
|
76
|
esac
|
77
|
done
|
78
|
|
79
|
[ -z "$srcdir" ] \
|
80
|
&& err "source directory is not defined"
|
81
|
|
82
|
[ -e $srcdir -a ! -d $srcdir ] \
|
83
|
&& err "source path already exists and is not a directory"
|
84
|
|
85
|
# Default obj dir to src/../obj
|
86
|
: ${objdir=${srcdir}/../obj}
|
87
|
|
88
|
[ -n "$objdir" -a -e "$objdir" -a ! -d "$objdir" ] \
|
89
|
&& err "obj path already exists and is not a directory"
|
90
|
|
91
|
for env_var in __MAKE_CONF SRCCONF SRC_ENV_CONF; do
|
92
|
eval "value=\${$env_var}"
|
93
|
[ -n "${value}" -a ! -f "${value}" ] \
|
94
|
&& err "${env_var} is pointing to a nonexistent file ${value}"
|
95
|
done
|
96
|
|
97
|
[ ! -f ${srcdir}/sys/sys/param.h ] \
|
98
|
&& err "Source directory is missing sys/sys/param.h"
|
99
|
|
100
|
ncpu=$(sysctl -qn hw.ncpu)
|
101
|
njobs=$((ncpu*2))
|
102
|
j="-j${njobs}"
|
103
|
|
104
|
[ -n "${objdir}" ] \
|
105
|
&& export MAKEOBJDIRPREFIX=${objdir}
|
106
|
|
107
|
[ -z "${skip_world}" ] \
|
108
|
&& run "Building world" \
|
109
|
"make -C ${srcdir} -s ${j} buildworld"
|
110
|
|
111
|
if [ -z "${skip_kernel}" ]; then
|
112
|
for kernel in ${KERNCONF:-pfSense}; do
|
113
|
run "Building kernel (${kernel})" \
|
114
|
"make -C ${srcdir} -s ${j} KERNCONF=${kernel} buildkernel"
|
115
|
done
|
116
|
fi
|
117
|
|
118
|
exit 0
|