aboutsummaryrefslogtreecommitdiff
path: root/libexec/build-make-package
blob: 87cf024315ff4524194b3752bb403b6e267cdfb9 (plain)
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
#!/usr/bin/env build

BUILD_MAKE_ARCHIVE_TMP1=
BUILD_MAKE_ARCHIVE_TMP2=
build_make_archive_cleanup()
{
	ret=$?

	if [ ${ret} -ne 0 ]; then
		echo "error: archiving failed for ${CATEGORY}/${NAME}" >&2
		echo "logfile: '${PKG_LOGFILE}'" >&2
		exit ${ret}
	fi
	if [ -f "${BUILD_MAKE_ARCHIVE_TMP1}" ]; then
		rm -f "${BUILD_MAKE_ARCHIVE_TMP1}"
	fi
	if [ -f "${BUILD_MAKE_ARCHIVE_TMP2}" ]; then
		rm -f "${BUILD_MAKE_ARCHIVE_TMP2}"
	fi
	exit 0
}

build_make_archive()
{(
	trap build_make_archive_cleanup 0

	echo "archiving: ${1}"
	load_rules "${1}"
	mkenv "archive"
	PKG_LOGFILE="${L}/archive.log"

	BUILD_MAKE_ARCHIVE_TMP1="$(mktemp "${BUILDER_TMPDIR}/${NAME}-${VERSION}-${RELEASE}.XXXXXXXX")"
	[ -f "${BUILD_MAKE_ARCHIVE_TMP1}" ] || die "failed to create temporary archive for package '${NAME}'"

	BUILD_MAKE_ARCHIVE_TMP2="$(mktemp "${BUILDER_TMPDIR}/${NAME}-${VERSION}-${RELEASE}.XXXXXXXX")"
	[ -f "${BUILD_MAKE_ARCHIVE_TMP2}" ] || die "failed to create temporary archive for package '${NAME}'"

	case "${ARCHIVE_FORMAT}" in
	(tbz2|tar.bz2)	ARCHIVE_COMPRESSOR="bzip2 -cv";;
	(tgz|tar.gz)	ARCHIVE_COMPRESSOR="gzip -cv";;
	(*)		die "unsupported archive format '${ARCHIVE_FORMAT}'";;
	esac

	if [ ! -d "${BUILDER_ATFDIR}/${CATEGORY}" ]; then
		mkdir -p "${BUILDER_ATFDIR}/${CATEGORY}"
	fi

	cd "${D}"
	tar -cvf "${BUILD_MAKE_ARCHIVE_TMP1}" .  > "${PKG_LOGFILE}" 2>&1
	${ARCHIVE_COMPRESSOR} "${BUILD_MAKE_ARCHIVE_TMP1}" > "${BUILD_MAKE_ARCHIVE_TMP2}" 2>> "${PKG_LOGFILE}"
	if [ -f "${BUILDER_ATFDIR}/${CATEGORY}/${NAME}-${VERSION}-${RELEASE}.${ARCHIVE_FORMAT}" ]; then
		rm -f "${BUILDER_ATFDIR}/${CATEGORY}/${NAME}-${VERSION}-${RELEASE}.${ARCHIVE_FORMAT}"
	fi
	mv -v "${BUILD_MAKE_ARCHIVE_TMP2}" "${BUILDER_ATFDIR}/${CATEGORY}/${NAME}-${VERSION}-${RELEASE}.${ARCHIVE_FORMAT}" >> "${PKG_LOGFILE}" 2>&1
	cd "${W}"
	find "${D}" -delete &

	##
	# Technically everything should be done but we did throw a number of
	# things into the background during execution, so go ahead and wait to
	# see if anything
	# is stil going.
	wait
)}

if test "${BUILDER_CALL_STACK}" = '__main__'; then
	simple_usage 'package' '[all|[<category>/]<package|all>]' "$@"
	build_make_archive "${@}"
fi


# vim: filetype=sh