aboutsummaryrefslogtreecommitdiff
path: root/scripts/gen-deps
blob: f45707c2c0592519489e54c9c2630823a4b96af0 (plain) (blame)
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
#!/bin/sh

PREFIX=
COMPILE=COMPILE
LINT=LINT
BUILD=build/

while getopts "p:c:b:l:" opt; do
	case "$opt" in
		p) PREFIX="$OPTARG"_;;
		c) COMPILE="$OPTARG";;
		l) LINT="$OPTARG";;
		b) BUILD=build/"$OPTARG";;
		*) echo "unrecognised option -$OPTARG" >&2; exit 1;;
	esac
done

shift $((OPTIND - 1))

# create all subdirectories
mkdir -p $(echo "${@}" | tr ' ' '\n' | sed "s|[^/]*$||;s|^|${BUILD}/|" | uniq)

for s in ${@}
do
	obj="${BUILD}/${s%.*}.o"
	lint="${obj}.l"
	dep="${obj}.d"

	echo "${PREFIX}OBJS += ${obj}"			>> deps.mk
	echo "${PREFIX}LINTS += ${lint}"		>> deps.mk
	echo "${dep}:"					>> deps.mk
	echo "-include ${dep}"				>> deps.mk
	echo "${obj}: ${s}"				>> deps.mk
	echo "	\$(${COMPILE}) -c ${s} -o ${obj}"	>> deps.mk
	echo "${lint}: ${s}"				>> deps.mk
	echo "	\$(${LINT}) -c ${s} -o /dev/null"	>> deps.mk
done