1#!/bin/sh
2
3set -u
4set -e
5trap onexit INT
6trap onexit TERM
7trap onexit EXIT
8
9TMPDIR=
10
11onexit()
12{
13	if [ ! "$TMPDIR" = "" ]; then
14		rm -rf $TMPDIR
15	fi
16}
17
18usage()
19{
20	echo "$0 [-build32 [32-bit build dir]] [-buildarmv6 [ARMv6 build dir]] [-buildarmv7 [ARMv7 build dir]] [-buildarmv7s [ARMv7s build dir] [-buildarmv8 [ARMv8 build dir]] [-lipo [path to lipo]]"
21	exit 1
22}
23
24PACKAGE_NAME=@PKGNAME@
25VERSION=@VERSION@
26BUILD=@BUILD@
27SRCDIR=@abs_top_srcdir@
28BUILDDIR32=@abs_top_srcdir@/osxx86
29BUILD32=0
30BUILDDIRARMV6=@abs_top_srcdir@/iosarmv6
31BUILDARMV6=0
32BUILDDIRARMV7=@abs_top_srcdir@/iosarmv7
33BUILDARMV7=0
34BUILDDIRARMV7S=@abs_top_srcdir@/iosarmv7s
35BUILDARMV7S=0
36BUILDDIRARMV8=@abs_top_srcdir@/iosarmv8
37BUILDARMV8=0
38WITH_JAVA=@WITH_JAVA@
39LIPO=lipo
40
41PREFIX=%{__prefix}
42BINDIR=%{__bindir}
43DOCDIR=%{__docdir}
44LIBDIR=%{__libdir}
45
46while [ $# -gt 0 ]; do
47	case $1 in
48	-h*)             usage 0                   ;;
49	-build32)
50		BUILD32=1
51		if [ $# -gt 1 ]; then
52			if [[ ! "$2" =~ -.* ]]; then
53				BUILDDIR32=$2;  shift
54			fi
55		fi
56		;;
57	-buildarmv6)
58		BUILDARMV6=1
59		if [ $# -gt 1 ]; then
60			if [[ ! "$2" =~ -.* ]]; then
61				BUILDDIRARMV6=$2;  shift
62			fi
63		fi
64		;;
65	-buildarmv7)
66		BUILDARMV7=1
67		if [ $# -gt 1 ]; then
68			if [[ ! "$2" =~ -.* ]]; then
69				BUILDDIRARMV7=$2;  shift
70			fi
71		fi
72		;;
73	-buildarmv7s)
74		BUILDARMV7S=1
75		if [ $# -gt 1 ]; then
76			if [[ ! "$2" =~ -.* ]]; then
77				BUILDDIRARMV7S=$2;  shift
78			fi
79		fi
80		;;
81	-buildarmv8)
82		BUILDARMV8=1
83		if [ $# -gt 1 ]; then
84			if [[ ! "$2" =~ -.* ]]; then
85				BUILDDIRARMV8=$2;  shift
86			fi
87		fi
88		;;
89	-lipo)
90		if [ $# -gt 1 ]; then
91			if [[ ! "$2" =~ -.* ]]; then
92				LIPO=$2;  shift
93			fi
94		fi
95		;;
96	esac
97	shift
98done
99
100if [ -f $PACKAGE_NAME-$VERSION.dmg ]; then
101	rm -f $PACKAGE_NAME-$VERSION.dmg
102fi
103
104umask 022
105TMPDIR=`mktemp -d /tmp/$PACKAGE_NAME-build.XXXXXX`
106PKGROOT=$TMPDIR/pkg/Package_Root
107mkdir -p $PKGROOT
108make install DESTDIR=$PKGROOT docdir=/Library/Documentation/$PACKAGE_NAME \
109	exampledir=/Library/Documentation/$PACKAGE_NAME
110rm -f $PKGROOT$LIBDIR/*.la
111
112if [ "$PREFIX" = "/opt/libjpeg-turbo" -a "$DOCDIR" = "/opt/libjpeg-turbo/doc" ]; then
113	ln -fs /Library/Documentation/$PACKAGE_NAME $PKGROOT$DOCDIR
114fi
115
116if [ $BUILD32 = 1 ]; then
117	if [ ! -d $BUILDDIR32 ]; then
118		echo ERROR: 32-bit build directory $BUILDDIR32 does not exist
119		exit 1
120	fi
121	if [ ! -f $BUILDDIR32/Makefile ]; then
122		echo ERROR: 32-bit build directory $BUILDDIR32 is not configured
123		exit 1
124	fi
125	mkdir -p $TMPDIR/dist.x86
126	pushd $BUILDDIR32
127	make install DESTDIR=$TMPDIR/dist.x86
128	popd
129	if [ ! -h $TMPDIR/dist.x86/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.dylib -a \
130		! -h $PKGROOT/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.dylib ]; then
131		$LIPO -create \
132			-arch i386 $TMPDIR/dist.x86/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.dylib \
133			-arch x86_64 $PKGROOT/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.dylib \
134			-output $PKGROOT/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.dylib
135	elif [ ! -h $TMPDIR/dist.x86/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.0.@SO_MINOR_VERSION@.dylib -a \
136		! -h $PKGROOT/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.0.@SO_MINOR_VERSION@.dylib ]; then
137		$LIPO -create \
138			-arch i386 $TMPDIR/dist.x86/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.0.@SO_MINOR_VERSION@.dylib \
139			-arch x86_64 $PKGROOT/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.0.@SO_MINOR_VERSION@.dylib \
140			-output $PKGROOT/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.0.@SO_MINOR_VERSION@.dylib
141	fi
142	$LIPO -create \
143		-arch i386 $TMPDIR/dist.x86/$LIBDIR/libjpeg.a \
144		-arch x86_64 $PKGROOT/$LIBDIR/libjpeg.a \
145		-output $PKGROOT/$LIBDIR/libjpeg.a
146	$LIPO -create \
147		-arch i386 $TMPDIR/dist.x86/$LIBDIR/libturbojpeg.0.dylib \
148		-arch x86_64 $PKGROOT/$LIBDIR/libturbojpeg.0.dylib \
149		-output $PKGROOT/$LIBDIR/libturbojpeg.0.dylib
150	$LIPO -create \
151		-arch i386 $TMPDIR/dist.x86/$LIBDIR/libturbojpeg.a \
152		-arch x86_64 $PKGROOT/$LIBDIR/libturbojpeg.a \
153		-output $PKGROOT/$LIBDIR/libturbojpeg.a
154	$LIPO -create \
155		-arch i386 $TMPDIR/dist.x86/$BINDIR/cjpeg \
156		-arch x86_64 $PKGROOT/$BINDIR/cjpeg \
157		-output $PKGROOT/$BINDIR/cjpeg
158	$LIPO -create \
159		-arch i386 $TMPDIR/dist.x86/$BINDIR/djpeg \
160		-arch x86_64 $PKGROOT/$BINDIR/djpeg \
161		-output $PKGROOT/$BINDIR/djpeg
162	$LIPO -create \
163		-arch i386 $TMPDIR/dist.x86/$BINDIR/jpegtran \
164		-arch x86_64 $PKGROOT/$BINDIR/jpegtran \
165		-output $PKGROOT/$BINDIR/jpegtran
166	$LIPO -create \
167		-arch i386 $TMPDIR/dist.x86/$BINDIR/tjbench \
168		-arch x86_64 $PKGROOT/$BINDIR/tjbench \
169		-output $PKGROOT/$BINDIR/tjbench
170	$LIPO -create \
171		-arch i386 $TMPDIR/dist.x86/$BINDIR/rdjpgcom \
172		-arch x86_64 $PKGROOT/$BINDIR/rdjpgcom \
173		-output $PKGROOT/$BINDIR/rdjpgcom
174	$LIPO -create \
175		-arch i386 $TMPDIR/dist.x86/$BINDIR/wrjpgcom \
176		-arch x86_64 $PKGROOT/$BINDIR/wrjpgcom \
177		-output $PKGROOT/$BINDIR/wrjpgcom
178
179fi
180
181if [ $BUILDARMV6 = 1 ]; then
182	if [ ! -d $BUILDDIRARMV6 ]; then
183		echo ERROR: ARMv6 build directory $BUILDDIRARMV6 does not exist
184		exit 1
185	fi
186	if [ ! -f $BUILDDIRARMV6/Makefile ]; then
187		echo ERROR: ARMv6 build directory $BUILDDIRARMV6 is not configured
188		exit 1
189	fi
190	mkdir -p $TMPDIR/dist.armv6
191	pushd $BUILDDIRARMV6
192	make install DESTDIR=$TMPDIR/dist.armv6
193	popd
194	if [ ! -h $TMPDIR/dist.armv6/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.dylib -a \
195		! -h $PKGROOT/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.dylib ]; then
196		$LIPO -create \
197			$PKGROOT/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.dylib \
198			-arch arm $TMPDIR/dist.armv6/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.dylib \
199			-output $PKGROOT/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.dylib
200	elif [ ! -h $TMPDIR/dist.armv6/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.0.@SO_MINOR_VERSION@.dylib -a \
201		! -h $PKGROOT/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.0.@SO_MINOR_VERSION@.dylib ]; then
202		$LIPO -create \
203			$PKGROOT/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.0.@SO_MINOR_VERSION@.dylib \
204			-arch arm $TMPDIR/dist.armv6/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.0.@SO_MINOR_VERSION@.dylib \
205			-output $PKGROOT/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.0.@SO_MINOR_VERSION@.dylib
206	fi
207	$LIPO -create \
208		$PKGROOT/$LIBDIR/libjpeg.a \
209		-arch arm $TMPDIR/dist.armv6/$LIBDIR/libjpeg.a \
210		-output $PKGROOT/$LIBDIR/libjpeg.a
211	$LIPO -create \
212		$PKGROOT/$LIBDIR/libturbojpeg.0.dylib \
213		-arch arm $TMPDIR/dist.armv6/$LIBDIR/libturbojpeg.0.dylib \
214		-output $PKGROOT/$LIBDIR/libturbojpeg.0.dylib
215	$LIPO -create \
216		$PKGROOT/$LIBDIR/libturbojpeg.a \
217		-arch arm $TMPDIR/dist.armv6/$LIBDIR/libturbojpeg.a \
218		-output $PKGROOT/$LIBDIR/libturbojpeg.a
219	$LIPO -create \
220		$PKGROOT/$BINDIR/cjpeg \
221		-arch arm $TMPDIR/dist.armv6/$BINDIR/cjpeg \
222		-output $PKGROOT/$BINDIR/cjpeg
223	$LIPO -create \
224		$PKGROOT/$BINDIR/djpeg \
225		-arch arm $TMPDIR/dist.armv6/$BINDIR/djpeg \
226		-output $PKGROOT/$BINDIR/djpeg
227	$LIPO -create \
228		$PKGROOT/$BINDIR/jpegtran \
229		-arch arm $TMPDIR/dist.armv6/$BINDIR/jpegtran \
230		-output $PKGROOT/$BINDIR/jpegtran
231	$LIPO -create \
232		$PKGROOT/$BINDIR/tjbench \
233		-arch arm $TMPDIR/dist.armv6/$BINDIR/tjbench \
234		-output $PKGROOT/$BINDIR/tjbench
235	$LIPO -create \
236		$PKGROOT/$BINDIR/rdjpgcom \
237		-arch arm $TMPDIR/dist.armv6/$BINDIR/rdjpgcom \
238		-output $PKGROOT/$BINDIR/rdjpgcom
239	$LIPO -create \
240		$PKGROOT/$BINDIR/wrjpgcom \
241		-arch arm $TMPDIR/dist.armv6/$BINDIR/wrjpgcom \
242		-output $PKGROOT/$BINDIR/wrjpgcom
243fi
244
245if [ $BUILDARMV7 = 1 ]; then
246	if [ ! -d $BUILDDIRARMV7 ]; then
247		echo ERROR: ARMv7 build directory $BUILDDIRARMV7 does not exist
248		exit 1
249	fi
250	if [ ! -f $BUILDDIRARMV7/Makefile ]; then
251		echo ERROR: ARMv7 build directory $BUILDDIRARMV7 is not configured
252		exit 1
253	fi
254	mkdir -p $TMPDIR/dist.armv7
255	pushd $BUILDDIRARMV7
256	make install DESTDIR=$TMPDIR/dist.armv7
257	popd
258	if [ ! -h $TMPDIR/dist.armv7/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.dylib -a \
259		! -h $PKGROOT/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.dylib ]; then
260		$LIPO -create \
261			$PKGROOT/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.dylib \
262			-arch arm $TMPDIR/dist.armv7/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.dylib \
263			-output $PKGROOT/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.dylib
264	elif [ ! -h $TMPDIR/dist.armv7/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.0.@SO_MINOR_VERSION@.dylib -a \
265		! -h $PKGROOT/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.0.@SO_MINOR_VERSION@.dylib ]; then
266		$LIPO -create \
267			$PKGROOT/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.0.@SO_MINOR_VERSION@.dylib \
268			-arch arm $TMPDIR/dist.armv7/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.0.@SO_MINOR_VERSION@.dylib \
269			-output $PKGROOT/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.0.@SO_MINOR_VERSION@.dylib
270	fi
271	$LIPO -create \
272		$PKGROOT/$LIBDIR/libjpeg.a \
273		-arch arm $TMPDIR/dist.armv7/$LIBDIR/libjpeg.a \
274		-output $PKGROOT/$LIBDIR/libjpeg.a
275	$LIPO -create \
276		$PKGROOT/$LIBDIR/libturbojpeg.0.dylib \
277		-arch arm $TMPDIR/dist.armv7/$LIBDIR/libturbojpeg.0.dylib \
278		-output $PKGROOT/$LIBDIR/libturbojpeg.0.dylib
279	$LIPO -create \
280		$PKGROOT/$LIBDIR/libturbojpeg.a \
281		-arch arm $TMPDIR/dist.armv7/$LIBDIR/libturbojpeg.a \
282		-output $PKGROOT/$LIBDIR/libturbojpeg.a
283	$LIPO -create \
284		$PKGROOT/$BINDIR/cjpeg \
285		-arch arm $TMPDIR/dist.armv7/$BINDIR/cjpeg \
286		-output $PKGROOT/$BINDIR/cjpeg
287	$LIPO -create \
288		$PKGROOT/$BINDIR/djpeg \
289		-arch arm $TMPDIR/dist.armv7/$BINDIR/djpeg \
290		-output $PKGROOT/$BINDIR/djpeg
291	$LIPO -create \
292		$PKGROOT/$BINDIR/jpegtran \
293		-arch arm $TMPDIR/dist.armv7/$BINDIR/jpegtran \
294		-output $PKGROOT/$BINDIR/jpegtran
295	$LIPO -create \
296		$PKGROOT/$BINDIR/tjbench \
297		-arch arm $TMPDIR/dist.armv7/$BINDIR/tjbench \
298		-output $PKGROOT/$BINDIR/tjbench
299	$LIPO -create \
300		$PKGROOT/$BINDIR/rdjpgcom \
301		-arch arm $TMPDIR/dist.armv7/$BINDIR/rdjpgcom \
302		-output $PKGROOT/$BINDIR/rdjpgcom
303	$LIPO -create \
304		$PKGROOT/$BINDIR/wrjpgcom \
305		-arch arm $TMPDIR/dist.armv7/$BINDIR/wrjpgcom \
306		-output $PKGROOT/$BINDIR/wrjpgcom
307fi
308
309if [ $BUILDARMV7S = 1 ]; then
310	if [ ! -d $BUILDDIRARMV7S ]; then
311		echo ERROR: ARMv7s build directory $BUILDDIRARMV7S does not exist
312		exit 1
313	fi
314	if [ ! -f $BUILDDIRARMV7S/Makefile ]; then
315		echo ERROR: ARMv7s build directory $BUILDDIRARMV7S is not configured
316		exit 1
317	fi
318	mkdir -p $TMPDIR/dist.armv7s
319	pushd $BUILDDIRARMV7S
320	make install DESTDIR=$TMPDIR/dist.armv7s
321	popd
322	if [ ! -h $TMPDIR/dist.armv7s/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.dylib -a \
323		! -h $PKGROOT/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.dylib ]; then
324		$LIPO -create \
325			$PKGROOT/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.dylib \
326			-arch arm $TMPDIR/dist.armv7s/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.dylib \
327			-output $PKGROOT/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.dylib
328	elif [ ! -h $TMPDIR/dist.armv7s/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.0.@SO_MINOR_VERSION@.dylib -a \
329		! -h $PKGROOT/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.0.@SO_MINOR_VERSION@.dylib ]; then
330		$LIPO -create \
331			$PKGROOT/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.0.@SO_MINOR_VERSION@.dylib \
332			-arch arm $TMPDIR/dist.armv7s/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.0.@SO_MINOR_VERSION@.dylib \
333			-output $PKGROOT/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.0.@SO_MINOR_VERSION@.dylib
334	fi
335	$LIPO -create \
336		$PKGROOT/$LIBDIR/libjpeg.a \
337		-arch arm $TMPDIR/dist.armv7s/$LIBDIR/libjpeg.a \
338		-output $PKGROOT/$LIBDIR/libjpeg.a
339	$LIPO -create \
340		$PKGROOT/$LIBDIR/libturbojpeg.0.dylib \
341		-arch arm $TMPDIR/dist.armv7s/$LIBDIR/libturbojpeg.0.dylib \
342		-output $PKGROOT/$LIBDIR/libturbojpeg.0.dylib
343	$LIPO -create \
344		$PKGROOT/$LIBDIR/libturbojpeg.a \
345		-arch arm $TMPDIR/dist.armv7s/$LIBDIR/libturbojpeg.a \
346		-output $PKGROOT/$LIBDIR/libturbojpeg.a
347	$LIPO -create \
348		$PKGROOT/$BINDIR/cjpeg \
349		-arch arm $TMPDIR/dist.armv7s/$BINDIR/cjpeg \
350		-output $PKGROOT/$BINDIR/cjpeg
351	$LIPO -create \
352		$PKGROOT/$BINDIR/djpeg \
353		-arch arm $TMPDIR/dist.armv7s/$BINDIR/djpeg \
354		-output $PKGROOT/$BINDIR/djpeg
355	$LIPO -create \
356		$PKGROOT/$BINDIR/jpegtran \
357		-arch arm $TMPDIR/dist.armv7s/$BINDIR/jpegtran \
358		-output $PKGROOT/$BINDIR/jpegtran
359	$LIPO -create \
360		$PKGROOT/$BINDIR/tjbench \
361		-arch arm $TMPDIR/dist.armv7s/$BINDIR/tjbench \
362		-output $PKGROOT/$BINDIR/tjbench
363	$LIPO -create \
364		$PKGROOT/$BINDIR/rdjpgcom \
365		-arch arm $TMPDIR/dist.armv7s/$BINDIR/rdjpgcom \
366		-output $PKGROOT/$BINDIR/rdjpgcom
367	$LIPO -create \
368		$PKGROOT/$BINDIR/wrjpgcom \
369		-arch arm $TMPDIR/dist.armv7s/$BINDIR/wrjpgcom \
370		-output $PKGROOT/$BINDIR/wrjpgcom
371fi
372
373if [ $BUILDARMV8 = 1 ]; then
374	if [ ! -d $BUILDDIRARMV8 ]; then
375		echo ERROR: ARMv8 build directory $BUILDDIRARMV8 does not exist
376		exit 1
377	fi
378	if [ ! -f $BUILDDIRARMV8/Makefile ]; then
379		echo ERROR: ARMv8 build directory $BUILDDIRARMV8 is not configured
380		exit 1
381	fi
382	mkdir -p $TMPDIR/dist.armv8
383	pushd $BUILDDIRARMV8
384	make install DESTDIR=$TMPDIR/dist.armv8
385	popd
386	if [ ! -h $TMPDIR/dist.armv8/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.dylib -a \
387		! -h $PKGROOT/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.dylib ]; then
388		$LIPO -create \
389			$PKGROOT/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.dylib \
390			-arch arm64 $TMPDIR/dist.armv8/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.dylib \
391			-output $PKGROOT/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.dylib
392	elif [ ! -h $TMPDIR/dist.armv8/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.0.@SO_MINOR_VERSION@.dylib -a \
393		! -h $PKGROOT/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.0.@SO_MINOR_VERSION@.dylib ]; then
394		$LIPO -create \
395			$PKGROOT/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.0.@SO_MINOR_VERSION@.dylib \
396			-arch arm64 $TMPDIR/dist.armv8/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.0.@SO_MINOR_VERSION@.dylib \
397			-output $PKGROOT/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.0.@SO_MINOR_VERSION@.dylib
398	fi
399	$LIPO -create \
400		$PKGROOT/$LIBDIR/libjpeg.a \
401		-arch arm64 $TMPDIR/dist.armv8/$LIBDIR/libjpeg.a \
402		-output $PKGROOT/$LIBDIR/libjpeg.a
403	$LIPO -create \
404		$PKGROOT/$LIBDIR/libturbojpeg.0.dylib \
405		-arch arm64 $TMPDIR/dist.armv8/$LIBDIR/libturbojpeg.0.dylib \
406		-output $PKGROOT/$LIBDIR/libturbojpeg.0.dylib
407	$LIPO -create \
408		$PKGROOT/$LIBDIR/libturbojpeg.a \
409		-arch arm64 $TMPDIR/dist.armv8/$LIBDIR/libturbojpeg.a \
410		-output $PKGROOT/$LIBDIR/libturbojpeg.a
411	$LIPO -create \
412		$PKGROOT/$BINDIR/cjpeg \
413		-arch arm64 $TMPDIR/dist.armv8/$BINDIR/cjpeg \
414		-output $PKGROOT/$BINDIR/cjpeg
415	$LIPO -create \
416		$PKGROOT/$BINDIR/djpeg \
417		-arch arm64 $TMPDIR/dist.armv8/$BINDIR/djpeg \
418		-output $PKGROOT/$BINDIR/djpeg
419	$LIPO -create \
420		$PKGROOT/$BINDIR/jpegtran \
421		-arch arm64 $TMPDIR/dist.armv8/$BINDIR/jpegtran \
422		-output $PKGROOT/$BINDIR/jpegtran
423	$LIPO -create \
424		$PKGROOT/$BINDIR/tjbench \
425		-arch arm64 $TMPDIR/dist.armv8/$BINDIR/tjbench \
426		-output $PKGROOT/$BINDIR/tjbench
427	$LIPO -create \
428		$PKGROOT/$BINDIR/rdjpgcom \
429		-arch arm64 $TMPDIR/dist.armv8/$BINDIR/rdjpgcom \
430		-output $PKGROOT/$BINDIR/rdjpgcom
431	$LIPO -create \
432		$PKGROOT/$BINDIR/wrjpgcom \
433		-arch arm64 $TMPDIR/dist.armv8/$BINDIR/wrjpgcom \
434		-output $PKGROOT/$BINDIR/wrjpgcom
435fi
436
437install_name_tool -id $LIBDIR/libjpeg.@SO_MAJOR_VERSION@.dylib $PKGROOT/$LIBDIR/libjpeg.@SO_MAJOR_VERSION@.dylib
438install_name_tool -id $LIBDIR/libturbojpeg.0.dylib $PKGROOT/$LIBDIR/libturbojpeg.0.dylib
439
440if [ $WITH_JAVA = 1 ]; then
441	ln -fs libturbojpeg.0.dylib $PKGROOT/$LIBDIR/libturbojpeg.jnilib
442fi
443if [ "$PREFIX" = "/opt/libjpeg-turbo" -a "$LIBDIR" = "/opt/libjpeg-turbo/lib" ]; then
444	if [ ! -h $PKGROOT/$PREFIX/lib32 ]; then
445		ln -fs lib $PKGROOT/$PREFIX/lib32
446	fi
447	if [ ! -h $PKGROOT/$PREFIX/lib64 ]; then
448		ln -fs lib $PKGROOT/$PREFIX/lib64
449	fi
450fi
451
452mkdir -p $TMPDIR/pkg
453
454install -m 755 pkgscripts/uninstall $PKGROOT/$BINDIR/
455
456find $PKGROOT -type f | while read file; do xattr -c $file; done
457
458cp $SRCDIR/release/License.rtf $SRCDIR/release/Welcome.rtf $SRCDIR/release/ReadMe.txt $TMPDIR/pkg/
459
460mkdir $TMPDIR/dmg
461pkgbuild --root $PKGROOT --version $VERSION.$BUILD \
462	--identifier com.libjpeg-turbo.libjpeg-turbo $TMPDIR/pkg/$PACKAGE_NAME.pkg
463productbuild --distribution $SRCDIR/release/Distribution.xml \
464	--package-path $TMPDIR/pkg/ --resources $TMPDIR/pkg/ \
465	$TMPDIR/dmg/$PACKAGE_NAME.pkg
466hdiutil create -fs HFS+ -volname $PACKAGE_NAME-$VERSION \
467	-srcfolder "$TMPDIR/dmg" $TMPDIR/$PACKAGE_NAME-$VERSION.dmg
468cp $TMPDIR/$PACKAGE_NAME-$VERSION.dmg .
469
470exit
471