Project

General

Profile

Download (2.72 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/bin/sh
2
#
3
# build_freebsd.sh
4
#
5
# part of pfSense (https://www.pfsense.org)
6
# Copyright (c) 2004-2016 Electric Sheep Fencing, LLC
7
# All rights reserved.
8
#
9
# Licensed under the Apache License, Version 2.0 (the "License");
10
# you may not use this file except in compliance with the License.
11
# You may obtain a copy of the License at
12
#
13
# http://www.apache.org/licenses/LICENSE-2.0
14
#
15
# Unless required by applicable law or agreed to in writing, software
16
# distributed under the License is distributed on an "AS IS" BASIS,
17
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
# See the License for the specific language governing permissions and
19
# limitations under the License.
20

    
21
export PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin
22

    
23
scripts_path=$(dirname $(realpath $0))
24

    
25
if [ ! -f "${scripts_path}/common.subr" ]; then
26
	echo >&2 "ERROR: common.subr is missing"
27
	exit 1
28
fi
29

    
30
. ${scripts_path}/common.subr
31

    
32
usage() {
33
	cat >&2 <<END
34
Usage: $(basename $0) -s srcdir [-o objdir] [-h]
35

    
36
Options:
37
	-s srcdir  -- Path to src directory
38
	-o objdir  -- Obj directory used to build
39
	-W         -- Skip buildworld
40
	-K         -- Skip buildkernel
41
	-h         -- Show this help and exit
42

    
43
Environment:
44
	__MAKE_CONF      -- Path to make.conf
45
	SRCCONF          -- Path to src.conf
46
	SRC_ENV_CONF     -- Path to src-env.conf
47
	KERNCONF         -- Kernel names
48
	MODULES_OVERRIDE -- List of kernel modules to build
49
	TARGET           -- Machine hardware name
50
	TARGET_ARCH      -- Machine processor arquitecture name
51
END
52
	exit 1
53
}
54

    
55
unset skip_world
56
unset skip_kernel
57
while getopts s:o:WKh opt; do
58
	case "$opt" in
59
		s)
60
			srcdir=$OPTARG
61
			;;
62
		o)
63
			objdir=$OPTARG
64
			;;
65
		W)
66
			skip_world=1
67
			;;
68
		K)
69
			skip_kernel=1
70
			;;
71
		*)
72
			usage
73
			;;
74
	esac
75
done
76

    
77
# Default obj dir to src/../obj
78
: ${objdir=${srcdir}/../obj}
79

    
80
[ -z "$srcdir" ] \
81
	&& err "source directory is not defined"
82

    
83
[ -e $srcdir -a ! -d $srcdir ] \
84
	&& err "source path already exists and is not a directory"
85

    
86
[ -n "$objdir" -a -e $objdir -a ! -d $objdir ] \
87
	&& err "obj path already exists and is not a directory"
88

    
89
for env_var in __MAKE_CONF SRCCONF SRC_ENV_CONF; do
90
	eval "value=\${$env_var}"
91
	[ -n "${value}" -a ! -f "${value}" ] \
92
		&& err "${env_var} is pointing to a nonexistent file ${value}"
93
done
94

    
95
[ ! -f ${srcdir}/sys/sys/param.h ] \
96
	&& err "Source directory is missing sys/sys/param.h"
97

    
98
ncpu=$(sysctl -n hw.ncpu)
99
njobs=$((ncpu*2))
100
j="-j${njobs}"
101

    
102
[ -n "${objdir}" ] \
103
	&& export MAKEOBJDIRPREFIX=${objdir}
104

    
105
[ -z "${skip_world}" ] \
106
	&& run "Building world" \
107
		"make -C ${srcdir} -s ${j} buildworld"
108

    
109
if [ -z "${skip_kernel}" ]; then
110
	for kernel in ${KERNCONF:-pfSense}; do
111
		run "Building kernel (${kernel})" \
112
			"make -C ${srcdir} -s ${j} KERNCONF=${kernel} buildkernel"
113
	done
114
fi
115

    
116
exit 0
(1-1/5)