aboutsummaryrefslogtreecommitdiff
path: root/libexec/build-make-prep
blob: 732c7cf7d5a9175f44b32a5cce97509730af09d3 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env build

build_make_prep_cleanup()
{
	ret=$?

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

build_make_prep()
{(
	trap build_make_prep_cleanup 0

	build_prep() { return; }
	pkg_prep() { build_prep; }

	load_rules "${1}"

	# Cleanup the build build environment
	for dir in "${S}" "${D}"; do
		if [ ! -d "${dir}" ]; then
			continue
		fi
		mv "${dir}" "${dir}.old"
		find "${dir}.old" -delete &
	done
	unset dir

	mkenv "prep"
	PKG_LOGFILE="${L}/prep.log"

	SOURCE_DIR="${BUILDER_PKGDIR}/${CATEGORY}/${NAME}/source"
	if [ -d "${SOURCE_DIR}" -o -L "${SOURCE_DIR}" ]; then
		echo "prepping ${1} from source: '${SOURCE_DIR}"
		if [ "$(command -v rsync)" ]; then
			if ! rsync -rav --delete "${SOURCE_DIR}/" "${S}"; then
				die "failed to sync source to '${S}'"
			fi
		else
			if ! cp -vadpR "${SOURCE_DIR}" "${S}"; then
				die "failed to copy source to '${S}'"
			fi
		fi >> "${PKG_LOGFILE}" 2>&1
	else
		# FIXME this stuff needs a lot of work
		for url in ${SOURCE_URI}; do
			file="$(build-url --archive "${url}")"
			if [ ! -f "${BUILDER_SRCDIR}/${file}" ]; then
				die "source does not exist '${file}'"
			fi
			echo "prepping ${1} from source: '${BUILDER_SRCDIR}/${file}"

			case "${file}" in
			(*.tar.Z|*.tar.z|*.tz)
				tar xZf "${BUILDER_SRCDIR}/${file}" -C "${W}" >> "${PKG_LOGFILE}" 2>&1;;
			(*.tar.gz|*.tgz)
				tar xzf "${BUILDER_SRCDIR}/${file}" -C "${W}" >> "${PKG_LOGFILE}" 2>&1;;
			(*.tar.bz2|*.tbz2)
				tar xjf "${BUILDER_SRCDIR}/${file}" -C "${W}" >> "${PKG_LOGFILE}" 2>&1;;
			(*.tar.xz|*.txz)
				tar xJf "${BUILDER_SRCDIR}/${file}" -C "${W}" >> "${PKG_LOGFILE}" 2>&1;;
			(*.tar.*)
				tar xaf "${BUILDER_SRCDIR}/${file}" -C "${W}" >> "${PKG_LOGFILE}" 2>&1;;
			(*.zip)
				unzip "${BUILDER_SRCDIR}/${file}" -d "${W}" >> "${PKG_LOGFILE}" 2>&1;;
			(*.jar)
				cp "${BUILDER_SRCDIR}/${file}" "${W}" >> "${PKG_LOGFILE}" 2>&1;;
			esac
		done
	fi

	cd "${W}"
	pkg_prep >> "${PKG_LOGFILE}" 2>&1

	# FIXME wrap up the patch command with something more functional
	if [ ! -z "${PATCHES}" ]; then
		for patch in ${PATCHES}; do
			echo "${NAME}: applying patch '${patch}'" | tee -a "${PKG_LOGFILE}"
			if ! patch -l -t -d "${S}" -p1 < "${F}/${NAME}-${VERSION}-${patch}.patch"; then
				exit 1
			fi >> "${PKG_LOGFILE}" 2>&1
		done
	fi

	date > "${BUILDER_TMPDIR}/${CATEGORY}/${NAME}/.prep"
)}

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

# vim: filetype=sh