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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
#!/bin/sh
cd `dirname $0`
rtdir=".."
build="build"
MAKE=${MAKE-"make"}
# Output into Makefile
echo "Generating Makefile"
exec 4<&1
exec 1>Makefile
# Get the list of base non-generated and generated sources
ngfiles=`sed \
-e '1,/##STDSRC-START/d' -e '/##STDSRC-END/,$d' \
-e 's/#.*//' -e 's/[[:space:]]*//' -e '/^$/d' \
${rtdir}/cmake_files/basic_vars.cmake`
gfiles=`sed \
-e '1,/##GENSRC-START/d' -e '/##GENSRC-END/,$d' \
-e 's/#.*//' -e 's/[[:space:]]*//' -e '/^$/d' \
${rtdir}/cmake_files/basic_vars.cmake`
# Extra file needed to build the binary
ngfiles="${ngfiles} ctwm_wrap.c"
# Non-generated files that are optional; separate so they don't end up in
# OFILES in the main run
ongfiles=""
ongfiles="${ongfiles} image_xpm.c"
ongfiles="${ongfiles} image_jpeg.c"
ongfiles="${ongfiles} parse_m4.c"
ongfiles="${ongfiles} ewmh.c"
ongfiles="${ongfiles} xrandr.c"
# Top boilerplate
cat << EOF
## GENERATED FILE
RTDIR=${rtdir}
BDIR=${build}
EOF
# Defs (external)
cat defs.mk
echo
# Will need this for setting the name of the obj file for a given .c
mkobj()
{
# /bin/sh on Slowaris is ksh93, which doesn't support 'local'.
# Thanks, guys. Well, I guess I'll just be sure not to use $_o
# anywhere else...
_o=$1
_o=${_o##*/}
_o="${_o%.c}.o"
eval "$2=$_o"
}
# List the core files first
echo "## Core files"
echo "OFILES = \\"
for i in ${ngfiles}; do
mkobj $i oret
echo " \${BDIR}/${oret} \\"
done
echo
# Have to manually write these; transform rules won't work across dirs
for i in ${ngfiles} ${ongfiles}; do
src="\${RTDIR}/${i}"
mkobj $i dst
dst="\${BDIR}/${dst}"
echo "${dst}: ${src}"
echo " \${CC} \${_CFLAGS} -c -o ${dst} ${src}"
done
echo
# Generated files
echo "## Generated files"
echo "OFILES += \\"
for i in ${gfiles}; do
echo " \${BDIR}/${i%.c}.o \\"
done
echo
for i in ${gfiles}; do
echo "gen: \${BDIR}/${i}"
done
echo
echo
# Build up STDSRC for depend state
echo "## For make depend"
echo "STDSRC = \\"
for i in ${ngfiles}; do
echo " \${RTDIR}/${i} \\"
done
echo
# The rest of the file
cat main.mk
# Figure out how we can run 'make depend', if we can. 'gccmakedep' and
# 'makedepend' are both programs from X.org that do it, and imake uses
# them, so probably anyone running X has one of them...
mkdep=""
for i in gccmakedep makedepend; do
mkdep=`command -v ${i}`
if [ "X" != "X${mkdep}" ]; then
echo
echo "depend: \${BDIR} \${GENFILES}"
echo " ${mkdep} -- \${_CFLAGS} -- \${STDSRC} \${GENSRC}"
echo " ${MAKE} rwdepend"
echo
echo
break
fi
done
# Done
exec 1<&4
# Run make depend if we have it. Else, run make gen so the generated
# files are already there, since otherwise we don't have the detailed
# dependencies to know when we need various headers.
if [ "X" != "X${mkdep}" ]; then
echo "Running make depend"
${MAKE} depend
rm Makefile.bak
else
echo "Running make gen"
${MAKE} gen
fi
|