summaryrefslogtreecommitdiff
path: root/source4/heimdal_build/et_compile_wrapper.sh
blob: 939b434767c1ac24157f0cbb7d8386d7e79813d9 (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
#!/bin/sh
#

SELF="$0"
SELFDIR=`dirname "${SELF}"`

DESTDIR="$1"
CMD="$2"
FILE="$3"
SOURCE="$4"
shift 4

test -z "${DESTDIR}" && {
	echo "${SELF}:DESTDIR: '${DESTDIR}'" >&2;
	exit 1;
}

test -z "${CMD}" && {
	echo "${SELF}:CMD: '${CMD}'" >&2;
	exit 1;
}

test -z "${FILE}" && {
	echo "${SELF}:FILE: '${FILE}'" >&2;
	exit 1;
}

test -z "${SOURCE}" && {
	echo "${SELF}:SOURCE: '${SOURCE}'" >&2;
	exit 1;
}

CURDIR="`pwd`"

cd "${DESTDIR}" && {
	# Remove older copies beforehand - MIT's compile_et uses odd permissions for these
	# files, which makes Heimdal's compile_et fail mysteriously when writing to them.
	rm -f `basename "${FILE}" .et`.c
	rm -f `basename "${FILE}" .et`.h
	"${CMD}" "${FILE}" >&2 || exit 1;
	cd "${CURDIR}"
	TMP="${SOURCE}.$$"
	mv "${SOURCE}" "${TMP}" && {
		echo "#include \"config.h\"" > "${SOURCE}" && {
			cat "${TMP}" >> "${SOURCE}"
		}
	}
	rm -f "${TMP}"
} || {
	echo "${SELF}:cannot cd into '${DESTDIR}'" >&2;
	exit 1;
}

exit 0;