forked from bruceg/daemontools-encore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makemake
executable file
·122 lines (108 loc) · 1.95 KB
/
makemake
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
#!/bin/sh
t=makemake.targetd
T=makemake.TARGETS
S=makemake.SOURCES
trap 'rm -fv *.tmp.$$ $T $S; rm -r $t' EXIT
rm -rf $t $T $S
mkdir -p $t
rm -f `cat TARGETS`
c() {
echo "$*" >&2;
}
error() {
echo "$0: Error: $*" >&2;
}
dependon() {
for dep in $*; do
echo "$dep" >&3
target $dep
done
}
formake() {
echo " $*" >&4
}
nosuchtarget() {
if [ -e "$target" ]; then
echo "$target" >>$S
else
error "No such target: $target"
fi
}
directtarget() {
# What is this supposed to do?
:
}
dependcc() {
dependon $1
for file in $(sed -e '/^#include "/!d;s/"$//;s/^.*"//' $1 2>/dev/null);
do
dependcc $file
done
}
depend() {
# What is this supposed to do?
# Invoked as: depend -ezmlm-warn.o=m
:
}
target() {
target=$1
if [ -e $target -a ! -e ${target}.do ]; then
echo $target >>$S
return
fi
if [ -e $t/$target.deps ]; then
return
fi
#c target: $target
starget=`echo $target | tr / :`
tmp=$starget.tmp.$$
(
ext=${target##*.}
base=${target%%.*}
set -- $target $base $tmp
if [ -f $target.do ]; then
. ./$target.do
elif [ -f default.$ext.do ]; then
. ./default.$ext.do $target $base $tmp
else
. ./default.do $target $base $tmp
fi
) 3>$t/$starget.deps 4>$t/$starget.cmds
# if [ -s $tmp ]; then
# mv -f $tmp $target
# else
# rm -f $tmp
# fi
}
echo "Calculating targets..."
target clean
target targets
rm -f $t/targets
echo "Building Makefile..."
(
cat <<EOF
# This file is automatically generated, do not edit.
SHELL=/bin/sh
default: it
EOF
cd $t
for deps in *.deps; do
target=${deps%.deps}
cmds=$target.cmds
target=`echo $target | tr : /`
if [ -s $deps -o -s $cmds ]; then
echo
echo "$target: \\"
echo `uniq $deps`
cat $cmds
echo $target >&2
fi
rm -f $deps $cmds
done
) >Makefile 2>$T
echo SOURCES >>$S
echo Makefile >>$S
sort -u $S >SOURCES
sort -u $T | fgrep -vxf SOURCES >TARGETS
rm -f $S $T
echo "done."