aboutsummaryrefslogtreecommitdiff
path: root/builder/build-makedeps
blob: e4b628ca524314f24571d2f41ac7501605d1d343 (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/env build
cat >"${BUILDER_MAKEFILE}" <<EOF
##
# Some generic catchall rules
all: ${PROJECT}_archive
all_fetch: ${PROJECT}_all_fetch
all_archive: ${PROJECT}_all_archive
all_install: ${PROJECT}_all_install
all_makedeps:
all_source:

sysroot_clean:
	@if test -d "${SYSROOT}"; then \
		echo "cleaning: sysroot" ; \
		(cd "${SYSROOT}" && find . -delete) ; \
	fi
artifacts_clean:
	@if test -d "${BUILDER_ATFDIR}"; then \
		echo "cleaning: artifacts" ; \
		(cd "${BUILDER_ATFDIR}" && find . -delete) ; \
	fi
tmpdir_clean:
	@if test -d "${BUILDER_TMPDIR}"; then \
		echo "cleaning: tmpdir" ; \
		find "${BUILDER_TMPDIR}" -delete ; \
	fi
EOF

PACKAGES_CLEAN=
for package in $(cd "${BUILDER_PKGDIR}" && echo */*); do
	if ! test -f "${BUILDER_PKGDIR}/${package}/Buildrules"; then
		error "no rulesfile for package '${package}'"
		continue
	fi
	if ! eval $(build-query --environ "${package}"); then
		die "in package '${package}'"
	fi

	package_make="$(echo "${package}"|tr '/-' '__')"
	package_archive="${BUILDER_ATFDIR}/${CATEGORY}/${NAME}-${VERSION}-${RELEASE}.${ARCHIVE_FORMAT}"
	package_install="${SYSROOT}/var/db/binpkgs/${CATEGORY}/${NAME}"
	package_logdir="${L}"

	package_sources="${RULESFILE}"
	for patch in ${PATCHES}; do
		patch="${F}/${NAME}-${VERSION}-${patch}.patch"
		if ! test -f "${patch}"; then
			die "patch does not exist '${patch}'"
		fi
		package_sources="${package_sources} ${patch}"
	done

	# FIXME there can be strange characters in a URI .. this might not be
	# the best approach in the long term.
	for url in ${SOURCE_URI}; do
		case "${url}" in
		# Do not translate local paths into archives in BUILDER_SRCDIR
		(file://*|/*)	package_sources="${package_sources} ${url##file://}";;

		# Assume anything else with :// in the name is remote
		(*://*)		pkg_src="$(build-fetch --name "${url}")"
				if test "$?" -ne "0"; then
					exit 1
				fi
				package_sources="${package_sources} ${BUILDER_SRCDIR}/${pkg_src}";;
		# Junk?
		(*)		die "do not know how to handle url '${url}'";;
		esac
	done

	# This loop can end up being fairly costly if we have to fire up
	# build-query, particularly when dealing with a large number of
	# packages.  So we do some FS level checks first in hopes of avoiding
	# it and improving performance.
	package_bdeps=
	for pkg_dep in ${BDEPENDS}; do
		if ! test -d "${BUILDER_PKGDIR}/${pkg_dep}"; then
			if ! test -d "${BUILDER_PKGDIR}/${PROJECT}/${pkg_dep}"; then
				if ! build-query --exists "${pkg_dep}"; then
					die "bad BDEPENDS in package '${package}'"
				fi
			elif ! test -f "${BUILDER_PKGDIR}/${PROJECT}/${pkg_dep}/Buildrules"; then
				die "no Buildrules for '${pkg_dep}'"
			fi
			pkg_dep="${PROJECT}/${pkg_dep}"
		elif ! test -f "${BUILDER_PKGDIR}/${pkg_dep}/Buildrules"; then
			die "no Buildrules for '${pkg_dep}'"
		fi
		package_bdeps="${package_bdeps} ${SYSROOT}/var/db/binpkgs/${pkg_dep}"
	done

	package_rdeps=
	for pkg_dep in ${RDEPENDS}; do
		if ! test -d "${BUILDER_PKGDIR}/${pkg_dep}"; then
			if ! test -d "${BUILDER_PKGDIR}/${PROJECT}/${pkg_dep}"; then
				if ! build-query --exists "${pkg_dep}"; then
					die "bad RDEPENDS in package '${package}'"
				fi
			elif ! test -f "${BUILDER_PKGDIR}/${PROJECT}/${pkg_dep}/Buildrules"; then
				die "no Buildrules for '${pkg_dep}'"
			fi
			pkg_dep="${PROJECT}/${pkg_dep}"
		elif ! test -f "${BUILDER_PKGDIR}/${pkg_dep}/Buildrules"; then
			die "no Buildrules for '${pkg_dep}'"
		fi
		package_rdeps="${package_rdeps} ${SYSROOT}/var/db/binpkgs/${pkg_dep}"
	done
	unset pkg_dep

cat <<EOF

##
# ${CATEGORY}/${NAME} - ${DESCRIPTION}
${package_make}: ${package_archive}
${package_make}_makedeps:
${package_make}_fetch: ${package_sources}
${package_make}_source: ${package_sources}
	@build-source "${CATEGORY}/${NAME}"
${package_make}_clean:
	@build-clean "${CATEGORY}/${NAME}"
${package_make}_distclean:
	@build-distclean "${CATEGORY}/${NAME}"
${package_make}_package: ${package_archive}
${package_archive}: ${package_sources} ${package_bdeps}
	@build-package "${CATEGORY}/${NAME}"
${package_make}_install: ${package_install}
${package_install}: ${package_archive} ${package_rdeps}
	@build-install "${CATEGORY}/${NAME}"
EOF

	##
	# This is a bit of a fun late-injection of the source archive for a
	# package.  The core problem is that multiple packages may depend on
	# the same sources, so we set up a separate rule for the source
	# archive when processing the package, but only if an existing entry
	# for that source does not exist.  We use the source name (as opposed
	# to the package name) to track if the package already has a rule.  The
	# whole thing really translates into something like
	# foo_1_1_3_tar_bz2="http://some/path/to/foo-1.1.3.tar.bz2"
	# All forms of URL translation and variable translation are done for us
	# by fetch so that makedeps doesn't have any specific expectations on
	# what the variable name should be.

	for url in ${SOURCE_URI}; do
		case "${url}" in
		# Do not translate local paths into archives in BUILDER_SRCDIR
		(file://*|/*)	echo "${url##file://}:";;

		# Assume anything else with :// in the name is remote
		(*://*)
			var="$(build-fetch --var "${url}")"
			if test -z "$(eval echo -n "\$${var}")"; then
				eval "${var}='${url}'"
				echo "${BUILDER_SRCDIR}/$(build-fetch --name "${url}"):"
				echo "	@build-fetch \"${url}\""
			fi
			;;
		esac
	done

	category="$(echo "${CATEGORY}"|tr '/-' '__')"
	CATEGORIES="${CATEGORIES} ${category}"

	eval "${category}_SOURCES=\"\${${category}_SOURCES} ${package_sources}\""
	eval "${category}_PACKAGES=\"\${${category}_PACKAGES} ${package_archive}\""
	eval "${category}_INSTALL=\"\${${category}_INSTALL} ${package_install}\""
	eval "${category}_CLEAN=\"\${${category}_CLEAN} ${package_make}_clean\""
	eval "${category}_DISTCLEAN=\"\${${category}_DISTCLEAN} ${package_make}_distclean\""

	PACKAGES_CLEAN="${PACKAGES_CLEAN} ${package_make}_clean"
done >> "${BUILDER_MAKEFILE}"

# FIXME It would have been nice to have not inserted the category if it was
# already in the list.
CATEGORIES="$(for CATEGORY in ${CATEGORIES};do echo "${CATEGORY}";done|sort|uniq)"

for CATEGORY in ${CATEGORIES}; do
cat<<EOF >> "${BUILDER_MAKEFILE}"
${CATEGORY}_all: ${CATEGORY}_archive
${CATEGORY}_all_fetch: $(eval echo "\${${CATEGORY}_SOURCES}")
${CATEGORY}_all_archive: $(eval echo "\${${CATEGORY}_PACKAGES}")
${CATEGORY}_all_install: $(eval echo "\${${CATEGORY}_INSTALL}")
${CATEGORY}_all_clean: $(eval echo "\${${CATEGORY}_CLEAN}")
${CATEGORY}_all_distclean: $(eval echo "\${${CATEGORY}_DISTCLEAN}")

EOF
done

cat<<EOF >> "${BUILDER_MAKEFILE}"
all_clean: ${PACKAGES_CLEAN}
all_distclean: sysroot_clean artifacts_clean tmpdir_clean
EOF

# vim: filetype=sh