|
| 1 | +# Universal Unix Makefile for Python extensions |
| 2 | +# ============================================= |
| 3 | + |
| 4 | +# Short Instructions |
| 5 | +# ------------------ |
| 6 | + |
| 7 | +# 1. Build and install Python (1.4 or newer). |
| 8 | +# 2. "make -f Makefile.pre.in boot" |
| 9 | +# 3. "make" |
| 10 | +# You should now have a shared library. |
| 11 | + |
| 12 | +# Long Instructions |
| 13 | +# ----------------- |
| 14 | + |
| 15 | +# Build *and install* the basic Python 1.4 distribution. See the |
| 16 | +# Python README for instructions. |
| 17 | + |
| 18 | +# Create a file Setup.in for your extension. This file follows the |
| 19 | +# format of the Modules/Setup.in file; see the instructions there. |
| 20 | +# For a simple module called "spam" on file "spammodule.c", it can |
| 21 | +# contain a single line: |
| 22 | +# spam spammodule.c |
| 23 | +# You can build as many modules as you want in the same directory -- |
| 24 | +# just have a separate line for each of them in the Setup.in file. |
| 25 | + |
| 26 | +# If you want to build your extension as a shared library, insert a |
| 27 | +# line containing just the string |
| 28 | +# *shared* |
| 29 | +# at the top of your Setup.in file. |
| 30 | + |
| 31 | +# Note that the build process copies Setup.in to Setup, and then works |
| 32 | +# with Setup. It doesn't overwrite Setup when Setup.in is changed, so |
| 33 | +# while you're in the process of debugging your Setup.in file, you may |
| 34 | +# want to edit Setup instead, and copy it back to Setup.in later. |
| 35 | +# (All this is done so you can distribute your extension easily and |
| 36 | +# someone else can select the modules they actually want to build by |
| 37 | +# commenting out lines in the Setup file, without editing the |
| 38 | +# original. Editing Setup is also used to specify nonstandard |
| 39 | +# locations for include or library files.) |
| 40 | + |
| 41 | +# Copy this file (Misc/Makefile.pre.in) to the directory containing |
| 42 | +# your extension. |
| 43 | + |
| 44 | +# Run "make -f Makefile.pre.in boot". This creates Makefile |
| 45 | +# (producing Makefile.pre and sedscript as intermediate files) and |
| 46 | +# config.c, incorporating the values for sys.prefix, sys.exec_prefix |
| 47 | +# and sys.version from the installed Python binary. For this to work, |
| 48 | +# the python binary must be on your path. If this fails, try |
| 49 | +# make -f Makefile.pre.in Makefile VERSION=1.4 installdir=<prefix> |
| 50 | +# where <prefix> is the prefix used to install Python for installdir |
| 51 | +# (and possibly similar for exec_installdir=<exec_prefix>). |
| 52 | + |
| 53 | +# If you are building your extension as a shared library (your |
| 54 | +# Setup.in file starts with *shared*), run "make" or "make sharedmods" |
| 55 | +# to build the shared library files. If you are building a statically |
| 56 | +# linked Python binary (the only solution of your platform doesn't |
| 57 | +# support shared libraries, and sometimes handy if you want to |
| 58 | +# distribute or install the resulting Python binary), run "make |
| 59 | +# python". |
| 60 | + |
| 61 | +# Note: Each time you edit Makefile.pre.in or Setup, you must run |
| 62 | +# "make Makefile" before running "make". |
| 63 | + |
| 64 | +# Hint: if you want to use VPATH, you can start in an empty |
| 65 | +# subdirectory and say (e.g.): |
| 66 | +# make -f ../Makefile.pre.in boot srcdir=.. VPATH=.. |
| 67 | + |
| 68 | + |
| 69 | +# === Bootstrap variables (edited through "make boot") === |
| 70 | + |
| 71 | +# The prefix used by "make inclinstall libainstall" of core python |
| 72 | +installdir= /usr/local |
| 73 | + |
| 74 | +# The exec_prefix used by the same |
| 75 | +exec_installdir=$(installdir) |
| 76 | + |
| 77 | +# Source directory and VPATH in case you want to use VPATH. |
| 78 | +# (You will have to edit these two lines yourself -- there is no |
| 79 | +# automatic support as the Makefile is not generated by |
| 80 | +# config.status.) |
| 81 | +srcdir= . |
| 82 | +VPATH= . |
| 83 | + |
| 84 | +# === Variables that you may want to customize (rarely) === |
| 85 | + |
| 86 | +# Add more -I and -D options here |
| 87 | +CFLAGS= $(OPT) -I$(INCLUDEPY) -I$(LIBPL) $(DEFS) |
| 88 | + |
| 89 | +# These two variables can be set in Setup to merge extensions. |
| 90 | +# See example[23]. |
| 91 | +BASELIB= |
| 92 | +BASESETUP= |
| 93 | + |
| 94 | +# === Variables set by makesetup === |
| 95 | + |
| 96 | +MODOBJS= _MODOBJS_ |
| 97 | +MODLIBS= _MODLIBS_ |
| 98 | + |
| 99 | +# === Definitions added by makesetup === |
| 100 | + |
| 101 | +# === Variables from configure (through sedscript) === |
| 102 | + |
| 103 | +VERSION= @VERSION@ |
| 104 | +CC= @CC@ |
| 105 | +OPT= @OPT@ |
| 106 | +LDFLAGS= @LDFLAGS@ |
| 107 | +DEFS= @DEFS@ |
| 108 | +LIBS= @LIBS@ |
| 109 | +LIBM= @LIBM@ |
| 110 | +LIBC= @LIBC@ |
| 111 | +RANLIB= @RANLIB@ |
| 112 | +MACHDEP= @MACHDEP@ |
| 113 | +SO= @SO@ |
| 114 | +LDSHARED= @LDSHARED@ |
| 115 | +CCSHARED= @CCSHARED@ |
| 116 | +LINKFORSHARED= @LINKFORSHARED@ |
| 117 | + |
| 118 | +# Install prefix for architecture-independent files |
| 119 | +prefix= /usr/local |
| 120 | + |
| 121 | +# Install prefix for architecture-dependent files |
| 122 | +exec_prefix= $(prefix) |
| 123 | + |
| 124 | +# === Fixed definitions === |
| 125 | + |
| 126 | +# Expanded directories |
| 127 | +BINDIR= $(exec_installdir)/bin |
| 128 | +LIBDIR= $(exec_prefix)/lib |
| 129 | +MANDIR= $(installdir)/man |
| 130 | +INCLUDEDIR= $(installdir)/include |
| 131 | +SCRIPTDIR= $(prefix)/lib |
| 132 | + |
| 133 | +# Detailed destination directories |
| 134 | +BINLIBDEST= $(LIBDIR)/python$(VERSION) |
| 135 | +LIBDEST= $(SCRIPTDIR)/python$(VERSION) |
| 136 | +INCLUDEPY= $(INCLUDEDIR)/python$(VERSION) |
| 137 | +LIBP= $(exec_installdir)/lib/python$(VERSION) |
| 138 | + |
| 139 | +LIBPL= $(LIBP)/config |
| 140 | + |
| 141 | +PYTHONLIBS= $(LIBPL)/libModules.a \ |
| 142 | + $(LIBPL)/libPython.a \ |
| 143 | + $(LIBPL)/libObjects.a \ |
| 144 | + $(LIBPL)/libParser.a |
| 145 | + |
| 146 | +MAKESETUP= $(LIBPL)/makesetup |
| 147 | +MAKEFILE= $(LIBPL)/Makefile |
| 148 | +CONFIGC= $(LIBPL)/config.c |
| 149 | +CONFIGCIN= $(LIBPL)/config.c.in |
| 150 | +SETUP= $(LIBPL)/Setup |
| 151 | + |
| 152 | +SYSLIBS= $(LIBM) $(LIBC) |
| 153 | + |
| 154 | +ADDOBJS= $(LIBPL)/main.o getpath.o config.o |
| 155 | + |
| 156 | +# === Fixed rules === |
| 157 | + |
| 158 | +# Default target. This builds shared libraries only |
| 159 | +default: sharedmods |
| 160 | + |
| 161 | +# Build everything |
| 162 | +all: python sharedmods |
| 163 | + |
| 164 | +# Build shared libraries from our extension modules |
| 165 | +sharedmods: $(SHAREDMODS) |
| 166 | + |
| 167 | +# Build a static Python binary containing our extension modules |
| 168 | +python: $(ADDOBJS) lib.a $(PYTHONLIBS) Makefile $(BASELIB) |
| 169 | + $(CC) $(LDFLAGS) $(ADDOBJS) lib.a $(PYTHONLIBS) \ |
| 170 | + $(LINKPATH) $(BASELIB) $(MODLIBS) $(LIBS) $(SYSLIBS) -o python |
| 171 | + |
| 172 | +# Build the library containing our extension modules |
| 173 | +lib.a: $(MODOBJS) |
| 174 | + -rm -f lib.a |
| 175 | + ar cr lib.a $(MODOBJS) |
| 176 | + -$(RANLIB) lib.a || \ |
| 177 | + echo "don't worry if ranlib fails -- probably SYSV or equiv" |
| 178 | + |
| 179 | +# This runs makesetup *twice* to use the BASESETUP definition from Setup |
| 180 | +config.c Makefile: Makefile.pre Setup $(BASESETUP) $(MAKESETUP) |
| 181 | + $(MAKESETUP) \ |
| 182 | + -m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP) |
| 183 | + $(MAKE) -f Makefile do-it-again |
| 184 | + |
| 185 | +# Internal target to run makesetup for the second time |
| 186 | +do-it-again: |
| 187 | + $(MAKESETUP) \ |
| 188 | + -m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP) |
| 189 | + |
| 190 | +# Make config.o from the config.c created by makesetup |
| 191 | +config.o: config.c |
| 192 | + $(CC) $(CFLAGS) -c config.c |
| 193 | + |
| 194 | +# Make our own private getpath.o from the installed source and our PYTHONPATH |
| 195 | +getpath.o: $(LIBPL)/getpath.c Makefile |
| 196 | + $(CC) $(CFLAGS) -DPYTHONPATH=\"$(PYTHONPATH)\" -c $(LIBPL)/getpath.c |
| 197 | + |
| 198 | +# Setup is copied from Setup.in *only* if it doesn't yet exist |
| 199 | +Setup: |
| 200 | + cp $(srcdir)/Setup.in Setup |
| 201 | + |
| 202 | +# Make the intermediate Makefile.pre from Makefile.pre.in |
| 203 | +Makefile.pre: Makefile.pre.in sedscript |
| 204 | + sed -f sedscript $(srcdir)/Makefile.pre.in >Makefile.pre |
| 205 | + |
| 206 | +# Shortcuts to make the sed arguments on one line |
| 207 | +P=prefix |
| 208 | +E=exec_prefix |
| 209 | +H=Generated automatically from Makefile.pre.in by sedscript. |
| 210 | +L=LINKFORSHARED |
| 211 | + |
| 212 | +# Make the sed script used to create Makefile.pre from Makefile.pre.in |
| 213 | +sedscript: $(MAKEFILE) |
| 214 | + sed -n \ |
| 215 | + -e '1s/.*/1i\\/p' \ |
| 216 | + -e '2s%.*%# $H%p' \ |
| 217 | + -e '/^VERSION=/s/^VERSION=[ ]*\(.*\)/s%@VERSION[@]%\1%/p' \ |
| 218 | + -e '/^CC=/s/^CC=[ ]*\(.*\)/s%@CC[@]%\1%/p' \ |
| 219 | + -e '/^OPT=/s/^OPT=[ ]*\(.*\)/s%@OPT[@]%\1%/p' \ |
| 220 | + -e '/^LDFLAGS=/s/^LDFLAGS=[ ]*\(.*\)/s%@LDFLAGS[@]%\1%/p' \ |
| 221 | + -e '/^DEFS=/s/^DEFS=[ ]*\(.*\)/s%@DEFS[@]%\1%/p' \ |
| 222 | + -e '/^LIBS=/s/^LIBS=[ ]*\(.*\)/s%@LIBS[@]%\1%/p' \ |
| 223 | + -e '/^LIBM=/s/^LIBM=[ ]*\(.*\)/s%@LIBM[@]%\1%/p' \ |
| 224 | + -e '/^LIBC=/s/^LIBC=[ ]*\(.*\)/s%@LIBC[@]%\1%/p' \ |
| 225 | + -e '/^RANLIB=/s/^RANLIB=[ ]*\(.*\)/s%@RANLIB[@]%\1%/p' \ |
| 226 | + -e '/^MACHDEP=/s/^MACHDEP=[ ]*\(.*\)/s%@MACHDEP[@]%\1%/p' \ |
| 227 | + -e '/^SO=/s/^SO=[ ]*\(.*\)/s%@SO[@]%\1%/p' \ |
| 228 | + -e '/^LDSHARED=/s/^LDSHARED=[ ]*\(.*\)/s%@LDSHARED[@]%\1%/p' \ |
| 229 | + -e '/^CCSHARED=/s/^CCSHARED=[ ]*\(.*\)/s%@CCSHARED[@]%\1%/p' \ |
| 230 | + -e '/^$L=/s/^$L=[ ]*\(.*\)/s%@$L[@]%\1%/p' \ |
| 231 | + -e '/^$P=/s/^$P=\(.*\)/s%^$P=.*%$P=\1%/p' \ |
| 232 | + -e '/^$E=/s/^$E=\(.*\)/s%^$E=.*%$E=\1%/p' \ |
| 233 | + $(MAKEFILE) >sedscript |
| 234 | + echo "/^installdir=/s%=.*%= $(installdir)%" >>sedscript |
| 235 | + echo "/^exec_installdir=/s%=.*%=$(exec_installdir)%" >>sedscript |
| 236 | + echo "/^srcdir=/s%=.*%= $(srcdir)%" >>sedscript |
| 237 | + echo "/^VPATH=/s%=.*%= $(VPATH)%" >>sedscript |
| 238 | + echo "/^LINKPATH=/s%=.*%= $(LINKPATH)%" >>sedscript |
| 239 | + echo "/^BASELIB=/s%=.*%= $(BASELIB)%" >>sedscript |
| 240 | + echo "/^BASESETUP=/s%=.*%= $(BASESETUP)%" >>sedscript |
| 241 | + |
| 242 | +# Bootstrap target |
| 243 | +boot: |
| 244 | + VERSION=`python -c "import sys; print sys.version[:3]"`; \ |
| 245 | + installdir=`python -c "import sys; print sys.prefix"`; \ |
| 246 | + exec_installdir=`python -c "import sys; print sys.exec_prefix"`; \ |
| 247 | + make -f Makefile.pre.in Makefile VPATH=$(VPATH) srcdir=$(srcdir) \ |
| 248 | + VERSION=$$VERSION \ |
| 249 | + installdir=$$installdir \ |
| 250 | + exec_installdir=$$exec_installdir |
| 251 | + |
| 252 | +# Handy target to remove intermediate files and backups |
| 253 | +clean: |
| 254 | + -rm -f *.o *~ |
| 255 | + |
| 256 | +# Handy target to remove everything that is easily regenerated |
| 257 | +clobber: clean |
| 258 | + -rm -f *.a tags TAGS config.c Makefile.pre python sedscript |
| 259 | + -rm -f *.so *.sl so_locations |
| 260 | + |
| 261 | + |
| 262 | +# Handy target to remove everything you don't want to distribute |
| 263 | +distclean: clobber |
| 264 | + -rm -f Makefile Setup |
0 commit comments