blob: 88b87b90afbf9835b8bc2629642a8d117667dbf1 [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
25# - for each <module> mentioned in Setup:
26# + 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
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, insert a rule
35# '<file>.o: <file>.c; <build commands>' before the comment
36# 'Rules added by makesetup'
37# - for each variable definition found in Setup, insert the definition
38# before the comment 'Definitions added by makesetup'
Guido van Rossumfba715a1994-01-02 00:26:09 +000039
Guido van Rossumb6775db1994-08-01 11:34:53 +000040# Loop over command line options
41usage='
42usage: makesetup [-s srcdir] [-c config.c.in] [-m Makefile.pre]
43 [Setup] ... [-n [Setup] ...]'
44srcdir=''
45config=''
46makepre=''
47noobjects=''
48while :
49do
50 case $1 in
51 -s) shift; srcdir=$1; shift;;
52 -c) shift; config=$1; shift;;
53 -m) shift; makepre=$1; shift;;
54 --) shift; break;;
55 -n) noobjects=yes;;
56 -*) echo "$usage" 1>&2; exit 2;;
57 *) break;;
58 esac
59done
60
61# Set default srcdir and config if not set by command line
62# (Not all systems have dirname)
63case $srcdir in
64'') case $0 in
65 */*) srcdir=`echo $0 | sed 's,/[^/]*$,,'`;;
66 *) srcdir=.;;
67 esac;;
68esac
69case $config in
70'') config=$srcdir/config.c.in;;
71esac
72case $makepre in
73'') makepre=Makefile.pre;;
74esac
75
76# Newline for sed i and a commands
Guido van Rossumfba715a1994-01-02 00:26:09 +000077NL="\\
78"
79
Guido van Rossumb6775db1994-08-01 11:34:53 +000080# Main loop
81for i in ${*-Setup}
82do
83 case $i in
84 -n) echo '<noobjects>';;
85 *) cat "$i";;
86 esac
87done |
88sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
Guido van Rossumfba715a1994-01-02 00:26:09 +000089(
90 DEFS=
91 MODS=
92 OBJS=
93 LIBS=
94 RULES=
Guido van Rossum0b498be1994-08-23 13:49:15 +000095 LOCALLIBS=
96 BASELIBS=
Guido van Rossumfba715a1994-01-02 00:26:09 +000097 while read line
98 do
Guido van Rossumb6775db1994-08-01 11:34:53 +000099 # Output DEFS in reverse order so first definition overrides
Guido van Rossumfba715a1994-01-02 00:26:09 +0000100 case $line in
Guido van Rossumb6775db1994-08-01 11:34:53 +0000101 *=*) DEFS="$line$NL$DEFS"; continue;;
Guido van Rossum0b498be1994-08-23 13:49:15 +0000102 '<noobjects>')
103 case $noobjects in
104 yes) ;;
105 *) LOCALLIBS=$LIBS; LIBS=;;
106 esac
107 noobjects=yes;
108 continue;;
Guido van Rossumfba715a1994-01-02 00:26:09 +0000109 esac
110 objs=
Guido van Rossum0b498be1994-08-23 13:49:15 +0000111 srcs=
Guido van Rossumfba715a1994-01-02 00:26:09 +0000112 cpps=
113 set $line
114 for arg
115 do
116 case $arg in
117 -[IDUC]*) cpps="$cpps $arg";;
Guido van Rossumb6775db1994-08-01 11:34:53 +0000118 -[A-Zl]*) LIBS="$LIBS $arg";;
Guido van Rossumfba715a1994-01-02 00:26:09 +0000119 *.a) LIBS="$LIBS $arg";;
120 *.o) objs="$objs $arg";;
Guido van Rossum0b498be1994-08-23 13:49:15 +0000121 *.[cC]) srcs="$srcs $arg";;
122 *.cc) srcs="$srcs $arg";;
123 *.c++) srcs="$srcs $arg";;
Guido van Rossumfba715a1994-01-02 00:26:09 +0000124 *.*) echo 1>&2 "bad word $arg in $line"
125 exit 1;;
126 [a-zA-Z_]*) MODS="$MODS $arg";;
127 *) echo 1>&2 "bad word $arg in $line"
128 exit 1;;
129 esac
130 done
Guido van Rossumb6775db1994-08-01 11:34:53 +0000131 case $noobjects in
132 yes) continue;;
133 esac
Guido van Rossumfba715a1994-01-02 00:26:09 +0000134 for obj in $objs
135 do
136 src=`basename $obj .o`.c
Guido van Rossumb6775db1994-08-01 11:34:53 +0000137 case $src in
138 glmodule.c) ;;
139 *) src='$(srcdir)/'$src;;
140 esac
Guido van Rossumfba715a1994-01-02 00:26:09 +0000141 RULES="$RULES$obj: $src; \$(CC) \$(CFLAGS) $cpps -c $src$NL"
142 done
143 OBJS="$OBJS $objs"
Guido van Rossum224b2891994-08-30 09:27:16 +0000144 objs=
Guido van Rossum0b498be1994-08-23 13:49:15 +0000145 for src in $srcs
146 do
147 case $src in
148 *.c) obj=`basename $src .c`.o; cc='$(CC)';;
149 *.cc) obj=`basename $src .cc`.o; cc='$(CCC)';;
150 *.c++) obj=`basename $src .c++`.o; cc='$(CCC)';;
151 *.C) obj=`basename $src .C`.o; cc='$(CCC)';;
152 *) continue;;
153 esac
Guido van Rossum224b2891994-08-30 09:27:16 +0000154 objs="$objs $obj"
Guido van Rossum0b498be1994-08-23 13:49:15 +0000155 case $src in
156 glmodule.c) ;;
157 *) src='$(srcdir)/'$src;;
158 esac
159 RULES="$RULES$obj: $src; $cc \$(CFLAGS) $cpps -c $src$NL"
160 done
Guido van Rossum224b2891994-08-30 09:27:16 +0000161 OBJS="$OBJS $objs"
Guido van Rossumfba715a1994-01-02 00:26:09 +0000162 done
163
Guido van Rossum0b498be1994-08-23 13:49:15 +0000164 case $noobjects in
165 yes) BASELIBS=$LIBS;;
166 *) LOCALLIBS=$LIBS;;
167 esac
168 LIBS='$(LOCALMODLIBS) $(BASEMODLIBS)'
169 DEFS="BASEMODLIBS=$BASELIBS$NL$DEFS"
170 DEFS="LOCALMODLIBS=$LOCALLIBS$NL$DEFS"
171
Guido van Rossumfba715a1994-01-02 00:26:09 +0000172 EXTDECLS=
173 INITBITS=
174 for mod in $MODS
175 do
176 EXTDECLS="${EXTDECLS}extern void init$mod();$NL"
177 INITBITS="${INITBITS} {\"$mod\", init$mod},$NL"
178 done
Guido van Rossumfba715a1994-01-02 00:26:09 +0000179
Guido van Rossumb6775db1994-08-01 11:34:53 +0000180 case $config in
181 -) ;;
182 *) sed -e "
183 1i$NL/* Generated automatically from $config by makesetup. */
184 /MARKER 1/i$NL$EXTDECLS
Guido van Rossumfba715a1994-01-02 00:26:09 +0000185 /MARKER 2/i$NL$INITBITS
186
Guido van Rossumb6775db1994-08-01 11:34:53 +0000187 " $config >config.c
188 ;;
189 esac
Guido van Rossumfba715a1994-01-02 00:26:09 +0000190
Guido van Rossumb6775db1994-08-01 11:34:53 +0000191 case $makepre in
192 -) ;;
193 *) sed -e "
194 1i$NL# Generated automatically from $makepre by makesetup.
Guido van Rossumfba715a1994-01-02 00:26:09 +0000195 s%@MODOBJS@%$OBJS%
196 s%@MODLIBS@%$LIBS%
Guido van Rossumb6775db1994-08-01 11:34:53 +0000197 /Rules added by makesetup/a$NL$NL$RULES
198 /Definitions added by makesetup/a$NL$NL$DEFS
199
200 " $makepre >Makefile
201 ;;
202 esac
Guido van Rossumfba715a1994-01-02 00:26:09 +0000203
204)