Projet

Général

Profil

Télécharger (10,9 ko) Statistiques
| Branche: | Révision:

univnautes-tools / builder_scripts / scripts / buildports.sh @ d0ae3b0c

1
#!/bin/sh
2

    
3
#set -e
4
#set -x
5
#set -u
6

    
7
if [ ! -f pfsense-build.conf ]; then
8
	echo ">>> You should run this script from tools/builder_scripts folder"
9
	kill $$
10
fi 
11

    
12
HOSTPLATFORM=$(uname -m)
13
BUILD_ONEPORT=""
14
MAKEJ_PORTS=""
15
CHECK_INSTALLED=""
16
PORTS_LIST=""
17
MAKE_CONF=""
18

    
19
while getopts P:J:l:m:c o; do
20
	case "${o}" in
21
		P)	BUILD_ONEPORT="${OPTARG}"
22
			echo ">>> Building a single port: '${BUILD_ONEPORT}'"
23
			;;
24
		J)	MAKEJ_PORTS="${OPTARG}"
25
			echo ">>> Setting MAKEJ_PORTS (-j) to '${MAKEJ_PORTS}'"
26
			;;
27
		l)	PORTS_LIST="${OPTARG}"
28
			echo ">>> Setting ports list: '${PORTS_LIST}'"
29
			;;
30
		m)	MAKE_CONF="${OPTARG}"
31
			echo ">>> Setting ports make.conf: '${MAKE_CONF}'"
32
			;;
33
		c)	CHECK_INSTALLED="check_installed"
34
			;;
35
	esac
36
done
37

    
38
if [ -z "${PORTS_LIST}" -o ! -f "${PORTS_LIST}" ]; then
39
	echo ">>> ERROR! Invalid Port list"
40
	exit 1
41
fi
42

    
43
if [ $(sysctl -n kern.osreldate) -gt 1000000 ]; then
44
	USE_PKGNG=1
45
else
46
	unset USE_PKGNG
47
fi
48

    
49
. ./builder_defaults.sh
50

    
51
if [ "$HOSTPLATFORM" = "$TARGET" ]; then
52
	if grep -q '^export REMOVE_PHP=true' $BASE_DIR/tools/builder_scripts/pfsense-build.conf; then
53
		echo ">>> Removing previous PHP environment..."
54
		if [ -n "${USE_PKGNG}" ]; then
55
			pkg delete -y -R -f -q -g php* 2>/dev/null
56
		else
57
			rm -rf /var/db/pkg/php*
58
		fi
59
		find /usr/local/include /usr/local/man/ /usr/local/bin /usr/local/sbin /usr/local/lib /usr/local/etc -name "*php*" -exec rm -rf {} \; 2>/dev/null
60
		find /usr/local -name extensions.ini -delete
61
	fi
62
	_PORT_BUILD_TARGET="nocrossbuild"
63
else
64
	echo ">>> Cross build environment will be used"
65
	if [ ! -f ${MAKEOBJDIRPREFIX}/${TARGET}.${TARGET_ARCH}/${SRCDIR}/tmp/usr/bin/cc ]; then
66
		echo ">>> ERROR! The Cross compiler environment does not exist!"
67
		echo ">>> CAnnot continue. EXITING!"
68
		exit 1
69
	fi
70
	_PORT_BUILD_TARGET="crossbuild"
71
fi
72

    
73
if [ -z "${MAKE_CONF}" -o ! -f "${MAKE_CONF}" ]; then
74
	MAKE_CONF="${BASE_DIR}/tools/builder_scripts/conf/pfPorts/make.conf"
75
fi
76

    
77
MAKE_CONF="__MAKE_CONF=${MAKE_CONF}"
78

    
79
if [ -z "${MAKEJ_PORTS}" ]; then
80
	if [ -f $BASE_DIR/tools/builder_scripts/builder_defaults.sh ]; then
81
		MAKEJ_PORTS=$(grep MAKEJ_PORTS $BASE_DIR/tools/builder_scripts/builder_defaults.sh | cut -d'"' -f2)
