blob: 01b49013661673d22217e90f5266783270c4f850 [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
Fred Drakecf3bc8c2000-10-26 17:07:40 +000020# format of the Modules/Setup.dist file; see the instructions there.
Guido van Rossum1631cbe1996-09-10 18:19:23 +000021# 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
Neil Schemenauer89e90d62001-06-02 06:16:02 +000098CFLAGS= $(OPT)
99CPPFLAGS= -I$(INCLUDEPY) -I$(EXECINCLUDEPY) $(DEFS)
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000100
101# These two variables can be set in Setup to merge extensions.
102# See example[23].
103BASELIB=
104BASESETUP=
105
106# === Variables set by makesetup ===
107
108MODOBJS= _MODOBJS_
109MODLIBS= _MODLIBS_
110
111# === Definitions added by makesetup ===
112
113# === Variables from configure (through sedscript) ===
114
115VERSION= @VERSION@
116CC= @CC@
Guido van Rossum91922671997-10-09 20:24:13 +0000117LINKCC= @LINKCC@
118SGI_ABI= @SGI_ABI@
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000119OPT= @OPT@
120LDFLAGS= @LDFLAGS@
Guido van Rossum38d3fe01998-03-11 17:49:55 +0000121LDLAST= @LDLAST@
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000122DEFS= @DEFS@
123LIBS= @LIBS@
124LIBM= @LIBM@
125LIBC= @LIBC@
126RANLIB= @RANLIB@
127MACHDEP= @MACHDEP@
128SO= @SO@
129LDSHARED= @LDSHARED@
130CCSHARED= @CCSHARED@
131LINKFORSHARED= @LINKFORSHARED@
Guido van Rossumc201bf42001-01-23 01:53:41 +0000132CXX= @CXX@
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000133
134# Install prefix for architecture-independent files
135prefix= /usr/local
136
137# Install prefix for architecture-dependent files
138exec_prefix= $(prefix)
139
Guido van Rossumcc8e1a41998-04-30 13:34:12 +0000140# Uncomment the following two lines for AIX
141#LINKCC= $(LIBPL)/makexp_aix $(LIBPL)/python.exp "" $(LIBRARY); $(PURIFY) $(CC)
142#LDSHARED= $(LIBPL)/ld_so_aix $(CC) -bI:$(LIBPL)/python.exp
143
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000144# === Fixed definitions ===
145
Guido van Rossumb0259bc1996-10-24 21:47:45 +0000146# Shell used by make (some versions default to the login shell, which is bad)
147SHELL= /bin/sh
148
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000149# Expanded directories
150BINDIR= $(exec_installdir)/bin
151LIBDIR= $(exec_prefix)/lib
152MANDIR= $(installdir)/man
153INCLUDEDIR= $(installdir)/include
154SCRIPTDIR= $(prefix)/lib
155
156# Detailed destination directories
157BINLIBDEST= $(LIBDIR)/python$(VERSION)
158LIBDEST= $(SCRIPTDIR)/python$(VERSION)
159INCLUDEPY= $(INCLUDEDIR)/python$(VERSION)
Guido van Rossum474ba3b1997-10-05 03:01:28 +0000160EXECINCLUDEPY= $(exec_installdir)/include/python$(VERSION)
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000161LIBP= $(exec_installdir)/lib/python$(VERSION)
Fred Drakebfeb74d1997-10-04 04:56:40 +0000162DESTSHARED= $(BINLIBDEST)/site-packages
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000163
164LIBPL= $(LIBP)/config
165
Guido van Rossumbef03ae1997-07-19 22:52:43 +0000166PYTHONLIBS= $(LIBPL)/libpython$(VERSION).a
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000167
168MAKESETUP= $(LIBPL)/makesetup
169MAKEFILE= $(LIBPL)/Makefile
170CONFIGC= $(LIBPL)/config.c
171CONFIGCIN= $(LIBPL)/config.c.in
Barry Warsaw6de72132000-06-30 16:04:18 +0000172SETUP= $(LIBPL)/Setup.config $(LIBPL)/Setup.local $(LIBPL)/Setup
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000173
174SYSLIBS= $(LIBM) $(LIBC)
175
Guido van Rossumbef03ae1997-07-19 22:52:43 +0000176ADDOBJS= $(LIBPL)/python.o config.o
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000177
Fred Drakebfeb74d1997-10-04 04:56:40 +0000178# Portable install script (configure doesn't always guess right)
179INSTALL= $(LIBPL)/install-sh -c
180# Shared libraries must be installed with executable mode on some systems;
181# rather than figuring out exactly which, we always give them executable mode.
182# Also, making them read-only seems to be a good idea...
183INSTALL_SHARED= ${INSTALL} -m 555
184
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000185# === Fixed rules ===
186
187# Default target. This builds shared libraries only
188default: sharedmods
189
190# Build everything
Guido van Rossum434882e1996-10-08 17:21:11 +0000191all: static sharedmods
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000192
193# Build shared libraries from our extension modules
194sharedmods: $(SHAREDMODS)
195
196# Build a static Python binary containing our extension modules
Guido van Rossum434882e1996-10-08 17:21:11 +0000197static: $(TARGET)
Guido van Rossumbef03ae1997-07-19 22:52:43 +0000198$(TARGET): $(ADDOBJS) lib.a $(PYTHONLIBS) Makefile $(BASELIB)
Guido van Rossum38d3fe01998-03-11 17:49:55 +0000199 $(LINKCC) $(LDFLAGS) $(LINKFORSHARED) \
200 $(ADDOBJS) lib.a $(PYTHONLIBS) \
Guido van Rossum434882e1996-10-08 17:21:11 +0000201 $(LINKPATH) $(BASELIB) $(MODLIBS) $(LIBS) $(SYSLIBS) \
Guido van Rossum38d3fe01998-03-11 17:49:55 +0000202 -o $(TARGET) $(LDLAST)
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000203
Fred Drakebfeb74d1997-10-04 04:56:40 +0000204install: sharedmods
205 if test ! -d $(DESTSHARED) ; then \
206 mkdir $(DESTSHARED) ; else true ; fi
207 -for i in X $(SHAREDMODS); do \
208 if test $$i != X; \
209 then $(INSTALL_SHARED) $$i $(DESTSHARED)/$$i; \
210 fi; \
211 done
212
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000213# Build the library containing our extension modules
214lib.a: $(MODOBJS)
215 -rm -f lib.a
216 ar cr lib.a $(MODOBJS)
Guido van Rossumbef03ae1997-07-19 22:52:43 +0000217 -$(RANLIB) lib.a
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000218
219# This runs makesetup *twice* to use the BASESETUP definition from Setup
220config.c Makefile: Makefile.pre Setup $(BASESETUP) $(MAKESETUP)
221 $(MAKESETUP) \
222 -m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP)
223 $(MAKE) -f Makefile do-it-again
224
225# Internal target to run makesetup for the second time
226do-it-again:
227 $(MAKESETUP) \
228 -m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP)
229
230# Make config.o from the config.c created by makesetup
231config.o: config.c
Neil Schemenauer89e90d62001-06-02 06:16:02 +0000232 $(CC) $(CFLAGS) $(CPPFLAGS) -c config.c
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000233
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000234# Setup is copied from Setup.in *only* if it doesn't yet exist
235Setup:
236 cp $(srcdir)/Setup.in Setup
237
238# Make the intermediate Makefile.pre from Makefile.pre.in
239Makefile.pre: Makefile.pre.in sedscript
240 sed -f sedscript $(srcdir)/Makefile.pre.in >Makefile.pre
241
242# Shortcuts to make the sed arguments on one line
243P=prefix
244E=exec_prefix
245H=Generated automatically from Makefile.pre.in by sedscript.
246L=LINKFORSHARED
247
248# Make the sed script used to create Makefile.pre from Makefile.pre.in
249sedscript: $(MAKEFILE)
250 sed -n \
251 -e '1s/.*/1i\\/p' \
252 -e '2s%.*%# $H%p' \
253 -e '/^VERSION=/s/^VERSION=[ ]*\(.*\)/s%@VERSION[@]%\1%/p' \
254 -e '/^CC=/s/^CC=[ ]*\(.*\)/s%@CC[@]%\1%/p' \
Guido van Rossumc201bf42001-01-23 01:53:41 +0000255 -e '/^CXX=/s/^CXX=[ ]*\(.*\)/s%@CXX[@]%\1%/p' \
Guido van Rossum91922671997-10-09 20:24:13 +0000256 -e '/^LINKCC=/s/^LINKCC=[ ]*\(.*\)/s%@LINKCC[@]%\1%/p' \
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000257 -e '/^OPT=/s/^OPT=[ ]*\(.*\)/s%@OPT[@]%\1%/p' \
258 -e '/^LDFLAGS=/s/^LDFLAGS=[ ]*\(.*\)/s%@LDFLAGS[@]%\1%/p' \
Guido van Rossum750c8ce1998-05-20 15:53:22 +0000259 -e '/^LDLAST=/s/^LDLAST=[ ]*\(.*\)/s%@LDLAST[@]%\1%/p' \
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000260 -e '/^DEFS=/s/^DEFS=[ ]*\(.*\)/s%@DEFS[@]%\1%/p' \
261 -e '/^LIBS=/s/^LIBS=[ ]*\(.*\)/s%@LIBS[@]%\1%/p' \
262 -e '/^LIBM=/s/^LIBM=[ ]*\(.*\)/s%@LIBM[@]%\1%/p' \
263 -e '/^LIBC=/s/^LIBC=[ ]*\(.*\)/s%@LIBC[@]%\1%/p' \
264 -e '/^RANLIB=/s/^RANLIB=[ ]*\(.*\)/s%@RANLIB[@]%\1%/p' \
265 -e '/^MACHDEP=/s/^MACHDEP=[ ]*\(.*\)/s%@MACHDEP[@]%\1%/p' \
266 -e '/^SO=/s/^SO=[ ]*\(.*\)/s%@SO[@]%\1%/p' \
267 -e '/^LDSHARED=/s/^LDSHARED=[ ]*\(.*\)/s%@LDSHARED[@]%\1%/p' \
268 -e '/^CCSHARED=/s/^CCSHARED=[ ]*\(.*\)/s%@CCSHARED[@]%\1%/p' \
Guido van Rossum795a4bc1998-06-08 21:22:12 +0000269 -e '/^SGI_ABI=/s/^SGI_ABI=[ ]*\(.*\)/s%@SGI_ABI[@]%\1%/p' \
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000270 -e '/^$L=/s/^$L=[ ]*\(.*\)/s%@$L[@]%\1%/p' \
271 -e '/^$P=/s/^$P=\(.*\)/s%^$P=.*%$P=\1%/p' \
272 -e '/^$E=/s/^$E=\(.*\)/s%^$E=.*%$E=\1%/p' \
273 $(MAKEFILE) >sedscript
274 echo "/^installdir=/s%=.*%= $(installdir)%" >>sedscript
275 echo "/^exec_installdir=/s%=.*%=$(exec_installdir)%" >>sedscript
276 echo "/^srcdir=/s%=.*%= $(srcdir)%" >>sedscript
277 echo "/^VPATH=/s%=.*%= $(VPATH)%" >>sedscript
278 echo "/^LINKPATH=/s%=.*%= $(LINKPATH)%" >>sedscript
279 echo "/^BASELIB=/s%=.*%= $(BASELIB)%" >>sedscript
280 echo "/^BASESETUP=/s%=.*%= $(BASESETUP)%" >>sedscript
281
282# Bootstrap target
Guido van Rossum43e66611996-10-10 19:12:47 +0000283boot: clobber
Guido van Rossumbec74841996-11-27 19:38:53 +0000284 VERSION=`$(PYTHON) -c "import sys; print sys.version[:3]"`; \
285 installdir=`$(PYTHON) -c "import sys; print sys.prefix"`; \
286 exec_installdir=`$(PYTHON) -c "import sys; print sys.exec_prefix"`; \
Guido van Rossum946cf891996-09-11 12:15:07 +0000287 $(MAKE) -f $(srcdir)/Makefile.pre.in VPATH=$(VPATH) srcdir=$(srcdir) \
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000288 VERSION=$$VERSION \
289 installdir=$$installdir \
Guido van Rossum946cf891996-09-11 12:15:07 +0000290 exec_installdir=$$exec_installdir \
291 Makefile
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000292
293# Handy target to remove intermediate files and backups
294clean:
295 -rm -f *.o *~
296
297# Handy target to remove everything that is easily regenerated
298clobber: clean
Guido van Rossumbec74841996-11-27 19:38:53 +0000299 -rm -f *.a tags TAGS config.c Makefile.pre $(TARGET) sedscript
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000300 -rm -f *.so *.sl so_locations
301
302
303# Handy target to remove everything you don't want to distribute
304distclean: clobber
305 -rm -f Makefile Setup