aboutsummaryrefslogtreecommitdiff
path: root/libexec/build-makedeps
blob: e15f49180d149f184d98359cec0e2d2529984978 (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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/usr/bin/env build

build_makedeps_name() { echo "${1}"|tr '/-' '__'; }

cat >"${BUILDER_MAKEFILE}" <<EOF
##
# Some generic catchall rules
all: all_package
all_all_clean: exports_clean
all_all_distclean: sysroot_clean artifacts_clean tmpdir_clean exports_clean

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
exports_clean:
	@if test -d "${BUILDER_TOPDIR}/exports"; then \\
		echo "cleaning: exports" ; \\
		find "${BUILDER_TOPDIR}/exports" -delete ; \\
	fi

EOF

PACKAGES_CLEAN=
set -- $(cd "${BUILDER_PKGDIR}" && echo */*)
for package; do
	test -d "${BUILDER_PKGDIR}/${package}" || die "no packages defined"

	if ! test -f "${BUILDER_PKGDIR}/${package}/Buildrules"; then
		error "no rulesfile for package '${package}'"
		continue
	fi

	load_rules "${package}"

	makedep_category="$(build_makedeps_name "${CATEGORY}")"

	makedep_target="$(build_makedeps_name "${package}")"
	makedep_tmpdir="${BUILDER_TMPDIR}/${package}"
	makedep_prep="${makedep_tmpdir}/.prep"
	makedep_compile="${makedep_tmpdir}/.compile"
	makedep_test="${makedep_tmpdir}/.test"
	makedep_source="${BUILDER_PKGDIR}/${package}/source"
	makedep_package="${BUILDER_ATFDIR}/${package}-${VERSION}-${RELEASE}.${ARCHIVE_FORMAT}"
	makedep_export="${BUILDER_TOPDIR}/exports/${package}-${VERSION}-${RELEASE}.${CHOST%%-*}.rpm"
	makedep_install="${SYSROOT}/var/db/binpkgs/${package}"

	# Our entry header with simple rules
	cat<<-END_OF_RULES
	##
	# ${CATEGORY}/${NAME} - ${DESCRIPTION}
	all all_all ${makedep_category}_all ${makedep_target}: ${makedep_package}
	all_source all_all_source ${makedep_category}_all_source ${makedep_target}_source: ${makedep_source}
	all_prep all_all_prep ${makedep_category}_all_prep ${makedep_target}_prep: ${makedep_prep}
	all_compile all_all_compile ${makedep_category}_all_compile ${makedep_target}_compile: ${makedep_compile}
	all_package all_all_packge ${makedep_category}_all_package ${makedep_target}_package: ${makedep_package}
	all_install all_all_install ${makedep_category}_all_install ${makedep_target}_install: ${makedep_install}
	all_test all_all_test ${makedep_category}_all_test ${makedep_target}_test: ${makedep_test}
	all_clean all_all_clean ${makedep_category}_all_clean: ${makedep_target}_clean
	all_distclean all_all_distclean ${makedep_category}_all_distclean: ${makedep_target}_distclean
	all_export all_all_export ${makedep_category}_all_export ${makedep_target}_export: ${makedep_export}
	END_OF_RULES

	# Add Forward and Reverse depends
	for dep in ${BDEPENDS}; do
		if ! test -d "${BUILDER_PKGDIR}/${dep}"; then
			die "bad BDEPENDS in package '${package}'"
		elif ! test -f "${BUILDER_PKGDIR}/${dep}/Buildrules"; then
			die "no Buildrules for '${dep}'"
		fi

		target="$(build_makedeps_name "${dep}")"
		echo "${target}_uninstall: ${makedep_target}_uninstall"
		echo "${target}_clean: ${makedep_target}_clean"
		echo "${target}_distclean: ${makedep_target}_distclean"
		echo "${makedep_prep}: ${SYSROOT}/var/db/binpkgs/${dep}"
	done
	unset target
	unset dep

	for dep in ${RDEPENDS}; do
		if ! test -d "${BUILDER_PKGDIR}/${dep}"; then
			die "bad RDEPENDS in package '${package}'"
		elif ! test -f "${BUILDER_PKGDIR}/${dep}/Buildrules"; then
			die "no Buildrules for '${dep}'"
		fi
		echo "${makedep_install}: ${SYSROOT}/var/db/binpkgs/${dep}"
		echo "${makedep_test}: ${BUILDER_TMPDIR}/${dep}/.tested"
	done
	unset dep

	# Depend on updates to 'builder'
	for index in ".git/modules/scripts" "scripts/.git"; do
		if test -f "${BUILDER_TOPDIR}/${index}/index"; then
			echo "${makedep_prep}: ${BUILDER_TOPDIR}/${index}/index"
			break
		fi
	done
	unset index

	# Depend on the build rules
	echo "${makedep_prep}: ${RULESFILE}"
	if test -f "${BUILDER_PKGDIR}/${CATEGORY}/.buildrules"; then
		echo "${makedep_prep}: ${BUILDER_PKGDIR}/${CATEGORY}/.buildrules"
	fi

	# Depend on included files
	for config in ${BUILDER_INCLUDED}; do
		if ! test -f "${BUILDER_CFGDIR}/${config}"; then
			die "include does not exist '${file}'"
		fi
		echo "${makedep_prep}: ${BUILDER_CFGDIR}/${config}"
	done
	unset config

	# Depend on extra source files from ${F}
	for file in ${EXTRA_SOURCES}; do
		if ! test -f "${F}/${file}"; then
			die "file does not exist '${file}'"
		fi
		echo "${makedep_prep}: ${F}/${file}"
	done
	unset file


	# FIXME there can be strange characters in a URI .. this might not be
	# the best approach in the long term.
	PACKAGE_SOURCES=
	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-url --archive "${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

	if test -e "${makedep_source}"; then
		printf "${makedep_source}:\n"
		printf "all_fetch all_all_fetch ${makedep_target}_fetch:\n"
		printf "${makedep_prep}: ${makedep_target}_fetch\n\t@build-make-prep '${package}'\n"
		printf "${makedep_target}_fetch:\n\t@rm -f ${makedep_prep}\n"
	else
		# Depend on all listed patches
		for patch in ${PATCHES}; do
			patch="${F}/${NAME}-${VERSION}-${patch}.patch"
			if ! test -f "${patch}"; then
				die "patch does not exist '${patch}'"
			fi
			echo "${makedep_prep}: ${patch}"
		done
		unset patch

		printf "${makedep_source}: ${PACKAGE_SOURCES}\n\t@build-make-source '${package}'\n"
		printf "${makedep_prep}: ${PACKAGE_SOURCES}\n\t@build-make-prep '${package}'\n"
		printf "all_fetch all_all_fetch ${makedep_target}_fetch: ${PACKAGE_SOURCES}\n"
	fi

	##
	# Produce the various build commands
	printf "${makedep_compile}: ${makedep_prep}\n\t@build-make-compile '${package}'\n"
	printf "${makedep_package}: ${makedep_compile}\n\t@build-make-package '${package}'\n"
	printf "${makedep_install}: ${makedep_package}\n\t@build-make-install '${package}'\n"
	printf "${makedep_test}: ${makedep_install}\n\t@build-make-test '${package}'\n"
	printf "${makedep_export}: ${makedep_install}\n\t@build-make-export '${package}'\n"
	printf "${makedep_target}_uninstall:\n\t@build-make-uninstall '${package}'\n"
	printf "${makedep_target}_clean:\n\t@build-make-clean '${package}'\n"
	printf "${makedep_target}_distclean:\n\t@build-make-distclean '${package}'\n"

	##
	# 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="fetch_$(build-url --archive "${url}"|sed 's/[+.-]/_/g')"
			if test -z "$(eval echo -n "\$${var}")"; then
				eval "${var}='${url}'"
				echo "${BUILDER_SRCDIR}/$(build-url --archive "${url}"):"
				echo "	@build-make-fetch \"${url}\""
			fi
			;;
		esac
	done

	printf '# End of %s\n\n' "${CATEGORY}/${NAME}"
done >> "${BUILDER_MAKEFILE}"

# vim: filetype=sh