Don't reference removed files in Makefile
[python/dscho.git] / Modules / makesetup
blob1feae60df423a79dd87a05aa923642141d2e07e9
1 #! /bin/sh
3 # Convert templates into Makefile and config.c, based on the module
4 # definitions found in the file Setup.
6 # Usage: makesetup [-s dir] [-c file] [-m file] [Setup] ... [-n [Setup] ...]
8 # Options:
9 # -s directory: alternative source directory (default derived from $0)
10 # -c file: alternative config.c template (default $srcdir/config.c.in)
11 # -c -: don't write config.c
12 # -m file: alternative Makefile template (default ./Makefile.pre)
13 # -m -: don't write Makefile
15 # Remaining arguments are one or more Setup files (default ./Setup).
16 # Setup files after a -n option are used for their variables, modules
17 # and libraries but not for their .o files.
19 # See Setup.in for a description of the format of the Setup file.
21 # The following edits are made:
23 # Copying config.c.in to config.c:
24 # - insert an identifying comment at the start
25 # - for each <module> mentioned in Setup before *noconfig*:
26 # + insert 'extern void init<module>();' before MARKER 1
27 # + insert '{"<module>", initmodule},' before MARKER 2
29 # Copying Makefile.pre to Makefile:
30 # - insert an identifying comment at the start
31 # - replace _MODOBJS_ by the list of objects from Setup (except for
32 # Setup files after a -n option)
33 # - replace _MODLIBS_ by the list of libraries from Setup
34 # - for each object file mentioned in Setup, append a rule
35 # '<file>.o: <file>.c; <build commands>' to the end of the Makefile
36 # - for each module mentioned in Setup, append a rule
37 # which creates a shared library version to the end of the Makefile
38 # - for each variable definition found in Setup, insert the definition
39 # before the comment 'Definitions added by makesetup'
41 # Loop over command line options
42 usage='
43 usage: makesetup [-s srcdir] [-c config.c.in] [-m Makefile.pre]
44 [Setup] ... [-n [Setup] ...]'
45 srcdir=''
46 config=''
47 makepre=''
48 noobjects=''
49 doconfig=yes
50 while :
52 case $1 in
53 -s) shift; srcdir=$1; shift;;
54 -c) shift; config=$1; shift;;
55 -m) shift; makepre=$1; shift;;
56 --) shift; break;;
57 -n) noobjects=yes;;
58 -*) echo "$usage" 1>&2; exit 2;;
59 *) break;;
60 esac
61 done
63 # Set default srcdir and config if not set by command line
64 # (Not all systems have dirname)
65 case $srcdir in
66 '') case $0 in
67 */*) srcdir=`echo $0 | sed 's,/[^/]*$,,'`;;
68 *) srcdir=.;;
69 esac;;
70 esac
71 case $config in
72 '') config=$srcdir/config.c.in;;
73 esac
74 case $makepre in
75 '') makepre=Makefile.pre;;
76 esac
78 # Newline for sed i and a commands
79 NL="\\
82 # Main loop
83 for i in ${*-Setup}
85 case $i in
86 -n) echo '*noobjects*';;
87 *) echo '*doconfig*'; cat "$i";;
88 esac
89 done |
90 sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
92 rulesf="@rules.$$"
93 trap 'rm -f $rulesf' 0 1 2 3
94 echo "
95 # Rules appended by makedepend
96 " >$rulesf
97 DEFS=
98 MODS=
99 SHAREDMODS=
100 OBJS=
101 LIBS=
102 LOCALLIBS=
103 BASELIBS=
104 while read line
106 # Output DEFS in reverse order so first definition overrides
107 case $line in
108 *=*) DEFS="$line$NL$DEFS"; continue;;
109 '*noobjects*')
110 case $noobjects in
111 yes) ;;
112 *) LOCALLIBS=$LIBS; LIBS=;;
113 esac
114 noobjects=yes;
115 continue;;
116 '*doconfig*') doconfig=yes; continue;;
117 '*noconfig*') doconfig=no; continue;;
118 esac
119 srcs=
120 cpps=
121 libs=
122 mods=
123 for arg in $line
125 case $arg in
126 -[IDUC]*) cpps="$cpps $arg";;
127 -[A-Zl]*) libs="$libs $arg";;
128 *.a) libs="$libs $arg";;
129 *.o) srcs="$srcs `basename $arg .o`.c";;
130 *.[cC]) srcs="$srcs $arg";;
131 *.cc) srcs="$srcs $arg";;
132 *.c++) srcs="$srcs $arg";;
133 \$*) libs="$libs $arg";;
134 *.*) echo 1>&2 "bad word $arg in $line"
135 exit 1;;
136 [a-zA-Z_]*) mods="$mods $arg";;
137 *) echo 1>&2 "bad word $arg in $line"
138 exit 1;;
139 esac
140 done
141 case $doconfig in
142 yes)
143 LIBS="$LIBS $libs"
144 MODS="$MODS $mods"
146 esac
147 case $noobjects in
148 yes) continue;;
149 esac
150 objs=''
151 for src in $srcs
153 case $src in
154 *.c) obj=`basename $src .c`.o; cc='$(CC)';;
155 *.cc) obj=`basename $src .cc`.o; cc='$(CCC)';;
156 *.c++) obj=`basename $src .c++`.o; cc='$(CCC)';;
157 *.C) obj=`basename $src .C`.o; cc='$(CCC)';;
158 *) continue;;
159 esac
160 objs="$objs $obj"
161 case $src in
162 glmodule.c) ;;
163 *) src='$(srcdir)/'$src;;
164 esac
165 case $doconfig in
166 no) cc="$cc \$(CCSHARED)";;
167 esac
168 rule="$obj: $src; $cc \$(CFLAGS) $cpps -c $src"
169 echo "$rule" >>$rulesf
170 done
171 case $doconfig in
172 yes) OBJS="$OBJS $objs";;
173 esac
174 for mod in $mods
176 case $objs in
177 *$mod.o*) base=$mod;;
178 *) base=${mod}module;;
179 esac
180 file="$base\$(SO)"
181 case $doconfig in
182 no) SHAREDMODS="$SHAREDMODS $file";;
183 esac
184 rule="$file: $objs"
185 rule="$rule; \$(LDSHARED) $objs $libs -o $file"
186 echo "$rule" >>$rulesf
187 done
188 done
190 case $SHAREDMODS in
191 '') ;;
192 *) DEFS="SHAREDMODS=$SHAREDMODS$NL$DEFS";;
193 esac
195 case $noobjects in
196 yes) BASELIBS=$LIBS;;
197 *) LOCALLIBS=$LIBS;;
198 esac
199 LIBS='$(LOCALMODLIBS) $(BASEMODLIBS)'
200 DEFS="BASEMODLIBS=$BASELIBS$NL$DEFS"
201 DEFS="LOCALMODLIBS=$LOCALLIBS$NL$DEFS"
203 EXTDECLS=
204 INITBITS=
205 for mod in $MODS
207 EXTDECLS="${EXTDECLS}extern void init$mod();$NL"
208 INITBITS="${INITBITS} {\"$mod\", init$mod},$NL"
209 done
212 case $config in
213 -) ;;
214 *) sed -e "
215 1i$NL/* Generated automatically from $config by makesetup. */
216 /MARKER 1/i$NL$EXTDECLS
217 /MARKER 2/i$NL$INITBITS
219 " $config >config.c
221 esac
223 case $makepre in
224 -) ;;
225 *) sedf="@sed.in.$$"
226 trap 'rm -f $sedf' 0 1 2 3
227 echo "1i\\" >$sedf
228 str="# Generated automatically from $makepre by makesetup."
229 echo "$str" >>$sedf
230 echo "s%_MODOBJS_%$OBJS%" >>$sedf
231 echo "s%_MODLIBS_%$LIBS%" >>$sedf
232 echo "/Definitions added by makesetup/a$NL$NL$DEFS" >>$sedf
233 sed -f $sedf $makepre >Makefile
234 cat $rulesf >>Makefile
235 rm -f $sedf
237 esac
239 rm -f $rulesf