Projet

Général

Profil

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

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

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

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

    
198
overlay_run_depend_list() {
199
	local BUILDLIST
200
	local BUILD
201

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

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

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

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

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

    
274
		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
275
			echo ">>> Building $_PORTNAME(${_PKGNAME})...ERROR!" >> $SCRATCHDIR/pfPort_build_failures
276
			echo "    +++ Failed to build. Error log in $SCRATCHDIR/pfPort/buildlogs/$_PORTNAME."
277
		else
278
			mv $SCRATCHDIR/pfPort/buildlogs/$_PORTNAME $SCRATCHDIR/pfPort/$_PKGNAME
279
			echo "$_PKGNAME" >> $_RECORDDB
280
			echo "Done."
281

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

    
290
	unset _PKGNAME
291
	unset _CROSSBUILD
292
	unset _RECORDDB
293
	unset _LOCAL_MAKE_CONF
294
	unset _LOCAL_TARGETS
295
	unset _VERIFY
296
}
297

    
298
clean_build_install_clean() {
299
	local PORTPATH
300
	local _VERIFYPORT
301
	local _RECORDDB
302
	local _CROSSBUILD
303

    
304
	PORTPATH="${1}"
305
	_RECORDDB="${2}"
306
	_CROSSBUILD="${3:-nocrossbuild}"
307
	_VERIFYPORT="${4}"
308

    
309
	if [ ! -d $PORTPATH ]; then
310
		echo "    +++ Port PATH does not exist: '${PORTPATH}'"
311
		return
312
	fi
313

    
314
	if [ "${_CROSSBUILD}" = "crossbuild" ]; then
315
		_RECORDDB=$SCRATCHDIR/pfPort_alreadybuilt
316
	else
317
		_RECORDDB=$SCRATCHDIR/pfPort_builddepend_alreadybuilt
318
	fi
319

    
320
	clean_make_install_build_dependency $PORTPATH $SCRATCHDIR/pfPort_builddepend_alreadybuilt build-depends-list nocrossbuild $_VERIFYPORT 
321
	overlay_run_depend_list ${PORTPATH}
322
	if [ "${_CROSSBUILD}" = "crossbuild" ]; then
323
		clean_make_install_build_dependency $PORTPATH $_RECORDDB run-depends-list $_CROSSBUILD $_VERIFYPORT
324
	fi
325
	clean_make_install $PORTPATH $_RECORDDB $_CROSSBUILD $_VERIFYPORT
326

    
327
	unset _RECORDDB
328
	unset _CROSSBUILD
329
	unset _VERIFYPORT
330
	unset PORTPATH
331
}
332

    
333
# Change the for seperator to use C/R instead of whitespace
334
oIFS=$IFS
335
IFS="
336
"
337

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

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

    
363
	if [ "$BUILD_ONEPORT" != "" -a "$_PORT_NAME" = "$BUILD_ONEPORT" ]; then
364
		break
365
	fi
366
done
367

    
368
echo ">>> Ports with failures: $(cat $SCRATCHDIR/pfPort_build_failures | wc -l)"
369
cat $SCRATCHDIR/pfPort_build_failures
370
echo
371

    
372
sleep 1
373

    
374
# Restore
375
IFS=$oIFS
(1-1/11)