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 |
| 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 Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 39 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 40 | # Loop over command line options |
| 41 | usage=' |
| 42 | usage: makesetup [-s srcdir] [-c config.c.in] [-m Makefile.pre] |
| 43 | [Setup] ... [-n [Setup] ...]' |
| 44 | srcdir='' |
| 45 | config='' |
| 46 | makepre='' |
| 47 | noobjects='' |
| 48 | while : |
| 49 | do |
| 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 |
| 59 | done |
| 60 | |
| 61 | # Set default srcdir and config if not set by command line |
| 62 | # (Not all systems have dirname) |
| 63 | case $srcdir in |
| 64 | '') case $0 in |
| 65 | */*) srcdir=`echo $0 | sed 's,/[^/]*$,,'`;; |
| 66 | *) srcdir=.;; |
| 67 | esac;; |
| 68 | esac |
| 69 | case $config in |
| 70 | '') config=$srcdir/config.c.in;; |
| 71 | esac |
| 72 | case $makepre in |
| 73 | '') makepre=Makefile.pre;; |
| 74 | esac |
| 75 | |
| 76 | # Newline for sed i and a commands |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 77 | NL="\\ |
| 78 | " |
| 79 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 80 | # Main loop |
| 81 | for i in ${*-Setup} |
| 82 | do |
| 83 | case $i in |
| 84 | -n) echo '<noobjects>';; |
| 85 | *) cat "$i";; |
| 86 | esac |
| 87 | done | |
| 88 | sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' | |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 89 | ( |
| 90 | DEFS= |
| 91 | MODS= |
| 92 | OBJS= |
| 93 | LIBS= |
| 94 | RULES= |
Guido van Rossum | 0b498be | 1994-08-23 13:49:15 +0000 | [diff] [blame] | 95 | LOCALLIBS= |
| 96 | BASELIBS= |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 97 | while read line |
| 98 | do |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 99 | # Output DEFS in reverse order so first definition overrides |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 100 | case $line in |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 101 | *=*) DEFS="$line$NL$DEFS"; continue;; |
Guido van Rossum | 0b498be | 1994-08-23 13:49:15 +0000 | [diff] [blame] | 102 | '<noobjects>') |
| 103 | case $noobjects in |
| 104 | yes) ;; |
| 105 | *) LOCALLIBS=$LIBS; LIBS=;; |
| 106 | esac |
| 107 | noobjects=yes; |
| 108 | continue;; |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 109 | esac |
| 110 | objs= |
Guido van Rossum | 0b498be | 1994-08-23 13:49:15 +0000 | [diff] [blame] | 111 | srcs= |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 112 | cpps= |
| 113 | set $line |
| 114 | for arg |
| 115 | do |
| 116 | case $arg in |
| 117 | -[IDUC]*) cpps="$cpps $arg";; |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 118 | -[A-Zl]*) LIBS="$LIBS $arg";; |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 119 | *.a) LIBS="$LIBS $arg";; |
| 120 | *.o) objs="$objs $arg";; |
Guido van Rossum | 0b498be | 1994-08-23 13:49:15 +0000 | [diff] [blame] | 121 | *.[cC]) srcs="$srcs $arg";; |
| 122 | *.cc) srcs="$srcs $arg";; |
| 123 | *.c++) srcs="$srcs $arg";; |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 124 | *.*) 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 Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 131 | case $noobjects in |
| 132 | yes) continue;; |
| 133 | esac |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 134 | for obj in $objs |
| 135 | do |
| 136 | src=`basename $obj .o`.c |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 137 | case $src in |
| 138 | glmodule.c) ;; |
| 139 | *) src='$(srcdir)/'$src;; |
| 140 | esac |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 141 | RULES="$RULES$obj: $src; \$(CC) \$(CFLAGS) $cpps -c $src$NL" |
| 142 | done |
| 143 | OBJS="$OBJS $objs" |
Guido van Rossum | 224b289 | 1994-08-30 09:27:16 +0000 | [diff] [blame] | 144 | objs= |
Guido van Rossum | 0b498be | 1994-08-23 13:49:15 +0000 | [diff] [blame] | 145 | 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 Rossum | 224b289 | 1994-08-30 09:27:16 +0000 | [diff] [blame] | 154 | objs="$objs $obj" |
Guido van Rossum | 0b498be | 1994-08-23 13:49:15 +0000 | [diff] [blame] | 155 | 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 Rossum | 224b289 | 1994-08-30 09:27:16 +0000 | [diff] [blame] | 161 | OBJS="$OBJS $objs" |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 162 | done |
| 163 | |
Guido van Rossum | 0b498be | 1994-08-23 13:49:15 +0000 | [diff] [blame] | 164 | 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 Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 172 | 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 Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 179 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 180 | case $config in |
| 181 | -) ;; |
| 182 | *) sed -e " |
| 183 | 1i$NL/* Generated automatically from $config by makesetup. */ |
| 184 | /MARKER 1/i$NL$EXTDECLS |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 185 | /MARKER 2/i$NL$INITBITS |
| 186 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 187 | " $config >config.c |
| 188 | ;; |
| 189 | esac |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 190 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 191 | case $makepre in |
| 192 | -) ;; |
| 193 | *) sed -e " |
| 194 | 1i$NL# Generated automatically from $makepre by makesetup. |
Guido van Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 195 | s%@MODOBJS@%$OBJS% |
| 196 | s%@MODLIBS@%$LIBS% |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 197 | /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 Rossum | fba715a | 1994-01-02 00:26:09 +0000 | [diff] [blame] | 203 | |
| 204 | ) |