blob: e3ad693afcfb65fa1273a4a96f5e8a4c36cbf976 [file] [log] [blame]
Guido van Rossum1631cbe1996-09-10 18:19:23 +00001# Universal Unix Makefile for Python extensions
2# =============================================
3
4# Short Instructions
5# ------------------
6
Guido van Rossumbef03ae1997-07-19 22:52:43 +00007# 1. Build and install Python (1.5 or newer).
Guido van Rossum1631cbe1996-09-10 18:19:23 +00008# 2. "make -f Makefile.pre.in boot"
9# 3. "make"
10# You should now have a shared library.
11
12# Long Instructions
13# -----------------
14
Guido van Rossumbef03ae1997-07-19 22:52:43 +000015# Build *and install* the basic Python 1.5 distribution. See the
16# Python README for instructions. (This version of Makefile.pre.in
17# only withs with Python 1.5, alpha 3 or newer.)
Guido van Rossum1631cbe1996-09-10 18:19:23 +000018
19# Create a file Setup.in for your extension. This file follows the
20# format of the Modules/Setup.in file; see the instructions there.
21# For a simple module called "spam" on file "spammodule.c", it can
22# contain a single line:
23# spam spammodule.c
24# You can build as many modules as you want in the same directory --
25# just have a separate line for each of them in the Setup.in file.
26
27# If you want to build your extension as a shared library, insert a
28# line containing just the string
29# *shared*
30# at the top of your Setup.in file.
31
32# Note that the build process copies Setup.in to Setup, and then works
33# with Setup. It doesn't overwrite Setup when Setup.in is changed, so
34# while you're in the process of debugging your Setup.in file, you may
35# want to edit Setup instead, and copy it back to Setup.in later.
36# (All this is done so you can distribute your extension easily and
37# someone else can select the modules they actually want to build by
38# commenting out lines in the Setup file, without editing the
39# original. Editing Setup is also used to specify nonstandard
40# locations for include or library files.)
41
42# Copy this file (Misc/Makefile.pre.in) to the directory containing
43# your extension.
44
45# Run "make -f Makefile.pre.in boot". This creates Makefile
46# (producing Makefile.pre and sedscript as intermediate files) and
47# config.c, incorporating the values for sys.prefix, sys.exec_prefix
48# and sys.version from the installed Python binary. For this to work,
49# the python binary must be on your path. If this fails, try
Guido van Rossumbef03ae1997-07-19 22:52:43 +000050# make -f Makefile.pre.in Makefile VERSION=1.5 installdir=<prefix>
Guido van Rossum1631cbe1996-09-10 18:19:23 +000051# where <prefix> is the prefix used to install Python for installdir
52# (and possibly similar for exec_installdir=<exec_prefix>).
53
Guido van Rossumbec74841996-11-27 19:38:53 +000054# Note: "make boot" implies "make clobber" -- it assumes that when you
55# bootstrap you may have changed platforms so it removes all previous
56# output files.
57
Guido van Rossum1631cbe1996-09-10 18:19:23 +000058# If you are building your extension as a shared library (your
59# Setup.in file starts with *shared*), run "make" or "make sharedmods"
60# to build the shared library files. If you are building a statically
61# linked Python binary (the only solution of your platform doesn't
62# support shared libraries, and sometimes handy if you want to
63# distribute or install the resulting Python binary), run "make
64# python".
65
66# Note: Each time you edit Makefile.pre.in or Setup, you must run
67# "make Makefile" before running "make".
68
69# Hint: if you want to use VPATH, you can start in an empty
70# subdirectory and say (e.g.):
71# make -f ../Makefile.pre.in boot srcdir=.. VPATH=..
72
73
74# === Bootstrap variables (edited through "make boot") ===
75
76# The prefix used by "make inclinstall libainstall" of core python
77installdir= /usr/local
78
79# The exec_prefix used by the same
80exec_installdir=$(installdir)
81
82# Source directory and VPATH in case you want to use VPATH.
83# (You will have to edit these two lines yourself -- there is no
84# automatic support as the Makefile is not generated by
85# config.status.)
86srcdir= .
87VPATH= .
88
89# === Variables that you may want to customize (rarely) ===
90
Guido van Rossum434882e1996-10-08 17:21:11 +000091# (Static) build target
92TARGET= python
93
Guido van Rossumbec74841996-11-27 19:38:53 +000094# Installed python binary (used only by boot target)
95PYTHON= python
96
Guido van Rossum1631cbe1996-09-10 18:19:23 +000097# Add more -I and -D options here
Guido van Rossum474ba3b1997-10-05 03:01:28 +000098CFLAGS= $(OPT) -I$(INCLUDEPY) -I$(EXECINCLUDEPY) $(DEFS)
Guido van Rossum1631cbe1996-09-10 18:19:23 +000099
100# These two variables can be set in Setup to merge extensions.
101# See example[23].
102BASELIB=
103BASESETUP=
104
105# === Variables set by makesetup ===
106
107MODOBJS= _MODOBJS_
108MODLIBS= _MODLIBS_
109
110# === Definitions added by makesetup ===
111
112# === Variables from configure (through sedscript) ===
113
114VERSION= @VERSION@
115CC= @CC@
116OPT= @OPT@
117LDFLAGS= @LDFLAGS@
118DEFS= @DEFS@
119LIBS= @LIBS@
120LIBM= @LIBM@
121LIBC= @LIBC@
122RANLIB= @RANLIB@
123MACHDEP= @MACHDEP@
124SO= @SO@
125LDSHARED= @LDSHARED@
126CCSHARED= @CCSHARED@
127LINKFORSHARED= @LINKFORSHARED@
128
129# Install prefix for architecture-independent files
130prefix= /usr/local
131
132# Install prefix for architecture-dependent files
133exec_prefix= $(prefix)
134
135# === Fixed definitions ===
136
Guido van Rossumb0259bc1996-10-24 21:47:45 +0000137# Shell used by make (some versions default to the login shell, which is bad)
138SHELL= /bin/sh
139
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000140# Expanded directories
141BINDIR= $(exec_installdir)/bin
142LIBDIR= $(exec_prefix)/lib
143MANDIR= $(installdir)/man
144INCLUDEDIR= $(installdir)/include
145SCRIPTDIR= $(prefix)/lib
146
147# Detailed destination directories
148BINLIBDEST= $(LIBDIR)/python$(VERSION)
149LIBDEST= $(SCRIPTDIR)/python$(VERSION)
150INCLUDEPY= $(INCLUDEDIR)/python$(VERSION)
Guido van Rossum474ba3b1997-10-05 03:01:28 +0000151EXECINCLUDEPY= $(exec_installdir)/include/python$(VERSION)
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000152LIBP= $(exec_installdir)/lib/python$(VERSION)
Fred Drakebfeb74d1997-10-04 04:56:40 +0000153DESTSHARED= $(BINLIBDEST)/site-packages
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000154
155LIBPL= $(LIBP)/config
156
Guido van Rossumbef03ae1997-07-19 22:52:43 +0000157PYTHONLIBS= $(LIBPL)/libpython$(VERSION).a
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000158
159MAKESETUP= $(LIBPL)/makesetup
160MAKEFILE= $(LIBPL)/Makefile
161CONFIGC= $(LIBPL)/config.c
162CONFIGCIN= $(LIBPL)/config.c.in
163SETUP= $(LIBPL)/Setup
164
165SYSLIBS= $(LIBM) $(LIBC)
166
Guido van Rossumbef03ae1997-07-19 22:52:43 +0000167ADDOBJS= $(LIBPL)/python.o config.o
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000168
Fred Drakebfeb74d1997-10-04 04:56:40 +0000169# Portable install script (configure doesn't always guess right)
170INSTALL= $(LIBPL)/install-sh -c
171# Shared libraries must be installed with executable mode on some systems;
172# rather than figuring out exactly which, we always give them executable mode.
173# Also, making them read-only seems to be a good idea...
174INSTALL_SHARED= ${INSTALL} -m 555
175
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000176# === Fixed rules ===
177
178# Default target. This builds shared libraries only
179default: sharedmods
180
181# Build everything
Guido van Rossum434882e1996-10-08 17:21:11 +0000182all: static sharedmods
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000183
184# Build shared libraries from our extension modules
185sharedmods: $(SHAREDMODS)
186
187# Build a static Python binary containing our extension modules
Guido van Rossum434882e1996-10-08 17:21:11 +0000188static: $(TARGET)
Guido van Rossumbef03ae1997-07-19 22:52:43 +0000189$(TARGET): $(ADDOBJS) lib.a $(PYTHONLIBS) Makefile $(BASELIB)
190 $(CC) $(LDFLAGS) $(ADDOBJS) lib.a $(PYTHONLIBS) \
Guido van Rossum434882e1996-10-08 17:21:11 +0000191 $(LINKPATH) $(BASELIB) $(MODLIBS) $(LIBS) $(SYSLIBS) \
192 -o $(TARGET)
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000193
Fred Drakebfeb74d1997-10-04 04:56:40 +0000194install: sharedmods
195 if test ! -d $(DESTSHARED) ; then \
196 mkdir $(DESTSHARED) ; else true ; fi
197 -for i in X $(SHAREDMODS); do \
198 if test $$i != X; \
199 then $(INSTALL_SHARED) $$i $(DESTSHARED)/$$i; \
200 fi; \
201 done
202
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000203# Build the library containing our extension modules
204lib.a: $(MODOBJS)
205 -rm -f lib.a
206 ar cr lib.a $(MODOBJS)
Guido van Rossumbef03ae1997-07-19 22:52:43 +0000207 -$(RANLIB) lib.a
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000208
209# This runs makesetup *twice* to use the BASESETUP definition from Setup
210config.c Makefile: Makefile.pre Setup $(BASESETUP) $(MAKESETUP)
211 $(MAKESETUP) \
212 -m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP)
213 $(MAKE) -f Makefile do-it-again
214
215# Internal target to run makesetup for the second time
216do-it-again:
217 $(MAKESETUP) \
218 -m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP)
219
220# Make config.o from the config.c created by makesetup
221config.o: config.c
222 $(CC) $(CFLAGS) -c config.c
223
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000224# Setup is copied from Setup.in *only* if it doesn't yet exist
225Setup:
226 cp $(srcdir)/Setup.in Setup
227
228# Make the intermediate Makefile.pre from Makefile.pre.in
229Makefile.pre: Makefile.pre.in sedscript
230 sed -f sedscript $(srcdir)/Makefile.pre.in >Makefile.pre
231
232# Shortcuts to make the sed arguments on one line
233P=prefix
234E=exec_prefix
235H=Generated automatically from Makefile.pre.in by sedscript.
236L=LINKFORSHARED
237
238# Make the sed script used to create Makefile.pre from Makefile.pre.in
239sedscript: $(MAKEFILE)
240 sed -n \
241 -e '1s/.*/1i\\/p' \
242 -e '2s%.*%# $H%p' \
243 -e '/^VERSION=/s/^VERSION=[ ]*\(.*\)/s%@VERSION[@]%\1%/p' \
244 -e '/^CC=/s/^CC=[ ]*\(.*\)/s%@CC[@]%\1%/p' \
245 -e '/^OPT=/s/^OPT=[ ]*\(.*\)/s%@OPT[@]%\1%/p' \
246 -e '/^LDFLAGS=/s/^LDFLAGS=[ ]*\(.*\)/s%@LDFLAGS[@]%\1%/p' \
247 -e '/^DEFS=/s/^DEFS=[ ]*\(.*\)/s%@DEFS[@]%\1%/p' \
248 -e '/^LIBS=/s/^LIBS=[ ]*\(.*\)/s%@LIBS[@]%\1%/p' \
249 -e '/^LIBM=/s/^LIBM=[ ]*\(.*\)/s%@LIBM[@]%\1%/p' \
250 -e '/^LIBC=/s/^LIBC=[ ]*\(.*\)/s%@LIBC[@]%\1%/p' \
251 -e '/^RANLIB=/s/^RANLIB=[ ]*\(.*\)/s%@RANLIB[@]%\1%/p' \
252 -e '/^MACHDEP=/s/^MACHDEP=[ ]*\(.*\)/s%@MACHDEP[@]%\1%/p' \
253 -e '/^SO=/s/^SO=[ ]*\(.*\)/s%@SO[@]%\1%/p' \
254 -e '/^LDSHARED=/s/^LDSHARED=[ ]*\(.*\)/s%@LDSHARED[@]%\1%/p' \
255 -e '/^CCSHARED=/s/^CCSHARED=[ ]*\(.*\)/s%@CCSHARED[@]%\1%/p' \
256 -e '/^$L=/s/^$L=[ ]*\(.*\)/s%@$L[@]%\1%/p' \
257 -e '/^$P=/s/^$P=\(.*\)/s%^$P=.*%$P=\1%/p' \
258 -e '/^$E=/s/^$E=\(.*\)/s%^$E=.*%$E=\1%/p' \
259 $(MAKEFILE) >sedscript
260 echo "/^installdir=/s%=.*%= $(installdir)%" >>sedscript
261 echo "/^exec_installdir=/s%=.*%=$(exec_installdir)%" >>sedscript
262 echo "/^srcdir=/s%=.*%= $(srcdir)%" >>sedscript
263 echo "/^VPATH=/s%=.*%= $(VPATH)%" >>sedscript
264 echo "/^LINKPATH=/s%=.*%= $(LINKPATH)%" >>sedscript
265 echo "/^BASELIB=/s%=.*%= $(BASELIB)%" >>sedscript
266 echo "/^BASESETUP=/s%=.*%= $(BASESETUP)%" >>sedscript
267
268# Bootstrap target
Guido van Rossum43e66611996-10-10 19:12:47 +0000269boot: clobber
Guido van Rossumbec74841996-11-27 19:38:53 +0000270 VERSION=`$(PYTHON) -c "import sys; print sys.version[:3]"`; \
271 installdir=`$(PYTHON) -c "import sys; print sys.prefix"`; \
272 exec_installdir=`$(PYTHON) -c "import sys; print sys.exec_prefix"`; \
Guido van Rossum946cf891996-09-11 12:15:07 +0000273 $(MAKE) -f $(srcdir)/Makefile.pre.in VPATH=$(VPATH) srcdir=$(srcdir) \
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000274 VERSION=$$VERSION \
275 installdir=$$installdir \
Guido van Rossum946cf891996-09-11 12:15:07 +0000276 exec_installdir=$$exec_installdir \
277 Makefile
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000278
279# Handy target to remove intermediate files and backups
280clean:
281 -rm -f *.o *~
282
283# Handy target to remove everything that is easily regenerated
284clobber: clean
Guido van Rossumbec74841996-11-27 19:38:53 +0000285 -rm -f *.a tags TAGS config.c Makefile.pre $(TARGET) sedscript
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000286 -rm -f *.so *.sl so_locations
287
288
289# Handy target to remove everything you don't want to distribute
290distclean: clobber
291 -rm -f Makefile Setup