3
# Convert templates into Makefile and config.c, based on the module
4
# definitions found in the file Setup.
6
# Usage: makesetup [-s dir] [-c file] [-m file] [Setup] ... [-n [Setup] ...]
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
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.
20
# See Setup.dist for a description of the format of the Setup file.
22
# The following edits are made:
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 PyObject* PyInit_<module>(void);' before MARKER 1
28
# + insert '{"<module>", PyInit_<module>},' before MARKER 2
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'
42
# Loop over command line options
44
usage: makesetup [-s srcdir] [-l libdir] [-c config.c.in] [-m Makefile.pre]
45
[Setup] ... [-n [Setup] ...]'
55
-s) shift; srcdir=$1; shift;;
56
-l) shift; libdir=$1; shift;;
57
-c) shift; config=$1; shift;;
58
-m) shift; makepre=$1; shift;;
61
-*) echo "$usage" 1>&2; exit 2;;
66
# Set default libdir and config if not set by command line
67
# (Not all systems have dirname)
70
*/*) libdir=`echo $0 | sed 's,/[^/]*$,,'`;;
75
'') config=$libdir/config.c.in;;
78
'') makepre=Makefile.pre;;
81
# Newline for sed i and a commands
85
# Setup to link with extra libraries when makeing shared extensions.
86
# Currently, only Cygwin needs this baggage.
88
CYGWIN*) if test $libdir = .
92
ExtraLibDir='$(LIBPL)'
94
ExtraLibs="-L$ExtraLibDir -lpython\$(VERSION)";;
101
-n) echo '*noobjects*';;
102
*) echo '*doconfig*'; cat "$i";;
105
sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
108
trap 'rm -f $rulesf' 0 1 2 3
110
# Rules appended by makedepend
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
126
line=`echo $line| sed s/.$//`$extraline
129
# Output DEFS in reverse order so first definition overrides
131
*=*) DEFS="$line$NL$DEFS"; continue;;
132
'include '*) DEFS="$line$NL$DEFS"; continue;;
136
*) LOCALLIBS=$LIBS; LIBS=;;
140
'*doconfig*') doconfig=yes; continue;;
141
'*static*') doconfig=yes; continue;;
142
'*noconfig*') doconfig=no; continue;;
143
'*shared*') doconfig=no; continue;;
153
libs) libs="$libs $arg"; skip=; continue;;
154
cpps) cpps="$cpps $arg"; skip=; continue;;
155
srcs) srcs="$srcs $arg"; skip=; continue;;
158
-framework) libs="$libs $arg"; skip=libs;
159
# OSX/OSXS/Darwin framework link cmd
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"
181
*.*) echo 1>&2 "bad word $arg in $line"
183
-u) skip=libs; libs="$libs -u";;
184
[a-zA-Z_]*) mods="$mods $arg";;
185
*) echo 1>&2 "bad word $arg in $line"
202
*.c) obj=`basename $src .c`.o; cc='$(CC)';;
203
*.cc) obj=`basename $src .cc`.o; cc='$(CXX)';;
204
*.c++) obj=`basename $src .c++`.o; cc='$(CXX)';;
205
*.C) obj=`basename $src .C`.o; cc='$(CXX)';;
206
*.cxx) obj=`basename $src .cxx`.o; cc='$(CXX)';;
207
*.cpp) obj=`basename $src .cpp`.o; cc='$(CXX)';;
208
*.m) obj=`basename $src .m`.o; cc='$(CC)';; # Obj-C
217
*) src='$(srcdir)/'"$srcdir/$src";;
220
no) cc="$cc \$(CCSHARED) \$(PY_CFLAGS) \$(PY_CPPFLAGS)";;
222
cc="$cc \$(PY_CORE_CFLAGS)";;
224
rule="$obj: $src; $cc $cpps -c $src -o $obj"
225
echo "$rule" >>$rulesf
228
yes) OBJS="$OBJS $objs";;
232
file="$srcdir/$mod\$(EXT_SUFFIX)"
234
no) SHAREDMODS="$SHAREDMODS $file";;
237
rule="$rule; \$(BLDSHARED) $objs $libs $ExtraLibs -o $file"
238
echo "$rule" >>$rulesf
244
*) DEFS="SHAREDMODS=$SHAREDMODS$NL$DEFS";;
248
yes) BASELIBS=$LIBS;;
251
LIBS='$(LOCALMODLIBS) $(BASEMODLIBS)'
252
DEFS="BASEMODLIBS=$BASELIBS$NL$DEFS"
253
DEFS="LOCALMODLIBS=$LOCALLIBS$NL$DEFS"
259
EXTDECLS="${EXTDECLS}extern PyObject* PyInit_$mod(void);$NL"
260
INITBITS="${INITBITS} {\"$mod\", PyInit_$mod},$NL"
267
1i$NL/* Generated automatically from $config by makesetup. */
268
/MARKER 1/i$NL$EXTDECLS
270
/MARKER 2/i$NL$INITBITS
279
trap 'rm -f $sedf' 0 1 2 3
281
str="# Generated automatically from $makepre by makesetup."
283
echo "s%_MODOBJS_%$OBJS%" >>$sedf
284
echo "s%_MODLIBS_%$LIBS%" >>$sedf
285
echo "/Definitions added by makesetup/a$NL$NL$DEFS" >>$sedf
286
sed -f $sedf $makepre >Makefile
287
cat $rulesf >>Makefile