aboutsummaryrefslogtreecommitdiff
path: root/libexec/build-make-export
blob: c4183f3ec530fd82d106006d6c8765fbd22e873f (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
99
100
101
102
103
#!/usr/bin/env build

build_make_export()
{(
	load_rules "${1}"

	if test -z "${LICENSE}"; then
		die "no license set in '${1}'"
	fi

	echo "exporting ${1}"

	for dir in "${S}" "${D}"; do
		if ! test -d "${dir}"; then
			continue
		fi
		mv "${dir}" "${dir}.old"
		find "${dir}.old" -delete &
	done
	unset dir

	mkenv 'export'
	EXPORT_LOGFILE="${L}/export.log"

	mkdir -p "${T}/${NAME}-${VERSION}.builder"
	cp "${RULESFILE}" "${T}/${NAME}-${VERSION}.builder/"

	if ! test -z "${PATCHES}"; then
		for patch in ${PATCHES}; do
			cp "${F}/${NAME}-${VERSION}-${patch}.patch" "${T}/${NAME}-${VERSION}.builder/"
		done
	fi

	cd "${T}"

	for url in ${SOURCE_URI}; do
		file="$(build-url --archive "${url}")"
		test -f "${BUILDER_SRCDIR}/${file}" || die "source does not exist '${file}'"
		cp "${BUILDER_SRCDIR}/${file}" "${NAME}-${VERSION}.builder/"
	done

	for dir in SOURCES SPECS RPMS BUILD; do
		mkdir -p "${S}/${dir}" &
	done
	wait

	if ! tar czf "${S}/SOURCES/${NAME}-${VERSION}.builder.tar.gz" "${NAME}-${VERSION}.builder"; then
		die "Failed to create base rpm tarball."
	fi

	cat <<-EOF > "${S}/SPECS/${NAME}-${VERSION}.spec"
	Summary: ${DESCRIPTION}
	Name: ${NAME}
	Version: ${VERSION}
	Release: ${RELEASE}
	License: ${LICENSE}
	Group: ${CATEGORY}
	Source: ${NAME}-${VERSION}.builder.tar.gz
	Buildroot: ${SYSROOT}
	%description
	${DESCRIPTION}

	%prep
	%setup -c

	%build

	%install

	%clean

	%files
	EOF

	# FIXME In the long run we should see about producing -dbg and -dev rpms
	tr '\000' '\n' < "${SYSROOT}/var/db/binpkgs/${CATEGORY}/${NAME}" \
		| sed -e 's,^,/,' \
		| grep -v '^/usr/include' | grep -v 'pkgconfig' | grep -v '^*\.a$' \
		>> "${S}/SPECS/${NAME}-${VERSION}.spec"

	#mkdir -p "${D}"
	#cd "${D}"
	#tar xaf "${BUILDER_ATFDIR}/${CATEGORY}/${NAME}-${VERSION}.${ARCHIVE_FORMAT}"

	rpmbuild --quiet --target "${CHOST}"	\
		--define "_topdir ${S}"		\
		--define "buildroot ${SYSROOT}"	\
		--define '_unpackaged_files_terminate_build 0'	\
		--define '_missing_doc_files_terminate_build 0'	\
		--define "arch ${CHOST%%-*}"	\
		-bb "${S}/SPECS/${NAME}-${VERSION}.spec" > "${L}/export.log" 2>&1 || die "Failed to integrate rpm spec file"

	mkdir -p "${BUILDER_TOPDIR}/exports"
# FIXME figure out the arch properly
	mv "${S}/RPMS/${CHOST%%-*}/${NAME}-${VERSION}-${RELEASE}.${CHOST%%-*}.rpm" "${BUILDER_TOPDIR}/exports/" || die "Failed to move rpm"
)}

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

# vim: filetype=sh