summaryrefslogtreecommitdiffhomepage
path: root/build/pkg.build
blob: ddfea6950555adf112a1d48e842cfb99642fe8d3 (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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#
# . ./build.vars and set -o errexit -o noglob are assumed.
#

parse_with_pkg_name ${1};
if [ ${PKG_DISABLED:-0} -eq 1 ]; then
	exit 0;
elif ! is_build_script_done fetch; then
	if test_cmd pkg_${PKG_NAME}_fetch; then
		pkg_${PKG_NAME}_fetch;
	else
		if [ "${PKG_URL_TYPE:-wget}" = wget ]; then
			fetch "${PKG_URL}" ${PKG_SHA256SUM};
		else
			fetch_git ${PKG_SUBDIR} ${PKG_URL} ${PKG_GIT_BRANCH};
		fi;
	fi;
	if test_cmd pkg_${PKG_NAME}_fetch_post; then
		pkg_${PKG_NAME}_fetch_post;
	fi;
	set_build_script_done fetch -extract;
fi;
if test_cmd pkg_${PKG_NAME}_finish; then
	pkg_${PKG_NAME}_finish; exit 0;
elif [ "${PKG_URL_TYPE:-wget}" = wget ] &&\
! is_build_script_done extract; then
	secure_rm ${PKG_SUBDIR};
	if [ ${PKG_SUBDIR_CREATE:-0} -eq 1 ]; then
		insecure_mkdir ${PKG_SUBDIR};
	fi;
	if [ "${PKG_FNAME##*.tar.}" = "bz2" ]; then
		bunzip2 -d < ${DLCACHEDIR}/${PKG_FNAME} | tar ${PKG_SUBDIR_CREATE:+-C ${PKG_SUBDIR}} -xf -;
	elif [ "${PKG_FNAME##*.tar.}" = "gz" ]; then
		gunzip -d < ${DLCACHEDIR}/${PKG_FNAME} | tar ${PKG_SUBDIR_CREATE:+-C ${PKG_SUBDIR}} -xf -;
	elif [ "${PKG_FNAME##*.tar.}" = "xz" ]; then
		xz -d < ${DLCACHEDIR}/${PKG_FNAME} | tar ${PKG_SUBDIR_CREATE:+-C ${PKG_SUBDIR}} -xf -;
	elif [ "${PKG_FNAME##*.t}" = "bz2" ]; then
		bunzip2 -d < ${DLCACHEDIR}/${PKG_FNAME} | tar ${PKG_SUBDIR_CREATE:+-C ${PKG_SUBDIR}} -xf -;
	elif [ "${PKG_FNAME##*.t}" = "gz" ]; then
		gunzip -d < ${DLCACHEDIR}/${PKG_FNAME} | tar ${PKG_SUBDIR_CREATE:+-C ${PKG_SUBDIR}} -xf -;
	elif [ "${PKG_FNAME##*.t}" = "xz" ]; then
		xz -d < ${DLCACHEDIR}/${PKG_FNAME} | tar ${PKG_SUBDIR_CREATE:+-C ${PKG_SUBDIR}} -xf -;
	else
		tar ${PKG_SUBDIR_CREATE:+-C ${PKG_SUBDIR}} -xf ${DLCACHEDIR}/${PKG_FNAME};
	fi;
	if test_cmd pkg_${PKG_NAME}_extract_post; then
		pkg_${PKG_NAME}_extract_post;
	fi;
	set_build_script_done extract -build_dir;
fi;
if [ -z "${PKG_BUILD_DIR}" ]; then
	set_build_dir ${PKG_SUBDIR} ${PKG_BUILD_TYPE:-native};
fi;
if ! is_build_script_done build_dir; then
	[ "${PKG_SUBDIR}" != "${PKG_BUILD_DIR}" ] &&\
		secure_rm ${PKG_BUILD_DIR};
		insecure_mkdir ${PKG_BUILD_DIR};
	set_build_script_done build_dir -patch_pre;
fi;
if ! is_build_script_done patch_pre; then
	for __ in 										\
			${MIDIPIX_BUILD_PWD}/patches/${PKG_SUBDIR}_pre.local.patch			\
			${MIDIPIX_BUILD_PWD}/patches/${PKG_SUBDIR}_pre.local@${BUILD_HNAME}.patch	\
			${MIDIPIX_BUILD_PWD}/../${PKG_SUBDIR}_pre.local.patch				\
			${MIDIPIX_BUILD_PWD}/../${PKG_SUBDIR}_pre.local@${BUILD_HNAME}.patch; do
		if [ -r "${__}" ]; then
			patch -b -d ${PKG_SUBDIR} -p1 < ${__};
		fi;
	done; unset __;
	if test_cmd pkg_${PKG_NAME}_patch_pre_post; then
		pkg_${PKG_NAME}_patch_pre_post;
	fi;
	set_build_script_done patch_pre -autoconf;
fi;
if [ -e ${PKG_SUBDIR}/configure -o							\
     -e ${PKG_SUBDIR}/configure.ac -o							\
     -e ${PKG_SUBDIR}/configure.in -o							\
     -e ${PKG_SUBDIR}/config.guess ]							\
&& ! is_build_script_done autoconf; then
	find ${PKG_SUBDIR} -name config.sub						\
		-exec echo mv -- {} {}.orig \;						\
		-exec mv -- {} {}.orig \;						\
		-exec echo install -m 0700 ${MIDIPIX_BUILD_PWD}/etc/config.sub {} \;	\
		-exec install -m 0700 ${MIDIPIX_BUILD_PWD}/etc/config.sub {} \;;
	if [ -e ${PKG_SUBDIR}/configure.ac -a						\
	   ! -e ${PKG_SUBDIR}/configure ]; then
		if [ -x ${PKG_SUBDIR}/autogen.sh ]; then
			for __ in ${PKG_SUBDIR}/build-aux ${PKG_SUBDIR}; do
				if [ -e ${__} ]; then
					echo install -m 0700				\
						${MIDIPIX_BUILD_PWD}/etc/config.sub 	\
						${__}/config.sub;
					install -m 0700					\
						${MIDIPIX_BUILD_PWD}/etc/config.sub	\
						${__}/config.sub;
					break;
				fi;
			done;
			(cd ${PKG_SUBDIR} && ./autogen.sh) || exit 1;
		else
			(cd ${PKG_SUBDIR} && autoconf) || exit 1;
		fi;
	fi;
	for __ in ${PKG_BUILD_DIR} ${PKG_CONFIG_CACHE_EXTRA}; do
		echo cp -- ${MIDIPIX_BUILD_PWD}/etc/config.cache ${__}/;
		cp -- ${MIDIPIX_BUILD_PWD}/etc/config.cache ${__}/;
	done;
	set_build_script_done autoconf -patch;
fi;
if ! is_build_script_done patch; then
	for __patch_fname in 									\
			${MIDIPIX_BUILD_PWD}/patches/${PKG_SUBDIR}.local.patch			\
			${MIDIPIX_BUILD_PWD}/patches/${PKG_SUBDIR}.local@${BUILD_HNAME}.patch	\
			${MIDIPIX_BUILD_PWD}/../${PKG_SUBDIR}.local.patch			\
			${MIDIPIX_BUILD_PWD}/../${PKG_SUBDIR}.local@${BUILD_HNAME}.patch; do
		if [ -r "${__patch_fname}" ]; then
			patch -b -d ${PKG_SUBDIR} -p1 < ${__patch_fname};
		fi;
	done; unset __patch_fname;
	if test_cmd pkg_${PKG_NAME}_patch_post; then
		pkg_${PKG_NAME}_patch_post;
	fi;
	set_build_script_done patch -configure;
fi;
PKG_SUBDIR_PATH=${PWD}/${PKG_SUBDIR#/};
if [ -z "${PKG_CONFIGURE}" ]; then
	PKG_CONFIGURE=${PKG_SUBDIR_PATH}/configure;
else
	PKG_CONFIGURE=${PWD}/${PKG_CONFIGURE#/};
fi;
cd ${PKG_BUILD_DIR};
if [ "${PKG_BUILD_TYPE}" = "host" ]; then
	export AR=ar;
	export CC=gcc;
	export RANLIB=ranlib;
else
	export AR=${PKG_TARGET}-ar;
	export CC=${PKG_TARGET}-gcc;
	export RANLIB=${PKG_TARGET}-ranlib;
fi;
if [ -x ${PKG_CONFIGURE} ]; then
	export CFLAGS_FOR_BUILD="${HOST_TOOLCHAIN_CFLAGS_CONFIGURE_DEFAULT}";
fi;
if [ -x ${PKG_CONFIGURE} ]\
&& ! is_build_script_done configure; then
	if test_cmd pkg_${PKG_NAME}_configure; then
		pkg_${PKG_NAME}_configure;
	else
		if test_cmd pkg_${PKG_NAME}_configure_pre; then
			pkg_${PKG_NAME}_configure_pre;
		fi;
		CFLAGS="${PKG_CFLAGS_CONFIGURE}${PKG_CFLAGS_CONFIGURE_EXTRA:+ ${PKG_CFLAGS_CONFIGURE_EXTRA}}"\
		LDFLAGS="${PKG_LDFLAGS_CONFIGURE}${PKG_LDFLAGS_CONFIGURE_EXTRA:+ ${PKG_LDFLAGS_CONFIGURE_EXTRA}}"\
		${PKG_CONFIGURE}								\
			${PKG_CONFIGURE_ARGS} ${PKG_CONFIGURE_ARGS_EXTRA} ${PKG_CONFIGURE_ARGS_EXTRA_DEBUG};
	fi;
	set_build_script_done configure clean -build;
else
	__no_autoconf=1;
	set_build_script_done clean -build;
fi;
if ! is_build_script_done clean; then
	make clean;
	set_build_script_done clean -build;
fi;
if ! is_build_script_done build; then
	if test_cmd pkg_${PKG_NAME}_build; then
		pkg_${PKG_NAME}_build;
	elif [ -n "${PKG_BUILD_CMDLINE}" ]; then
		${PKG_BUILD_CMDLINE};
	else
		if [ "${PKG_SLIBTOOL}" != "default" ]; then
			export MAKE="make LIBTOOL=${PKG_SLIBTOOL:-slibtool}";
		fi;
		# N.B.	We only specify CC= here if the current package does not use GNU
		#	autoconf as it often abuses it by appending -std={gnu99,...} to it
		#	instead of amending CFLAGS.
		run_cmd_unsplit make							\
			${PKG_MAKEFLAGS_BUILD}						\
			${PKG_MAKEFLAGS_BUILD_EXTRA}					\
			AR=${AR} ${__no_autoconf:+CC=${CC}} RANLIB=${RANLIB}		\
			"${PKG_CFLAGS_BUILD:+CFLAGS=${PKG_CFLAGS_BUILD}}"		\
			"${CFLAGS_FOR_BUILD:+CFLAGS_FOR_BUILD=${CFLAGS_FOR_BUILD}}"	\
			"${PKG_CFLAGS_BUILD_EXTRA:+CFLAGS+=${PKG_CFLAGS_BUILD_EXTRA}}"	\
			"${PKG_LDFLAGS_BUILD:+LDFLAGS=${PKG_LDFLAGS_BUILD}}"		\
			"${PKG_LDFLAGS_BUILD_EXTRA:+LDFLAGS+=${PKG_LDFLAGS_BUILD_EXTRA}}";
		unset __no_autoconf;
	fi;
	set_build_script_done build -install;
fi;
if ! is_build_script_done install; then
	if test_cmd pkg_${PKG_NAME}_install; then
		pkg_${PKG_NAME}_install;
	else
		if [ ${PKG_NO_MAKE_INSTALL:-0} -eq 0 ]; then
			run_cmd_unsplit make					\
				${PKG_MAKEFLAGS_INSTALL}			\
				${PKG_MAKEFLAGS_INSTALL_EXTRA}			\
				AR=${AR} CC=${CC} RANLIB=${RANLIB}		\
				"${PKG_CFLAGS_INSTALL:+CFLAGS=${PKG_CFLAGS_INSTALL}}"				\
				"${PKG_CFLAGS_INSTALL_EXTRA:+CFLAGS+=${PKG_CFLAGS_INSTALL_EXTRA}}"		\
				"${PKG_LDFLAGS_INSTALL:+LDFLAGS=${PKG_LDFLAGS_INSTALL}}"			\
				"${PKG_LDFLAGS_INSTALL_EXTRA:+LDFLAGS+=${PKG_LDFLAGS_INSTALL_EXTRA}}"		\
				"${PKG_RANLIB_INSTALL:+RANLIB=${PKG_RANLIB_INSTALL}}"				\
				${PKG_INSTALL_TARGET:=install};
			if [ -n "${PKG_PREFIX_EXTRA}" ]; then
				run_cmd_unsplit make				\
					${PKG_MAKEFLAGS_INSTALL}		\
					${PKG_MAKEFLAGS_INSTALL_EXTRA}		\
					AR=${AR} CC=${CC} RANLIB=${RANLIB}	\
					"${PKG_CFLAGS_INSTALL:+CFLAGS=${PKG_CFLAGS_INSTALL}}"			\
					"${PKG_CFLAGS_INSTALL_EXTRA:+CFLAGS+=${PKG_CFLAGS_INSTALL_EXTRA}}"	\
					"${PKG_LDFLAGS_INSTALL:+LDFLAGS=${PKG_LDFLAGS_INSTALL}}"		\
					"${PKG_LDFLAGS_INSTALL_EXTRA:+LDFLAGS+=${PKG_LDFLAGS_INSTALL_EXTRA}}"	\
					"${PKG_RANLIB_INSTALL:+RANLIB=${PKG_RANLIB_INSTALL}}"			\
					${PKG_INSTALL_TARGET_EXTRA:=install}	\
					DESTDIR=${PKG_PREFIX_EXTRA};
			fi;
		fi;
		if test_cmd pkg_${PKG_NAME}_install_post; then
			pkg_${PKG_NAME}_install_post;
		fi;
	fi;
	if [ -d ${PKG_PREFIX}/lib ]; then
		for __ in $(find ${PKG_PREFIX}/lib -type f -name \*.la); do
			secure_rm ${__};
		done;
	fi;
	if [ -n "${PKG_INSTALL_FILES}" ]; then
		(set -- ${PKG_INSTALL_FILES};
		while [ ${#} -gt 0 ]; do
		case "${1}" in
		@*=*)
			__ln_target="${1%=*}";
			__ln_target="${__ln_target#@}";
			__ln_fname="${1#*=}";
			echo ln -sf -- ${__ln_target} ${PKG_PREFIX}/${__ln_fname};
			ln -sf -- ${__ln_target} ${PKG_PREFIX}/${__ln_fname};
			;;
		/=*)
			__mkdir_fname="${1#/=}";
			insecure_mkdir ${PKG_PREFIX}/${__mkdir_fname};
			;;
		*)
			__file_fname_src="${1%=*}";
			__file_fname_dst="${1#*=}";
			echo cp -pP -- ${__file_fname_src} ${PKG_PREFIX}/${__file_fname_dst};
			cp -pP -- ${__file_fname_src} ${PKG_PREFIX}/${__file_fname_dst};
			;;
		esac; shift;
		done);
	fi;
	if test_cmd perk && test_cmd ${PKG_TARGET}-dlltool; then
		for __so_fname in							\
			$(find	\( -name "*.so"						\
				-or -name "*.so.[0-9]"					\
				-or -name "*.so.[0-9].[0-9]"				\
				-or -name "*.so.[0-9].[0-9].[0-9]" \) -printf '%P\n');
		do
			if [ \( -e ${__so_fname%.so}.lib.a \) -o			\
			     \( ! -e ${PKG_PREFIX}/lib/$(basename ${__so_fname}) \) ];
			then
				continue;
			else
				__so_name="${__so_fname%.so}";
				echo perk -epdlltool ${__so_fname} \> ${__so_fname%.so}.def;
				perk -epdlltool ${__so_fname} > ${__so_fname%.so}.def;
				echo ${PKG_TARGET}-dlltool -l ${__so_fname%.so}.lib.a	\
					-D ${__so_fname} -d ${__so_fname%.so}.def;
				${PKG_TARGET}-dlltool -l ${__so_fname%.so}.lib.a	\
					-D ${__so_fname} -d ${__so_fname%.so}.def;
				echo cp -- ${__so_fname%.so}.lib.a "${PKG_PREFIX}/lib";
				cp -- ${__so_fname%.so}.lib.a "${PKG_PREFIX}/lib";
			fi;
		done;
	fi;
	set_build_script_done install -finish;
fi;
set_build_script_done finish;

# vim:filetype=sh