summaryrefslogtreecommitdiffstats
path: root/src/3/ppt-mkpkgs
blob: 518e1e3fcaaea7245040d8347bd1d06feb054f5a (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
#!/bin/sh

set -eu

PLAT=
MAKE_SUBSTVARS=false

substvars=''

info()
{
	local fmt="${1}"
	shift 1

	printf "ppt-mkpkgs: ${fmt}\n" "${@}"
}

make_common_pkg()
{
	# Make "-common" package to provide source package documentation files.
	mkdir -p "config-${PLAT}-common.pkg"
	cat >"config-${PLAT}-common.pkg/control" <<-EOF
		# Generated by ppt-mkpkgs.  Do not edit.
		Architecture: all
		Platform: all
		Section: share
		Description: "${PLAT}" platform configuration - common files
		EOF
	>"config-${PLAT}-common.pkg/docs"
	info 'Metadata for package "%s" generated.' "config-${PLAT}-common"
}

make_base_pkg()
{
	# Make a "config-base" package to depend on packages to be automatically
	# installed.
	mkdir -p "config-base.pkg"
	cat >"config-base.pkg/control" <<-EOF
		# Generated by ppt-mkpkgs.  Do not edit.
		Architecture: all
		Platform: ${PLAT}
		Section: share
		Essential: yes
		Depends: config-${PLAT}-common (= \${Binary-Version}),
		 \${Config-Base-Depends}
		Description: "${PLAT}" platform configuration - base package
		EOF
	if ${MAKE_SUBSTVARS}; then
		printf 'Config-Base-Depends:\n' >>'substvars'
	fi
	info 'Metadata for package "%s" generated.' "config-base"
}

make_build_time_pkgs()
{
	local pkg_ver=
	local pkg=
	local var=

	# Make each config-*-* package.
	for pkg_ver in src/build/*; do
		[ -d "${pkg_ver}" ] || continue
		pkg_ver="${pkg_ver#src/build/}"
		pkg="${pkg_ver%_*}"
		var="$(printf '%s' "${pkg}" | tr -C 'A-Za-z0-9-' '-')"
		substvars="${substvars} Config-${var}-Depends"
		mkdir -p "config-${pkg}-${PLAT}.pkg"
		cat >"config-${pkg}-${PLAT}.pkg/control" <<-EOF
			# Generated by ppt-mkpkgs.  Do not edit.
			Architecture: all
			Platform: all
			Section: dev
			Depends: config-${PLAT}-common (= \${Binary-Version}),
			 \${Config-${var}-Depends}
			Description: "${PLAT}" platform configuration for ${pkg}
			EOF
		if ${MAKE_SUBSTVARS}; then
			printf 'Config-%s-Depends:\n' "${var}" >>'substvars'
		fi
		info 'Metadata for package "%s" generated.' \
			"config-${pkg}-${PLAT}"
	done
}

make_run_time_pkgs()
{
	local pkg=
	local var=

	# Make each config-* package.
	for pkg in src/run/*; do
		[ -d "${pkg}" ] || continue
		pkg="${pkg#src/run/}"
		var="$(printf '%s' "${pkg}" | tr -C 'A-Za-z0-9-' '-')"
		substvars="${substvars} Config-${var}-Depends"
		mkdir -p "config-${pkg}.pkg"
		cat >"config-${pkg}.pkg/control" <<-EOF
			# Generated by ppt-mkpkgs.  Do not edit.
			Architecture: all
			Platform: ${PLAT}
			Section: share
			Depends: config-${PLAT}-common (= \${Binary-Version}),
			 \${Config-${var}-Depends}
			Description: "${PLAT}" platform configuration for ${pkg}
			EOF
		if ${MAKE_SUBSTVARS}; then
			printf 'Config-%s-Depends:\n' "${var}" >>'substvars'
		fi
		info 'Metadata for package "%s" generated.' \
			"config-${pkg}"
	done
}

main()
{
	local var=

	PLAT="$(sed '1{s/^config-\([^ ][^ ]*\) (.*$/\1/;};1!q;' changelog)"

	if ! [ -e 'substvars' ]; then
		MAKE_SUBSTVARS=true
		printf '# Generated by ppt-mkpkgs.  DO EDIT.\n' >'substvars'
	fi
	make_common_pkg
	make_base_pkg
	make_build_time_pkgs
	make_run_time_pkgs
	info 'Consider adding "opkbuild (>= 4.2.0)" to Build-Depends'
	if ${MAKE_SUBSTVARS}; then
		info 'Stub "substvars" file generated.  Set variables as '$(: \
			)'needed.'
	else
		info 'Ensure "substvars" contains the following variables:'
		for var in ${substvars}; do
			info '  * %s' "${var}"
		done
	fi
}

main "${@}"