82
	fi
83
fi
84

    
85
# Keep track of build failures
86
if [ "${BUILD_ONEPORT}" != "" ]; then
87
	rm -f $SCRATCHDIR/pfPort_build_failures
88
	touch $SCRATCHDIR/pfPort_build_failures
89
fi
90

    
91
# Keep track of items already built (dependencies)
92
# rm -f $SCRATCHDIR/pfPort_alreadybuilt
93
touch $SCRATCHDIR/pfPort_alreadybuilt
94
# rm -f $SCRATCHDIR/pfPort_builddepend_alreadybuilt
95
touch $SCRATCHDIR/pfPort_builddepend_alreadybuilt
96

    
97
# Individual logs here
98
mkdir -p $SCRATCHDIR/pfPort/buildlogs
99

    
100
is_port_installed() {
101
	local PORT
102

    
103
	PORT="${1}"
104

    
105
	if [ -z "${PORT}" ]; then
106
		return 1
107
	elif [ -n "${USE_PKGNG}" ]; then
108
		if pkg query %n ${PORT} >/dev/null 2>&1; then
109
			return 0
110
		else
111
			return 1
112
		fi
113
	else
114
		if [ -d /var/db/pkg/${PORT} ]; then
115
			return 0
116
		else
117
			return 1
118
		fi
119
	fi
120
}
121

    
122
overlay_port() {
123
	local PORTPATH
124
	local PORTNAME
125

    
126
	PORTPATH="${1}"
127
	PORTNAME=$(basename $PORTPATH)
128

    
129
	if [ -d ${pfSPORTS_BASE_DIR}/$PORTNAME ]; then
130
		echo "    +++ Overlaying pfPorts ${pfSPORTS_BASE_DIR}/$PORTNAME to ${PORTPATH} ..."
131
		rm -rf $PORTPATH
132
		mkdir -p $PORTPATH
133
		rm -rf ${pfSPORTS_BASE_DIR}/$PORTNAME/work 2>/dev/null
134
		cp -R ${pfSPORTS_BASE_DIR}/$PORTNAME/* $PORTPATH/
135
	fi
136
}
137

    
138
clean_make_install_build_dependency() {
139
	local PORTA
140
	local _VERIFY
141
	local BUILDLIST
142
	local _PORTNAME
143
	local _PKGNAME
144
	local BUILD
145
	local _TARGET
146
	local _RECORDDB
147

    
148
	PORTA="${1}"
149
	_TARGET="${3}"
150
	_VERIFY="${5}"
151

    
152
	if [ "${4}" = "crossbuild" ]; then
153
		_RECORDDB=$SCRATCHDIR/pfPort_alreadybuilt
154
	else
155
		_RECORDDB=$SCRATCHDIR/pfPort_builddepend_alreadybuilt
156
	fi
157

    
158
	_PORTNAME=$(basename $PORTA)
159
	_PKGNAME=$(make ${MAKE_CONF} -C $PORTA -V PKGNAME)
160

    
161
	# Check to see if item is already built
162
	if grep -q "$_PKGNAME" $_RECORDDB; then
163
		if [ -z "$_VERIFY" -o -f $_VERIFY ]; then
164
			echo "    +++ $_PORTNAME(${_PKGNAME})...already built on this run.  Skipping."
165
		fi
166
	else
167
		# Complete dependency chain first
168
		BUILDLIST=$(make ${MAKE_CONF} -C ${PORTA} $_TARGET 2>/dev/null)
169
		for BUILD in $BUILDLIST; do
170
			echo "    +++ $BUILD is a ${_TARGET} of $PORTA"
171
			# Check to see if item is already built
172
			overlay_port ${BUILD}
173
			local _PKGNAME=$(make ${MAKE_CONF} -C $PORTA -V PKGNAME)
174
			SKIP=0
175
			if grep -q "$_PKGNAME" $_RECORDDB; then
176
				SKIP=1
177
				echo "    +++ ${_TARGET} $BUILD of $PORTA already built on this run.  Skipping."
178
			elif [ "${CHECK_INSTALLED}" = "check_installed" ]; then
179
				if is_port_installed ${_PKGNAME}; then
180
					if [ -z "$_VERIFY" -o -f $_VERIFY ]; then
181
						echo "$_PKGNAME" >> $_RECORDDB
182
						SKIP=1
183
					fi
184
				fi
185
			fi
186

    
187
			if [ ${SKIP} -eq 0 ]; then
188
				echo "    +++ Building ${_TARGET} $BUILD of $PORTA"
189
				clean_build_install_clean $BUILD $_RECORDDB ${4} ""
190
				echo "    +++ Finished ${_TARGET} $BUILD of $PORTA.... DONE!"
191
			fi
192
		done
193
	fi
194
	unset _TARGET
195
	unset _RECORDDB
196
	unset BUILD
197
	unset BUILDLIST
198
}
199

    
200
overlay_run_depend_list() {
201
	local BUILDLIST
202
	local BUILD
203

    
204
	BUILDLIST=$(make ${MAKE_CONF} -C ${PORTA} run-depends-list 2>/dev/null)
205
	for BUILD in $BUILDLIST; do
206
		
207
		overlay_port $BUILD
208
	done
209
	unset BUILD
210
	unset BUILDLIST
211
}
212

    
213
clean_make_install() {
214
	# Architecture, supported ARCH values are:
215
	#  Tier 1: i386, AMD64, and PC98
216
	#  Tier 2: ARM, PowerPC, ia64, Sparc64 and sun4v
217
	#  Tier 3: MIPS and S/390
218
	#  Tier 4: None at the moment
219
	#  Source: http:/www.freebsd.org/doc/en/articles/committers-guide/archs.html
220
	# Default is i386
221
	local PORTA
222
	local _VERIFY
223
	local _PORTNAME
224
	local _PKGNAME
225
	local _RECORDDB
226
	local _CROSSBUILD
227
	local _LOCAL_MAKE_CONF
228
	local _LOCAL_TARGETS
229

    
230
	PORTA="${1}"
231
	_RECORDDB="${2}"
232
	_CROSSBUILD="${3}"
233
	_VERIFY="${4}"
234

    
235
	_PORTNAME=$(basename $PORTA)
236
	_PKGNAME=$(make ${MAKE_CONF} -C $PORTA -V PKGNAME)
237

    
238
	# Check to see if item is already built
239
	if grep -q "$_PKGNAME" "$_RECORDDB"; then
240
		if [ -z "$_VERIFY" -o -f $_VERIFY ]; then
241
			echo "    +++ $_PORTNAME(${_PKGNAME})...already built on this run.  Skipping."
242
		fi
243
	else
244
		_LOCAL_MAKE_CONF="${MAKE_CONF} ${MAKEJ_PORTS} BATCH=yes"
245
		if [ "${HOSTPLATFORM}" = "${TARGET}" -o "${_CROSSBUILD}" = "nocrossbuild" ]; then
246
			echo -n "    +++ Building port: $_PORTNAME(${_PKGNAME})..."
247
			if [ "${BUILD_ONEPORT}" = "" -a "${CHECK_INSTALLED}" = "check_installed" ]; then
248
				if is_port_installed ${_PKGNAME}; then
249
					if [ -z "$_VERIFY" -o -f $_VERIFY ]; then
250
						echo "$_PKGNAME" >> $_RECORDDB
251
						echo "already built.  Skipping."
252
						return
253
					fi
254
				fi
255
			fi
256
			_LOCAL_MAKE_CONF="${_LOCAL_MAKE_CONF} FORCE_PKG_REGISTER=yes"
257
			_LOCAL_TARGETS="rmconfig clean build deinstall install clean"
258
			_CROSSOMPILECC=""
259
		else
260
			echo "    +++ Cross building port: ${_PORTNAME}(${_PKGNAME}) "
261
			# XXX: /usr/local is hardcoded here!
262
			#_LOCAL_MAKE_CONF="${_LOCAL_MAKE_CONF} ARCH=${TARGET_ARCH} PREFIX=${PFSENSESTAGEDIR}/usr/local NO_PKG_REGISTER=yes STAGEDIR=/usr/local/pfsense-stage-ports"
263
			_LOCAL_MAKE_CONF="${_LOCAL_MAKE_CONF} ARCH=${TARGET_ARCH} NO_PKG_REGISTER=yes" # STAGEDIR=${PFSENSESTAGEDIR}"
264
			_LOCAL_MAKE_CONF="${_LOCAL_MAKE_CONF} CONFIGURE_ARGS+=\"--host=${TARGET_ARCH}-undermydesk-freebsd\""
265
			_LOCAL_MAKE_CONF="${_LOCAL_MAKE_CONF} LDFLAGS+=\"-rpath=${PFSENSESTAGEDIR}/lib:${PFSENSESTAGEDIR}/usr/lib:${PFSENSESTAGEDIR}:/usr/local\lib:\
266
				${MAKEOBJDIRPREFIX}/${TARGET}.${TARGET_ARCH}$SRCDIR/tmp/lib:${MAKEOBJDIRPREFIX}/${TARGET}.${TARGET_ARCH}$SRCDIR/tmp/usr/lib\""
267
			_LOCAL_MAKE_CONF="${_LOCAL_MAKE_CONF} LDFLAGS+=\"-L${PFSENSESTAGEDIR}/lib\""
268
			_LOCAL_MAKE_CONF="${_LOCAL_MAKE_CONF} LDFLAGS+=\"-L${PFSENSESTAGEDIR}/usr/lib\""
269
			_LOCAL_MAKE_CONF="${_LOCAL_MAKE_CONF} LDFLAGS+=\"-L${PFSENSESTAGEDIR}/usr/local/lib\""
270
			_LOCAL_MAKE_CONF="${_LOCAL_MAKE_CONF} LDFLAGS+=\"-L${MAKEOBJDIRPREFIX}/${TARGET}.${TARGET_ARCH}$SRCDIR/tmp/lib\""
271
			_LOCAL_MAKE_CONF="${_LOCAL_MAKE_CONF} LDFLAGS+=\"-L${MAKEOBJDIRPREFIX}/${TARGET}.${TARGET_ARCH}$SRCDIR/tmp/usr/lib\""
272
			_VERIFY="${PFSENSESTAGEDIR}${_VERIFY}"
273
			_LOCAL_TARGETS="rmconfig clean build stage package clean"
274
			_CROSSOMPILECC="${MAKEOBJDIRPREFIX}/${TARGET}.${TARGET_ARCH}$SRCDIR/tmp/usr/bin:"
275
		fi
276
		echo "    +++ ${_PORTNAME} environment: ${_LOCAL_MAKE_CONF}"
277

    
278
		if ! script $SCRATCHDIR/pfPort/buildlogs/$_PORTNAME env -u TARGET -u TARGET_ARCH PATH=${_CROSSOMPILECC}${PATH} make ${_LOCAL_MAKE_CONF} -C $PORTA $_LOCAL_TARGETS 2>&1 1>/dev/null; then
279
			echo ">>> Building $_PORTNAME(${_PKGNAME})...ERROR!" >> $SCRATCHDIR/pfPort_build_failures
280
			echo "    +++ Failed to build. Error log in $SCRATCHDIR/pfPort/buildlogs/$_PORTNAME."
281
		else
282
			mv $SCRATCHDIR/pfPort/buildlogs/$_PORTNAME $SCRATCHDIR/pfPort/$_PKGNAME
283
			echo "$_PKGNAME" >> $_RECORDDB
284
			echo "Done."
285

    
286
			# If the file is not found, log it.
287
			if [ ! -z "${_VERIFY}" -a ! -f "${_VERIFY}" ]; then
288
				echo ">>> File not found $PORTA - $_VERIFY" >> $SCRATCHDIR/pfPort_build_failures
289
				echo "    +++ File not found $PORTA - $_VERIFY(${2})"
290
			fi
291
		fi
292
	fi
293

    
294
	unset _PKGNAME
295
	unset _CROSSBUILD
296
	unset _RECORDDB
297
	unset _LOCAL_MAKE_CONF
298
	unset _LOCAL_TARGETS
299
	unset _VERIFY
300
}
301

    
302
clean_build_install_clean() {
303
	local PORTPATH
304
	local _VERIFYPORT
305
	local _RECORDDB
306
	local _CROSSBUILD
307

    
308
	PORTPATH="${1}"
309
	_RECORDDB="${2}"
310
	_CROSSBUILD="${3:-nocrossbuild}"
311
	_VERIFYPORT="${4}"
312

    
313
	if [ ! -d $PORTPATH ]; then
314
		echo "    +++ Port PATH does not exist: '${PORTPATH}'"
315
		return
316
	fi
317

    
318
	if [ "${_CROSSBUILD}" = "crossbuild" ]; then
319
		_RECORDDB=$SCRATCHDIR/pfPort_alreadybuilt
320
	else
321
		_RECORDDB=$SCRATCHDIR/pfPort_builddepend_alreadybuilt
322
	fi
323

    
324
	clean_make_install_build_dependency $PORTPATH $SCRATCHDIR/pfPort_builddepend_alreadybuilt build-depends-list nocrossbuild $_VERIFYPORT 
325
	overlay_run_depend_list ${PORTPATH}
326
	if [ "${_CROSSBUILD}" = "crossbuild" ]; then
327
		clean_make_install_build_dependency $PORTPATH $_RECORDDB run-depends-list $_CROSSBUILD $_VERIFYPORT
328
	fi
329
	clean_make_install $PORTPATH $_RECORDDB $_CROSSBUILD $_VERIFYPORT
330

    
331
	unset _RECORDDB
332
	unset _CROSSBUILD
333
	unset _VERIFYPORT
334
	unset PORTPATH
335
}
336

    
337
# Change the for seperator to use C/R instead of whitespace
338
oIFS=$IFS
339
IFS="
340
"
341

    
342
# Remove blank and commented out lines
343
PORTSTOBUILD=$(cat ${PORTS_LIST} | sed -e '/^[[:blank:]]*$/d; /^[[:blank:]]#/d')
344
for _PORT in $PORTSTOBUILD; do
345
	_PORT_NAME=$(echo $_PORT | awk '{ print $1 }')
346
	if [ "$BUILD_ONEPORT" != "" -a "$_PORT_NAME" != "$BUILD_ONEPORT" ]; then
347
		continue
348
	fi
349
	_PORT_LOCATION=$(echo $_PORT | awk '{ print $2 }')
350
	_PORT_VERIFY_INSTALL_FILE=$(echo $_PORT | awk '{ print $3 }')
351

    
352
	_PORTSUFFIX=$(echo $_PORT_LOCATION | cut -d'/' -f4-5)
353
	if [ "$_PORTSUFFIX" != "" ]; then
354
		# Return the seperator back to its original value
355
		IFS=$oIFS
356
		echo ">>> Starting build of ${_PORT_NAME}"
357
		overlay_port ${_PORT_LOCATION}
358
		clean_build_install_clean $_PORT_LOCATION $SCRATCHDIR/pfPort_alreadybuilt $_PORT_BUILD_TARGET $_PORT_VERIFY_INSTALL_FILE
359
		# Change the for seperator to use C/R instead of whitespace
360
		echo ">>> Finished build of ${_PORT_NAME}"
361
		IFS="
362
"
363
	else
364
		echo ">>> Could not Locate PORTSUFFIX for $_PORT_LOCATION"
365
	fi
366

    
367
	if [ "$BUILD_ONEPORT" != "" -a "$_PORT_NAME" = "$BUILD_ONEPORT" ]; then
368
		break
369
	fi
370
done
371

    
372
echo ">>> Ports with failures: $(cat $SCRATCHDIR/pfPort_build_failures | wc -l)"
373
cat $SCRATCHDIR/pfPort_build_failures
374
echo
375

    
376
sleep 1
377

    
378
# Restore
379
IFS=$oIFS
(1-1/11)