44# Convert templates into Makefile and config.c, based on the module
55# definitions found in the file Setup.
66#
7- # Usage: makesetup [-s dir] [-c file] [-m file] [Setup] ... [-n [Setup] ...]
7+ # Usage: makesetup [-s dir] [-c file] [-m file] [Setup] ... [-b Setup] ...
8+ # [-n [Setup] ...]
89#
910# Options:
1011# -s directory: alternative source directory (default .)
1112# -l directory: library source directory (default derived from $0)
1213# -c file: alternative config.c template (default $libdir/config.c.in)
13- # -c -: don't write config.c
14+ # -c -: don't write config.c (nor config_bootstrap.c)
1415# -m file: alternative Makefile template (default ./Makefile.pre)
1516# -m -: don't write Makefile
1617#
1718# Remaining arguments are one or more Setup files (default ./Setup).
19+ # The Setup file following a -b option holds the *bootstrap* modules:
20+ # the static modules that the build helper programs (_freeze_module,
21+ # _bootstrap_python) are linked with. They are also regular modules of
22+ # the final build.
1823# Setup files after a -n option are used for their variables, modules
1924# and libraries but not for their .o files.
2025#
2833# + insert 'extern PyObject* PyInit_<module>(void);' before MARKER 1
2934# + insert '{"<module>", PyInit_<module>},' before MARKER 2
3035#
36+ # Copying config.c.in to config_bootstrap.c (only with a -b Setup file):
37+ # - same as config.c, but only for the modules of the -b Setup file
38+ #
3139# Copying Makefile.pre to Makefile:
3240# - insert an identifying comment at the start
3341# - replace _MODBUILT_NAMES_ by the list of *static* and *shared* modules
3745# - replace _MODOBJS_ by the list of objects from Setup (except for
3846# Setup files after a -n option)
3947# - replace _MODLIBS_ by the list of libraries from Setup
48+ # - replace _BOOTSTRAP_MODOBJS_ and _BOOTSTRAP_MODLIBS_ by the objects and
49+ # libraries of the -b Setup file
4050# - for each object file mentioned in Setup, append a rule
4151# '<file>.o: <file>.c; <build commands>' to the end of the Makefile
4252# - for each module mentioned in Setup, append a rule
@@ -47,13 +57,14 @@ set -e
4757# Loop over command line options
4858usage='
4959usage: makesetup [-s srcdir] [-l libdir] [-c config.c.in] [-m Makefile.pre]
50- [Setup] ... [-n [Setup] ...]'
60+ [Setup] ... [-b Setup] ... [- n [Setup] ...]'
5161srcdir=' .'
5262libdir=' '
5363config=' '
5464makepre=' '
5565noobjects=' '
5666doconfig=yes
67+ bootstrap=
5768while :
5869do
5970 case $1 in
93104 echo ' ' # Add a linebreak so we don't choke on files missing EOL.
94105 case $i in
95106 -n) echo ' *noobjects*' ;;
96- * ) echo ' *doconfig*' ; cat " $i " ;;
107+ -b) echo ' *bootstrap*' ;;
108+ * ) echo ' *doconfig*' ; cat " $i " ; echo ' ' ; echo ' *nobootstrap*' ;;
97109 esac
98110done |
99111sed -e ' s/[ ]*#.*//' -e ' /^[ ]*$/d' |
@@ -114,6 +126,10 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
114126 LIBS=
115127 LOCALLIBS=
116128 BASELIBS=
129+ BOOTMODS=
130+ BOOTOBJS=
131+ BOOTLIBS=
132+ havebootstrap=
117133 while read line
118134 do
119135 # to handle backslashes for sh's that don't automatically
@@ -136,6 +152,8 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
136152 noobjects=yes;
137153 continue ;;
138154 ' *doconfig*' ) doconfig=yes; continue ;;
155+ ' *bootstrap*' ) bootstrap=yes; havebootstrap=yes; continue ;;
156+ ' *nobootstrap*' ) bootstrap=; continue ;;
139157 ' *static*' ) doconfig=yes; continue ;;
140158 ' *noconfig*' ) doconfig=no; continue ;;
141159 ' *shared*' ) doconfig=no; continue ;;
@@ -204,6 +222,18 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
204222 # Detected multiple rules for a module, first rule wins. This
205223 # allows users to disable modules in Setup.local.
206224 echo 1>&2 " maksetup: '$mod ' was handled by previous rule."
225+ case $bootstrap in
226+ yes)
227+ # This module is in the bootstrap Setup file, but an
228+ # earlier Setup file (e.g. Setup.local) already defined
229+ # it, and that definition won. Give the build helpers
230+ # that earlier definition, so they use the same module
231+ # as the final interpreter.
232+ eval " BOOTMODS=\"\$ BOOTMODS \$ {STATICMOD_$mod }\" "
233+ eval " BOOTOBJS=\"\$ BOOTOBJS \$ {STATICOBJS_$mod }\" "
234+ eval " BOOTLIBS=\"\$ BOOTLIBS \$ {STATICLIBS_$mod }\" "
235+ ;;
236+ esac
207237 continue 2;;
208238 esac
209239 CONFIGURED=" $CONFIGURED ,${mod} ,"
@@ -213,6 +243,12 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
213243 LIBS=" $LIBS $libs "
214244 MODS=" $MODS $mods "
215245 BUILT=" $BUILT $mods "
246+ case $bootstrap in
247+ yes)
248+ BOOTLIBS=" $BOOTLIBS $libs "
249+ BOOTMODS=" $BOOTMODS $mods "
250+ ;;
251+ esac
216252 ;;
217253 no)
218254 BUILT=" $BUILT $mods "
@@ -265,7 +301,21 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
265301 echo " $rule " >> $rulesf
266302 done
267303 case $doconfig in
268- yes) OBJS=" $OBJS $objs " ;;
304+ yes)
305+ OBJS=" $OBJS $objs "
306+ case $bootstrap in
307+ yes) BOOTOBJS=" $BOOTOBJS $objs " ;;
308+ esac
309+ # Record each static module's objects and libs by name, so
310+ # the bootstrap handling above can find a definition that
311+ # won over a later line in the bootstrap Setup file.
312+ for mod in $mods
313+ do
314+ eval " STATICMOD_$mod ='$mod '"
315+ eval " STATICOBJS_$mod ='$objs '"
316+ eval " STATICLIBS_$mod ='$libs '"
317+ done
318+ ;;
269319 esac
270320 for mod in $mods
271321 do
@@ -295,24 +345,31 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
295345 DEFS=" BASEMODLIBS=$BASELIBS$NL$DEFS "
296346 DEFS=" LOCALMODLIBS=$LOCALLIBS$NL$DEFS "
297347
298- EXTDECLS=
299- INITBITS=
300- for mod in $MODS
301- do
302- EXTDECLS=" ${EXTDECLS} extern PyObject* PyInit_$mod (void);$NL "
303- INITBITS=" ${INITBITS} {\" $mod \" , PyInit_$mod },$NL "
304- done
305-
306-
307- case $config in
308- -) ;;
309- * ) sed -e "
348+ # Generate a config.c from the template for the given modules
349+ genconfig () {
350+ out=$1 ; shift
351+ EXTDECLS=
352+ INITBITS=
353+ for mod
354+ do
355+ EXTDECLS=" ${EXTDECLS} extern PyObject* PyInit_$mod (void);$NL "
356+ INITBITS=" ${INITBITS} {\" $mod \" , PyInit_$mod },$NL "
357+ done
358+ sed -e "
310359 1i$NL /* Generated automatically from $config by makesetup. */
311360 /MARKER 1/i$NL$EXTDECLS
312361
313362 /MARKER 2/i$NL$INITBITS
314363
315- " $config > config.c
364+ " $config > $out
365+ }
366+
367+ case $config in
368+ -) ;;
369+ * ) genconfig config.c $MODS
370+ case $havebootstrap in
371+ yes) genconfig config_bootstrap.c $BOOTMODS ;;
372+ esac
316373 ;;
317374 esac
318375
@@ -331,6 +388,9 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
331388 echo " s%_MODBUILT_NAMES_%$BUILT %" >> $sedf
332389 echo " s%_MODSHARED_NAMES_%$BUILT_SHARED %" >> $sedf
333390 echo " s%_MODDISABLED_NAMES_%$DISABLED %" >> $sedf
391+ # _BOOTSTRAP_* first: _MODOBJS_ is a substring of _BOOTSTRAP_MODOBJS_
392+ echo " s%_BOOTSTRAP_MODOBJS_%$BOOTOBJS %" >> $sedf
393+ echo " s%_BOOTSTRAP_MODLIBS_%$BOOTLIBS %" >> $sedf
334394 echo " s%_MODOBJS_%$OBJS %" >> $sedf
335395 echo " s%_MODLIBS_%$LIBS %" >> $sedf
336396 echo " /Definitions added by makesetup/r $sedr " >> $sedf
0 commit comments