1#!/bin/bash -e
2
3if [ "$ACTION" = installhdrs ]; then exit 0; fi
4if [ "${PLATFORM_NAME/iphone/}" != "${PLATFORM_NAME}" ]; then exit 0; fi
5
6UNIFDEF_FLAGS=`${SRCROOT}/xcodescripts/generate_features.pl --unifdef`
7MANPAGES_LIST="${SRCROOT}/man/manpages.lst"
8FILES=$(find -E ${SRCROOT} -regex '.*/[^.]+\.[0-9]' -type f)
9
10cat ${MANPAGES_LIST} | grep -v -E '(^#|^\s*$)' | while read first solid rest; do
11	SOURCE=$(grep -E "/${first}$"<<EOF
12${FILES}
13EOF
14)
15
16	# This is a subshell, the real exit is after the loop.
17	if [ -z "${SOURCE}" ]; then
18		echo "Error: ${first} not found"
19		exit 1
20	fi
21
22	SECTION=$(echo ${first} | tail -c 2)
23
24	DESTDIR=${DSTROOT}/usr/share/man/man${SECTION}
25	DEST=${DESTDIR}/${solid}
26
27	mkdir -p ${DSTROOT}/usr/share/man/man${SECTION}
28
29	# cat is used to keep bash happy, unifdef returns non-zero in some success cases
30	cmd="unifdef -t ${UNIFDEF_FLAGS} < ${SOURCE} | cat > ${DEST}"
31	echo ${cmd}
32	eval ${cmd}
33
34	for link in ${rest}; do 
35		cmd="ln -sf ${first} ${DESTDIR}/${link}"
36		echo ${cmd}
37		eval ${cmd}
38	done
39done
40
41if [ $? -ne 0 ]; then
42	echo "Exiting due to previous error(s)."
43	exit 1
44fi
45
46# grrr, uuid special case
47for page in libuuid.3 uuid_clear.3 uuid_compare.3 uuid_copy.3 uuid_generate.3 uuid_is_null.3 uuid_parse.3 uuid_unparse.3; do
48	SECTION=$(echo ${page} | tail -c 2)
49	DESTDIR=${DSTROOT}/usr/share/man/man${SECTION}
50	DEST=${DESTDIR}/${page}
51
52	# libuuid.3 -> uuid.3
53	[[ "${page}" == "libuuid.3" ]] && DEST=${DESTDIR}/uuid.3
54
55	sed -f ${SRCROOT}/uuid/uuidman.sed ${SRCROOT}/uuid/uuidsrc/${page}.in > ${DEST}
56done
57
58# and because uuid pages are special cased, so are the links
59for link in uuid_generate_random.3 uuid_generate_time.3; do
60	SECTION=$(echo ${link} | tail -c 2)
61	ln -sf uuid_generate.3 ${DSTROOT}/usr/share/man/man${SECTION}/${link}
62done
63
64for link in uuid_unparse_lower.3 uuid_unparse_upper.3; do
65	SECTION=$(echo ${link} | tail -c 2)
66	ln -sf uuid_unparse.3 ${DSTROOT}/usr/share/man/man${SECTION}/${link}
67done
68