blob: fb480dd862d96a34b4a9f87e796e1c14c2eb457d [file] [log] [blame]
Guido van Rossumfba715a1994-01-02 00:26:09 +00001#! /bin/sh
2
Guido van Rossumb6775db1994-08-01 11:34:53 +00003# Convert templates into Makefile and config.c, based on the module
4# definitions found in the file Setup.
5#
6# Usage: makesetup [-s dir] [-c file] [-m file] [Setup] ... [-n [Setup] ...]
7#
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
14#
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.
18#
19# See Setup.in for a description of the format of the Setup file.
20#
21# The following edits are made:
22#
23# Copying config.c.in to config.c:
24# - insert an identifying comment at the start
Guido van Rossum7cc5abd1994-09-12 10:42:20 +000025# - for each <module> mentioned in Setup before *noconfig*:
Guido van Rossumb6775db1994-08-01 11:34:53 +000026# + insert 'extern void init<module>();' before MARKER 1
27# + insert '{"<module>", initmodule},' before MARKER 2
28#
29# Copying Makefile.pre to Makefile:
30# - insert an identifying comment at the start
Guido van Rossum3bbc62e1995-01-02 19:30:30 +000031# - replace _MODOBJS_ by the list of objects from Setup (except for
Guido van Rossumb6775db1994-08-01 11:34:53 +000032# Setup files after a -n option)
Guido van Rossum3bbc62e1995-01-02 19:30:30 +000033# - replace _MODLIBS_ by the list of libraries from Setup
Guido van Rossum7cc5abd1994-09-12 10:42:20 +000034# - 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
Guido van Rossumb6775db1994-08-01 11:34:53 +000038# - for each variable definition found in Setup, insert the definition
39# before the comment 'Definitions added by makesetup'
Guido van Rossumfba715a1994-01-02 00:26:09 +000040
Guido van Rossumb6775db1994-08-01 11:34:53 +000041# Loop over command line options
42usage='
43usage: makesetup [-s srcdir] [-c config.c.in] [-m Makefile.pre]
44 [Setup] ... [-n [Setup] ...]'
45srcdir=''
46config=''
47makepre=''
48noobjects=''
Guido van Rossum7cc5abd1994-09-12 10:42:20 +000049doconfig=yes
Guido van Rossumb6775db1994-08-01 11:34:53 +000050while :
51do
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
61done
62
63# Set default srcdir and config if not set by command line
64# (Not all systems have dirname)
65case $srcdir in
66'') case $0 in
67 */*) srcdir=`echo $0 | sed 's,/[^/]*$,,'`;;
68 *) srcdir=.;;
69 esac;;
70esac
71case $config in
72'') config=$srcdir/config.c.in;;
73esac
74case $makepre in
75'') makepre=Makefile.pre;;
76esac
77
78# Newline for sed i and a commands
Guido van Rossum4a269861995-06-14 22:52:06 +000079NL='\
80'
Guido van Rossumfba715a1994-01-02 00:26:09 +000081
Guido van Rossumb6775db1994-08-01 11:34:53 +000082# Main loop
83for i in ${*-Setup}
84do
85 case $i in
Guido van Rossum7cc5abd1994-09-12 10:42:20 +000086 -n) echo '*noobjects*';;
87 *) echo '*doconfig*'; cat "$i";;
Guido van Rossumb6775db1994-08-01 11:34:53 +000088 esac
89done |
90sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
Guido van Rossumfba715a1994-01-02 00:26:09 +000091(
Guido van Rossum7cc5abd1994-09-12 10:42:20 +000092 rulesf="@rules.$$"
93 trap 'rm -f $rulesf' 0 1 2 3
94 echo "
95# Rules appended by makedepend
96" >$rulesf
Guido van Rossumfba715a1994-01-02 00:26:09 +000097 DEFS=
98 MODS=
Guido van Rossum7cc5abd1994-09-12 10:42:20 +000099 SHAREDMODS=
Guido van Rossumfba715a1994-01-02 00:26:09 +0000100 OBJS=
101 LIBS=
Guido van Rossum0b498be1994-08-23 13:49:15 +0000102 LOCALLIBS=
103 BASELIBS=
Guido van Rossumfba715a1994-01-02 00:26:09 +0000104 while read line
105 do
Guido van Rossumb6775db1994-08-01 11:34:53 +0000106 # Output DEFS in reverse order so first definition overrides
Guido van Rossumfba715a1994-01-02 00:26:09 +0000107 case $line in
Guido van Rossumb6775db1994-08-01 11:34:53 +0000108 *=*) DEFS="$line$NL$DEFS"; continue;;
Guido van Rossum9bf84451997-04-02 05:33:00 +0000109 'include '*) DEFS="$line$NL$DEFS"; continue;;
Guido van Rossum7cc5abd1994-09-12 10:42:20 +0000110 '*noobjects*')
Guido van Rossum0b498be1994-08-23 13:49:15 +0000111 case $noobjects in
112 yes) ;;
113 *) LOCALLIBS=$LIBS; LIBS=;;
114 esac
115 noobjects=yes;
Guido van Rossum7cc5abd1994-09-12 10:42:20 +0000116 continue;;
117 '*doconfig*') doconfig=yes; continue;;
Guido van Rossum43554541996-08-20 19:49:13 +0000118 '*static*') doconfig=yes; continue;;
Guido van Rossum7cc5abd1994-09-12 10:42:20 +0000119 '*noconfig*') doconfig=no; continue;;
Guido van Rossum43554541996-08-20 19:49:13 +0000120 '*shared*') doconfig=no; continue;;
Guido van Rossumfba715a1994-01-02 00:26:09 +0000121 esac
Guido van Rossum0b498be1994-08-23 13:49:15 +0000122 srcs=
Guido van Rossumfba715a1994-01-02 00:26:09 +0000123 cpps=
Guido van Rossum7cc5abd1994-09-12 10:42:20 +0000124 libs=
125 mods=
Guido van Rossum4a269861995-06-14 22:52:06 +0000126 skip=
Guido van Rossum7cc5abd1994-09-12 10:42:20 +0000127 for arg in $line
Guido van Rossumfba715a1994-01-02 00:26:09 +0000128 do
Guido van Rossum4a269861995-06-14 22:52:06 +0000129 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
Guido van Rossumfba715a1994-01-02 00:26:09 +0000134 case $arg in
135 -[IDUC]*) cpps="$cpps $arg";;
Guido van Rossumb447d111997-12-02 20:38:11 +0000136 -Xlinker) libs="$libs $arg"; skip=libs;;
Guido van Rossum7cc5abd1994-09-12 10:42:20 +0000137 -[A-Zl]*) libs="$libs $arg";;
138 *.a) libs="$libs $arg";;
Guido van Rossuma29756c1996-08-19 22:00:05 +0000139 *.so) libs="$libs $arg";;
140 *.sl) libs="$libs $arg";;
Guido van Rossumfa1fb7d1998-05-14 02:37:45 +0000141 /*.o) libs="$libs $arg";;
Guido van Rossum7cc5abd1994-09-12 10:42:20 +0000142 *.o) srcs="$srcs `basename $arg .o`.c";;
Guido van Rossum0b498be1994-08-23 13:49:15 +0000143 *.[cC]) srcs="$srcs $arg";;
144 *.cc) srcs="$srcs $arg";;
145 *.c++) srcs="$srcs $arg";;
Guido van Rossumbabacb01997-02-14 16:44:04 +0000146 *.cxx) srcs="$srcs $arg";;
147 *.cpp) srcs="$srcs $arg";;
Sjoerd Mullender4237efc1995-10-11 08:45:15 +0000148 \$*) libs="$libs $arg"
149 cpps="$cpps $arg";;
Guido van Rossumfba715a1994-01-02 00:26:09 +0000150 *.*) echo 1>&2 "bad word $arg in $line"
151 exit 1;;
Guido van Rossum4a269861995-06-14 22:52:06 +0000152 -u) skip=libs; libs="$libs -u";;
Guido van Rossum7cc5abd1994-09-12 10:42:20 +0000153 [a-zA-Z_]*) mods="$mods $arg";;
Guido van Rossumfba715a1994-01-02 00:26:09 +0000154 *) echo 1>&2 "bad word $arg in $line"
155 exit 1;;
156 esac
157 done
Guido van Rossum7cc5abd1994-09-12 10:42:20 +0000158 case $doconfig in
159 yes)
160 LIBS="$LIBS $libs"
161 MODS="$MODS $mods"
162 ;;
163 esac
Guido van Rossumb6775db1994-08-01 11:34:53 +0000164 case $noobjects in
165 yes) continue;;
166 esac
Guido van Rossum7cc5abd1994-09-12 10:42:20 +0000167 objs=''
Guido van Rossum0b498be1994-08-23 13:49:15 +0000168 for src in $srcs
169 do
Guido van Rossum7cc5abd1994-09-12 10:42:20 +0000170 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)';;
Guido van Rossum16cb6f41997-10-21 19:30:29 +0000175 *.cxx) obj=`basename $src .cxx`.o; cc='$(CCC)';;
176 *.cpp) obj=`basename $src .cpp`.o; cc='$(CCC)';;
Guido van Rossum7cc5abd1994-09-12 10:42:20 +0000177 *) continue;;
178 esac
179 objs="$objs $obj"
180 case $src in
181 glmodule.c) ;;
182 *) src='$(srcdir)/'$src;;
183 esac
184 case $doconfig in
Guido van Rossum89910651994-10-20 21:58:30 +0000185 no) cc="$cc \$(CCSHARED)";;
Guido van Rossum7cc5abd1994-09-12 10:42:20 +0000186 esac
187 rule="$obj: $src; $cc \$(CFLAGS) $cpps -c $src"
188 echo "$rule" >>$rulesf
Guido van Rossum0b498be1994-08-23 13:49:15 +0000189 done
Guido van Rossum7cc5abd1994-09-12 10:42:20 +0000190 case $doconfig in
191 yes) OBJS="$OBJS $objs";;
192 esac
193 for mod in $mods
194 do
195 case $objs in
196 *$mod.o*) base=$mod;;
197 *) base=${mod}module;;
198 esac
199 file="$base\$(SO)"
200 case $doconfig in
201 no) SHAREDMODS="$SHAREDMODS $file";;
202 esac
203 rule="$file: $objs"
Sjoerd Mullender4eba0c91994-10-13 09:09:05 +0000204 rule="$rule; \$(LDSHARED) $objs $libs -o $file"
Guido van Rossum7cc5abd1994-09-12 10:42:20 +0000205 echo "$rule" >>$rulesf
206 done
Guido van Rossumfba715a1994-01-02 00:26:09 +0000207 done
208
Guido van Rossum7cc5abd1994-09-12 10:42:20 +0000209 case $SHAREDMODS in
210 '') ;;
211 *) DEFS="SHAREDMODS=$SHAREDMODS$NL$DEFS";;
212 esac
213
Guido van Rossum0b498be1994-08-23 13:49:15 +0000214 case $noobjects in
215 yes) BASELIBS=$LIBS;;
216 *) LOCALLIBS=$LIBS;;
217 esac
218 LIBS='$(LOCALMODLIBS) $(BASEMODLIBS)'
219 DEFS="BASEMODLIBS=$BASELIBS$NL$DEFS"
220 DEFS="LOCALMODLIBS=$LOCALLIBS$NL$DEFS"
221
Guido van Rossumfba715a1994-01-02 00:26:09 +0000222 EXTDECLS=
223 INITBITS=
224 for mod in $MODS
225 do
226 EXTDECLS="${EXTDECLS}extern void init$mod();$NL"
227 INITBITS="${INITBITS} {\"$mod\", init$mod},$NL"
228 done
Guido van Rossumfba715a1994-01-02 00:26:09 +0000229
Guido van Rossum7cc5abd1994-09-12 10:42:20 +0000230
Guido van Rossumb6775db1994-08-01 11:34:53 +0000231 case $config in
232 -) ;;
233 *) sed -e "
234 1i$NL/* Generated automatically from $config by makesetup. */
235 /MARKER 1/i$NL$EXTDECLS
Guido van Rossumfba715a1994-01-02 00:26:09 +0000236 /MARKER 2/i$NL$INITBITS
237
Guido van Rossumb6775db1994-08-01 11:34:53 +0000238 " $config >config.c
239 ;;
240 esac
Guido van Rossumfba715a1994-01-02 00:26:09 +0000241
Guido van Rossumb6775db1994-08-01 11:34:53 +0000242 case $makepre in
Guido van Rossum7cc5abd1994-09-12 10:42:20 +0000243 -) ;;
244 *) sedf="@sed.in.$$"
245 trap 'rm -f $sedf' 0 1 2 3
246 echo "1i\\" >$sedf
247 str="# Generated automatically from $makepre by makesetup."
248 echo "$str" >>$sedf
Guido van Rossum3bbc62e1995-01-02 19:30:30 +0000249 echo "s%_MODOBJS_%$OBJS%" >>$sedf
250 echo "s%_MODLIBS_%$LIBS%" >>$sedf
Guido van Rossum7cc5abd1994-09-12 10:42:20 +0000251 echo "/Definitions added by makesetup/a$NL$NL$DEFS" >>$sedf
252 sed -f $sedf $makepre >Makefile
253 cat $rulesf >>Makefile
254 rm -f $sedf
Guido van Rossumb6775db1994-08-01 11:34:53 +0000255 ;;
256 esac
Guido van Rossumfba715a1994-01-02 00:26:09 +0000257
Guido van Rossum7cc5abd1994-09-12 10:42:20 +0000258 rm -f $rulesf
Guido van Rossumfba715a1994-01-02 00:26:09 +0000259)