| 1 | #! /bin/sh
|
|---|
| 2 |
|
|---|
| 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 .)
|
|---|
| 10 | # -l directory: library source directory (default derived from $0)
|
|---|
| 11 | # -c file: alternative config.c template (default $libdir/config.c.in)
|
|---|
| 12 | # -c -: don't write config.c
|
|---|
| 13 | # -m file: alternative Makefile template (default ./Makefile.pre)
|
|---|
| 14 | # -m -: don't write Makefile
|
|---|
| 15 | #
|
|---|
| 16 | # Remaining arguments are one or more Setup files (default ./Setup).
|
|---|
| 17 | # Setup files after a -n option are used for their variables, modules
|
|---|
| 18 | # and libraries but not for their .o files.
|
|---|
| 19 | #
|
|---|
| 20 | # See Setup.dist for a description of the format of the Setup file.
|
|---|
| 21 | #
|
|---|
| 22 | # The following edits are made:
|
|---|
| 23 | #
|
|---|
| 24 | # Copying config.c.in to config.c:
|
|---|
| 25 | # - insert an identifying comment at the start
|
|---|
| 26 | # - for each <module> mentioned in Setup before *noconfig*:
|
|---|
| 27 | # + insert 'extern void init<module>(void);' before MARKER 1
|
|---|
| 28 | # + insert '{"<module>", initmodule},' before MARKER 2
|
|---|
| 29 | #
|
|---|
| 30 | # Copying Makefile.pre to Makefile:
|
|---|
| 31 | # - insert an identifying comment at the start
|
|---|
| 32 | # - replace _MODOBJS_ by the list of objects from Setup (except for
|
|---|
| 33 | # Setup files after a -n option)
|
|---|
| 34 | # - replace _MODLIBS_ by the list of libraries from Setup
|
|---|
| 35 | # - for each object file mentioned in Setup, append a rule
|
|---|
| 36 | # '<file>.o: <file>.c; <build commands>' to the end of the Makefile
|
|---|
| 37 | # - for each module mentioned in Setup, append a rule
|
|---|
| 38 | # which creates a shared library version to the end of the Makefile
|
|---|
| 39 | # - for each variable definition found in Setup, insert the definition
|
|---|
| 40 | # before the comment 'Definitions added by makesetup'
|
|---|
| 41 |
|
|---|
| 42 | # Loop over command line options
|
|---|
| 43 | usage='
|
|---|
| 44 | usage: makesetup [-s srcdir] [-l libdir] [-c config.c.in] [-m Makefile.pre]
|
|---|
| 45 | [Setup] ... [-n [Setup] ...]'
|
|---|
| 46 | srcdir='.'
|
|---|
| 47 | libdir=''
|
|---|
| 48 | config=''
|
|---|
| 49 | makepre=''
|
|---|
| 50 | noobjects=''
|
|---|
| 51 | doconfig=yes
|
|---|
| 52 | while :
|
|---|
| 53 | do
|
|---|
| 54 | case $1 in
|
|---|
| 55 | -s) shift; srcdir=$1; shift;;
|
|---|
| 56 | -l) shift; libdir=$1; shift;;
|
|---|
| 57 | -c) shift; config=$1; shift;;
|
|---|
| 58 | -m) shift; makepre=$1; shift;;
|
|---|
| 59 | --) shift; break;;
|
|---|
| 60 | -n) noobjects=yes;;
|
|---|
| 61 | -*) echo "$usage" 1>&2; exit 2;;
|
|---|
| 62 | *) break;;
|
|---|
| 63 | esac
|
|---|
| 64 | done
|
|---|
| 65 |
|
|---|
| 66 | # Set default libdir and config if not set by command line
|
|---|
| 67 | # (Not all systems have dirname)
|
|---|
| 68 | case $libdir in
|
|---|
| 69 | '') case $0 in
|
|---|
| 70 | */*) libdir=`echo $0 | sed 's,/[^/]*$,,'`;;
|
|---|
| 71 | *) libdir=.;;
|
|---|
| 72 | esac;;
|
|---|
| 73 | esac
|
|---|
| 74 | case $config in
|
|---|
| 75 | '') config=$libdir/config.c.in;;
|
|---|
| 76 | esac
|
|---|
| 77 | case $makepre in
|
|---|
| 78 | '') makepre=Makefile.pre;;
|
|---|
| 79 | esac
|
|---|
| 80 |
|
|---|
| 81 | # Newline for sed i and a commands
|
|---|
| 82 | NL='\
|
|---|
| 83 | '
|
|---|
| 84 |
|
|---|
| 85 | # Setup to link with extra libraries when makeing shared extensions.
|
|---|
| 86 | # Currently, only Cygwin needs this baggage.
|
|---|
| 87 | case `uname -s` in
|
|---|
| 88 | CYGWIN*) if test $libdir = .
|
|---|
| 89 | then
|
|---|
| 90 | ExtraLibDir=.
|
|---|
| 91 | else
|
|---|
| 92 | ExtraLibDir='$(LIBPL)'
|
|---|
| 93 | fi
|
|---|
| 94 | ExtraLibs="-L$ExtraLibDir -lpython\$(VERSION)";;
|
|---|
| 95 | esac
|
|---|
| 96 |
|
|---|
| 97 | # Main loop
|
|---|
| 98 | for i in ${*-Setup}
|
|---|
| 99 | do
|
|---|
| 100 | case $i in
|
|---|
| 101 | -n) echo '*noobjects*';;
|
|---|
| 102 | *) echo '*doconfig*'; cat "$i";;
|
|---|
| 103 | esac
|
|---|
| 104 | done |
|
|---|
| 105 | sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
|
|---|
| 106 | (
|
|---|
| 107 | rulesf="@rules.$$"
|
|---|
| 108 | trap 'rm -f $rulesf' 0 1 2 3
|
|---|
| 109 | echo "
|
|---|
| 110 | # Rules appended by makedepend
|
|---|
| 111 | " >$rulesf
|
|---|
| 112 | DEFS=
|
|---|
| 113 | MODS=
|
|---|
| 114 | SHAREDMODS=
|
|---|
| 115 | OBJS=
|
|---|
| 116 | LIBS=
|
|---|
| 117 | LOCALLIBS=
|
|---|
| 118 | BASELIBS=
|
|---|
| 119 | while read line
|
|---|
| 120 | do
|
|---|
| 121 | # to handle backslashes for sh's that don't automatically
|
|---|
| 122 | # continue a read when the last char is a backslash
|
|---|
| 123 | while echo $line | grep '\\$' > /dev/null
|
|---|
| 124 | do
|
|---|
| 125 | read extraline
|
|---|
| 126 | line=`echo $line| sed s/.$//`$extraline
|
|---|
| 127 | done
|
|---|
| 128 |
|
|---|
| 129 | # Output DEFS in reverse order so first definition overrides
|
|---|
| 130 | case $line in
|
|---|
| 131 | *=*) DEFS="$line$NL$DEFS"; continue;;
|
|---|
| 132 | 'include '*) DEFS="$line$NL$DEFS"; continue;;
|
|---|
| 133 | '*noobjects*')
|
|---|
| 134 | case $noobjects in
|
|---|
| 135 | yes) ;;
|
|---|
| 136 | *) LOCALLIBS=$LIBS; LIBS=;;
|
|---|
| 137 | esac
|
|---|
| 138 | noobjects=yes;
|
|---|
| 139 | continue;;
|
|---|
| 140 | '*doconfig*') doconfig=yes; continue;;
|
|---|
| 141 | '*static*') doconfig=yes; continue;;
|
|---|
| 142 | '*noconfig*') doconfig=no; continue;;
|
|---|
| 143 | '*shared*') doconfig=no; continue;;
|
|---|
| 144 | esac
|
|---|
| 145 | srcs=
|
|---|
| 146 | cpps=
|
|---|
| 147 | libs=
|
|---|
| 148 | mods=
|
|---|
| 149 | skip=
|
|---|
| 150 | for arg in $line
|
|---|
| 151 | do
|
|---|
| 152 | case $skip in
|
|---|
| 153 | libs) libs="$libs $arg"; skip=; continue;;
|
|---|
| 154 | cpps) cpps="$cpps $arg"; skip=; continue;;
|
|---|
| 155 | srcs) srcs="$srcs $arg"; skip=; continue;;
|
|---|
| 156 | esac
|
|---|
| 157 | case $arg in
|
|---|
| 158 | -framework) libs="$libs $arg"; skip=libs;
|
|---|
| 159 | # OSX/OSXS/Darwin framework link cmd
|
|---|
| 160 | ;;
|
|---|
| 161 | -[IDUCfF]*) cpps="$cpps $arg";;
|
|---|
| 162 | -Xcompiler) skip=cpps;;
|
|---|
| 163 | -Xlinker) libs="$libs $arg"; skip=libs;;
|
|---|
| 164 | -rpath) libs="$libs $arg"; skip=libs;;
|
|---|
| 165 | --rpath) libs="$libs $arg"; skip=libs;;
|
|---|
| 166 | -[A-Zl]*) libs="$libs $arg";;
|
|---|
| 167 | *.a) libs="$libs $arg";;
|
|---|
| 168 | *.so) libs="$libs $arg";;
|
|---|
| 169 | *.sl) libs="$libs $arg";;
|
|---|
| 170 | /*.o) libs="$libs $arg";;
|
|---|
| 171 | *.def) libs="$libs $arg";;
|
|---|
| 172 | *.o) srcs="$srcs `basename $arg .o`.c";;
|
|---|
| 173 | *.[cC]) srcs="$srcs $arg";;
|
|---|
| 174 | *.m) srcs="$srcs $arg";; # Objective-C src
|
|---|
| 175 | *.cc) srcs="$srcs $arg";;
|
|---|
| 176 | *.c++) srcs="$srcs $arg";;
|
|---|
| 177 | *.cxx) srcs="$srcs $arg";;
|
|---|
| 178 | *.cpp) srcs="$srcs $arg";;
|
|---|
| 179 | \$*) libs="$libs $arg"
|
|---|
| 180 | cpps="$cpps $arg";;
|
|---|
| 181 | *.*) echo 1>&2 "bad word $arg in $line"
|
|---|
| 182 | exit 1;;
|
|---|
| 183 | -u) skip=libs; libs="$libs -u";;
|
|---|
| 184 | [a-zA-Z_]*) mods="$mods $arg";;
|
|---|
| 185 | *) echo 1>&2 "bad word $arg in $line"
|
|---|
| 186 | exit 1;;
|
|---|
| 187 | esac
|
|---|
| 188 | done
|
|---|
| 189 | case $doconfig in
|
|---|
| 190 | yes)
|
|---|
| 191 | LIBS="$LIBS $libs"
|
|---|
| 192 | MODS="$MODS $mods"
|
|---|
| 193 | ;;
|
|---|
| 194 | esac
|
|---|
| 195 | case $noobjects in
|
|---|
|
|---|