Fix an amazing number of typos & malformed sentences reported by Detlef
[python/dscho.git] / Modules / makesetup
blob0fefcfffc1f3c50b023ae6802c47e834c0735867
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 'include '*) DEFS="$line$NL$DEFS"; continue;;
110 '*noobjects*')
111 case $noobjects in
112 yes) ;;
113 *) LOCALLIBS=$LIBS; LIBS=;;
114 esac
115 noobjects=yes;
116 continue;;
117 '*doconfig*') doconfig=yes; continue;;
118 '*static*') doconfig=yes; continue;;
119 '*noconfig*') doconfig=no; continue;;
120 '*shared*') doconfig=no; continue;;
121 esac
122 srcs=
123 cpps=
124 libs=
125 mods=
126 skip=
127 for arg in $line
129 case $skip in
130 libs) libs="$libs $arg"; skip=; continue;;
131 cpps) cpps="$cpps $arg"; skip=; continue;;
132 srcs) srcs="$srcs $arg"; skip=; continue;;
133 esac
134 case $arg in
135 -[IDUC]*) cpps="$cpps $arg";;
136 -Xlinker) libs="$libs $arg"; skip=libs;;
137 -[A-Zl]*) libs="$libs $arg";;
138 *.a) libs="$libs $arg";;
139 *.so) libs="$libs $arg";;
140 *.sl) libs="$libs $arg";;
141 /*.o) libs="$libs $arg";;
142 *.o) srcs="$srcs `basename $arg .o`.c";;
143 *.[cC]) srcs="$srcs $arg";;
144 *.cc) srcs="$srcs $arg";;
145 *.c++) srcs="$srcs $arg";;
146 *.cxx) srcs="$srcs $arg";;
147 *.cpp) srcs="$srcs $arg";;
148 \$*) libs="$libs $arg"
149 cpps="$cpps $arg";;
150 *.*) echo 1>&2 "bad word $arg in $line"
151 exit 1;;
152 -u) skip=libs; libs="$libs -u";;
153 [a-zA-Z_]*) mods="$mods $arg";;
154 *) echo 1>&2 "bad word $arg in $line"
155 exit 1;;
156 esac
157 done
158 case $doconfig in
159 yes)
160 LIBS="$LIBS $libs"
161 MODS="$MODS $mods"
163 esac
164 case $noobjects in
165 yes) continue;;
166 esac
167 objs=''
168 for src in $srcs
170 case $src in
171 *.c) obj=`basename $src .c`.o; cc='$(CC)';;
172 *.cc) obj=`basename $src .cc`.o; cc='$(CCC)';;
173 *.c++) obj=`basename $src .c++`.o; cc='$(CCC)';;
174 *.C) obj=`basename $src .C`.o; cc='$(CCC)';;
175 *.cxx) obj=`basename $src .cxx`.o; cc='$(CCC)';;
176 *.cpp) obj=`basename $src .cpp`.o; cc='$(CCC)';;
177 *) continue;;
178 esac
179 objs="$objs $obj"
180 case $src in
181 glmodule.c) ;;
182 /*) ;;
183 *) src='$(srcdir)/'$src;;
184 esac
185 case $doconfig in
186 no) cc="$cc \$(CCSHARED)";;
187 esac
188 rule="$obj: $src; $cc $cpps \$(CFLAGS) -c $src"
189 echo "$rule" >>$rulesf
190 done
191 case $doconfig in
192 yes) OBJS="$OBJS $objs";;
193 esac
194 for mod in $mods
196 case $objs in
197 *$mod.o*) base=$mod;;
198 *) base=${mod}module;;
199 esac
200 file="$base\$(SO)"
201 case $doconfig in
202 no) SHAREDMODS="$SHAREDMODS $file";;
203 esac
204 rule="$file: $objs"
205 rule="$rule; \$(LDSHARED) $objs $libs -o $file"
206 echo "$rule" >>$rulesf
207 done
208 done
210 case $SHAREDMODS in
211 '') ;;
212 *) DEFS="SHAREDMODS=$SHAREDMODS$NL$DEFS";;
213 esac
215 case $noobjects in
216 yes) BASELIBS=$LIBS;;
217 *) LOCALLIBS=$LIBS;;
218 esac
219 LIBS='$(LOCALMODLIBS) $(BASEMODLIBS)'
220 DEFS="BASEMODLIBS=$BASELIBS$NL$DEFS"
221 DEFS="LOCALMODLIBS=$LOCALLIBS$NL$DEFS"
223 EXTDECLS=
224 INITBITS=
225 for mod in $MODS
227 EXTDECLS="${EXTDECLS}extern void init$mod();$NL"
228 INITBITS="${INITBITS} {\"$mod\", init$mod},$NL"
229 done
232 case $config in
233 -) ;;
234 *) sed -e "
235 1i$NL/* Generated automatically from $config by makesetup. */
236 /MARKER 1/i$NL$EXTDECLS
238 /MARKER 2/i$NL$INITBITS
240 " $config >config.c
242 esac
244 case $makepre in
245 -) ;;
246 *) sedf="@sed.in.$$"
247 trap 'rm -f $sedf' 0 1 2 3
248 echo "1i\\" >$sedf
249 str="# Generated automatically from $makepre by makesetup."
250 echo "$str" >>$sedf
251 echo "s%_MODOBJS_%$OBJS%" >>$sedf
252 echo "s%_MODLIBS_%$LIBS%" >>$sedf
253 echo "/Definitions added by makesetup/a$NL$NL$DEFS" >>$sedf
254 sed -f $sedf $makepre >Makefile
255 cat $rulesf >>Makefile
256 rm -f $sedf
258 esac
260 rm -f $rulesf