Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 1 | #! /bin/sh |
| 2 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 3 | # 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 Rossum | 7cc5abd | 1994-09-12 10:42:20 +0000 | [diff] [blame] | 25 | # - for each <module> mentioned in Setup before *noconfig*: |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 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 |
Guido van Rossum | 3bbc62e | 1995-01-02 19:30:30 +0000 | [diff] [blame] | 31 | # - replace _MODOBJS_ by the list of objects from Setup (except for |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 32 | # Setup files after a -n option) |
Guido van Rossum | 3bbc62e | 1995-01-02 19:30:30 +0000 | [diff] [blame] | 33 | # - replace _MODLIBS_ by the list of libraries from Setup |
Guido van Rossum | 7cc5abd | 1994-09-12 10:42:20 +0000 | [diff] [blame] | 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 |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 38 | # - for each variable definition found in Setup, insert the definition |
| 39 | # before the comment 'Definitions added by makesetup' |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 40 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 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='' |
Guido van Rossum | 7cc5abd | 1994-09-12 10:42:20 +0000 | [diff] [blame] | 49 | doconfig=yes |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 50 | while : |
| 51 | do |
| 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 |
| 62 | |
| 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 |
| 77 | |
| 78 | # Newline for sed i and a commands |
Guido van Rossum | 4a26986 | 1995-06-14 22:52:06 +0000 | [diff] [blame] | 79 | NL='\ |
| 80 | ' |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 81 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 82 | # Main loop |
| 83 | for i in ${*-Setup} |
| 84 | do |
| 85 | case $i in |
Guido van Rossum | 7cc5abd | 1994-09-12 10:42:20 +0000 | [diff] [blame] | 86 | -n) echo '*noobjects*';; |
| 87 | *) echo '*doconfig*'; cat "$i";; |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 88 | esac |
| 89 | done | |
| 90 | sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' | |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 91 | ( |
Guido van Rossum | 7cc5abd | 1994-09-12 10:42:20 +0000 | [diff] [blame] | 92 | rulesf="@rules.$$" |
| 93 | trap 'rm -f $rulesf' 0 1 2 3 |
| 94 | echo " |
| 95 | # Rules appended by makedepend |
| 96 | " >$rulesf |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 97 | DEFS= |
| 98 | MODS= |
Guido van Rossum | 7cc5abd | 1994-09-12 10:42:20 +0000 | [diff] [blame] | 99 | SHAREDMODS= |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 100 | OBJS= |
| 101 | LIBS= |
Guido van Rossum | 0b498be | 1994-08-23 13:49:15 +0000 | [diff] [blame] | 102 | LOCALLIBS= |
| 103 | BASELIBS= |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 104 | while read line |
| 105 | do |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 106 | # Output DEFS in reverse order so first definition overrides |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 107 | case $line in |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 108 | *=*) DEFS="$line$NL$DEFS"; continue;; |
Guido van Rossum | 7cc5abd | 1994-09-12 10:42:20 +0000 | [diff] [blame] | 109 | '*noobjects*') |
Guido van Rossum | 0b498be | 1994-08-23 13:49:15 +0000 | [diff] [blame] | 110 | case $noobjects in |
| 111 | yes) ;; |
| 112 | *) LOCALLIBS=$LIBS; LIBS=;; |
| 113 | esac |
| 114 | noobjects=yes; |
Guido van Rossum | 7cc5abd | 1994-09-12 10:42:20 +0000 | [diff] [blame] | 115 | continue;; |
| 116 | '*doconfig*') doconfig=yes; continue;; |
Guido van Rossum | 4355454 | 1996-08-20 19:49:13 +0000 | [diff] [blame] | 117 | '*static*') doconfig=yes; continue;; |
Guido van Rossum | 7cc5abd | 1994-09-12 10:42:20 +0000 | [diff] [blame] | 118 | '*noconfig*') doconfig=no; continue;; |
Guido van Rossum | 4355454 | 1996-08-20 19:49:13 +0000 | [diff] [blame] | 119 | '*shared*') doconfig=no; continue;; |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 120 | esac |
Guido van Rossum | 0b498be | 1994-08-23 13:49:15 +0000 | [diff] [blame] | 121 | srcs= |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 122 | cpps= |
Guido van Rossum | 7cc5abd | 1994-09-12 10:42:20 +0000 | [diff] [blame] | 123 | libs= |
| 124 | mods= |
Guido van Rossum | 4a26986 | 1995-06-14 22:52:06 +0000 | [diff] [blame] | 125 | skip= |
Guido van Rossum | 7cc5abd | 1994-09-12 10:42:20 +0000 | [diff] [blame] | 126 | for arg in $line |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 127 | do |
Guido van Rossum | 4a26986 | 1995-06-14 22:52:06 +0000 | [diff] [blame] | 128 | case $skip in |
| 129 | libs) libs="$libs $arg"; skip=; continue;; |
| 130 | cpps) cpps="$cpps $arg"; skip=; continue;; |
| 131 | srcs) srcs="$srcs $arg"; skip=; continue;; |
| 132 | esac |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 133 | case $arg in |
| 134 | -[IDUC]*) cpps="$cpps $arg";; |
Guido van Rossum | 7cc5abd | 1994-09-12 10:42:20 +0000 | [diff] [blame] | 135 | -[A-Zl]*) libs="$libs $arg";; |
| 136 | *.a) libs="$libs $arg";; |
Guido van Rossum | a29756c | 1996-08-19 22:00:05 +0000 | [diff] [blame] | 137 | *.so) libs="$libs $arg";; |
| 138 | *.sl) libs="$libs $arg";; |
Guido van Rossum | 7cc5abd | 1994-09-12 10:42:20 +0000 | [diff] [blame] | 139 | *.o) srcs="$srcs `basename $arg .o`.c";; |
Guido van Rossum | 0b498be | 1994-08-23 13:49:15 +0000 | [diff] [blame] | 140 | *.[cC]) srcs="$srcs $arg";; |
| 141 | *.cc) srcs="$srcs $arg";; |
| 142 | *.c++) srcs="$srcs $arg";; |
Sjoerd Mullender | 4237efc | 1995-10-11 08:45:15 +0000 | [diff] [blame] | 143 | \$*) libs="$libs $arg" |
| 144 | cpps="$cpps $arg";; |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 145 | *.*) echo 1>&2 "bad word $arg in $line" |
| 146 | exit 1;; |
Guido van Rossum | 4a26986 | 1995-06-14 22:52:06 +0000 | [diff] [blame] | 147 | -u) skip=libs; libs="$libs -u";; |
Guido van Rossum | 7cc5abd | 1994-09-12 10:42:20 +0000 | [diff] [blame] | 148 | [a-zA-Z_]*) mods="$mods $arg";; |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 149 | *) echo 1>&2 "bad word $arg in $line" |
| 150 | exit 1;; |
| 151 | esac |
| 152 | done |
Guido van Rossum | 7cc5abd | 1994-09-12 10:42:20 +0000 | [diff] [blame] | 153 | case $doconfig in |
| 154 | yes) |
| 155 | LIBS="$LIBS $libs" |
| 156 | MODS="$MODS $mods" |
| 157 | ;; |
| 158 | esac |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 159 | case $noobjects in |
| 160 | yes) continue;; |
| 161 | esac |
Guido van Rossum | 7cc5abd | 1994-09-12 10:42:20 +0000 | [diff] [blame] | 162 | objs='' |
Guido van Rossum | 0b498be | 1994-08-23 13:49:15 +0000 | [diff] [blame] | 163 | for src in $srcs |
| 164 | do |
Guido van Rossum | 7cc5abd | 1994-09-12 10:42:20 +0000 | [diff] [blame] | 165 | case $src in |
| 166 | *.c) obj=`basename $src .c`.o; cc='$(CC)';; |
| 167 | *.cc) obj=`basename $src .cc`.o; cc='$(CCC)';; |
| 168 | *.c++) obj=`basename $src .c++`.o; cc='$(CCC)';; |
| 169 | *.C) obj=`basename $src .C`.o; cc='$(CCC)';; |
| 170 | *) continue;; |
| 171 | esac |
| 172 | objs="$objs $obj" |
| 173 | case $src in |
| 174 | glmodule.c) ;; |
| 175 | *) src='$(srcdir)/'$src;; |
| 176 | esac |
| 177 | case $doconfig in |
Guido van Rossum | 8991065 | 1994-10-20 21:58:30 +0000 | [diff] [blame] | 178 | no) cc="$cc \$(CCSHARED)";; |
Guido van Rossum | 7cc5abd | 1994-09-12 10:42:20 +0000 | [diff] [blame] | 179 | esac |
| 180 | rule="$obj: $src; $cc \$(CFLAGS) $cpps -c $src" |
| 181 | echo "$rule" >>$rulesf |
Guido van Rossum | 0b498be | 1994-08-23 13:49:15 +0000 | [diff] [blame] | 182 | done |
Guido van Rossum | 7cc5abd | 1994-09-12 10:42:20 +0000 | [diff] [blame] | 183 | case $doconfig in |
| 184 | yes) OBJS="$OBJS $objs";; |
| 185 | esac |
| 186 | for mod in $mods |
| 187 | do |
| 188 | case $objs in |
| 189 | *$mod.o*) base=$mod;; |
| 190 | *) base=${mod}module;; |
| 191 | esac |
| 192 | file="$base\$(SO)" |
| 193 | case $doconfig in |
| 194 | no) SHAREDMODS="$SHAREDMODS $file";; |
| 195 | esac |
| 196 | rule="$file: $objs" |
Sjoerd Mullender | 4eba0c9 | 1994-10-13 09:09:05 +0000 | [diff] [blame] | 197 | rule="$rule; \$(LDSHARED) $objs $libs -o $file" |
Guido van Rossum | 7cc5abd | 1994-09-12 10:42:20 +0000 | [diff] [blame] | 198 | echo "$rule" >>$rulesf |
| 199 | done |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 200 | done |
| 201 | |
Guido van Rossum | 7cc5abd | 1994-09-12 10:42:20 +0000 | [diff] [blame] | 202 | case $SHAREDMODS in |
| 203 | '') ;; |
| 204 | *) DEFS="SHAREDMODS=$SHAREDMODS$NL$DEFS";; |
| 205 | esac |
| 206 | |
Guido van Rossum | 0b498be | 1994-08-23 13:49:15 +0000 | [diff] [blame] | 207 | case $noobjects in |
| 208 | yes) BASELIBS=$LIBS;; |
| 209 | *) LOCALLIBS=$LIBS;; |
| 210 | esac |
| 211 | LIBS='$(LOCALMODLIBS) $(BASEMODLIBS)' |
| 212 | DEFS="BASEMODLIBS=$BASELIBS$NL$DEFS" |
| 213 | DEFS="LOCALMODLIBS=$LOCALLIBS$NL$DEFS" |
| 214 | |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 215 | EXTDECLS= |
| 216 | INITBITS= |
| 217 | for mod in $MODS |
| 218 | do |
| 219 | EXTDECLS="${EXTDECLS}extern void init$mod();$NL" |
| 220 | INITBITS="${INITBITS} {\"$mod\", init$mod},$NL" |
| 221 | done |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 222 | |
Guido van Rossum | 7cc5abd | 1994-09-12 10:42:20 +0000 | [diff] [blame] | 223 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 224 | case $config in |
| 225 | -) ;; |
| 226 | *) sed -e " |
| 227 | 1i$NL/* Generated automatically from $config by makesetup. */ |
| 228 | /MARKER 1/i$NL$EXTDECLS |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 229 | /MARKER 2/i$NL$INITBITS |
| 230 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 231 | " $config >config.c |
| 232 | ;; |
| 233 | esac |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 234 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 235 | case $makepre in |
Guido van Rossum | 7cc5abd | 1994-09-12 10:42:20 +0000 | [diff] [blame] | 236 | -) ;; |
| 237 | *) sedf="@sed.in.$$" |
| 238 | trap 'rm -f $sedf' 0 1 2 3 |
| 239 | echo "1i\\" >$sedf |
| 240 | str="# Generated automatically from $makepre by makesetup." |
| 241 | echo "$str" >>$sedf |
Guido van Rossum | 3bbc62e | 1995-01-02 19:30:30 +0000 | [diff] [blame] | 242 | echo "s%_MODOBJS_%$OBJS%" >>$sedf |
| 243 | echo "s%_MODLIBS_%$LIBS%" >>$sedf |
Guido van Rossum | 7cc5abd | 1994-09-12 10:42:20 +0000 | [diff] [blame] | 244 | echo "/Definitions added by makesetup/a$NL$NL$DEFS" >>$sedf |
| 245 | sed -f $sedf $makepre >Makefile |
| 246 | cat $rulesf >>Makefile |
| 247 | rm -f $sedf |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 248 | ;; |
| 249 | esac |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 250 | |
Guido van Rossum | 7cc5abd | 1994-09-12 10:42:20 +0000 | [diff] [blame] | 251 | rm -f $rulesf |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 252 | ) |