blob: 32e59d411df4c98022df7fc6a04d0c18130ae701 [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
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
72installdir= /usr/local
73
74# The exec_prefix used by the same
75exec_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.)
81srcdir= .
82VPATH= .
83
84# === Variables that you may want to customize (rarely) ===
85
Guido van Rossum434882e1996-10-08 17:21:11 +000086# (Static) build target
87TARGET= python
88
Guido van Rossum1631cbe1996-09-10 18:19:23 +000089# Add more -I and -D options here
90CFLAGS= $(OPT) -I$(INCLUDEPY) -I$(LIBPL) $(DEFS)
91
92# These two variables can be set in Setup to merge extensions.
93# See example[23].
94BASELIB=
95BASESETUP=
96
97# === Variables set by makesetup ===
98
99MODOBJS= _MODOBJS_
100MODLIBS= _MODLIBS_
101
102# === Definitions added by makesetup ===
103
104# === Variables from configure (through sedscript) ===
105
106VERSION= @VERSION@
107CC= @CC@
108OPT= @OPT@
109LDFLAGS= @LDFLAGS@
110DEFS= @DEFS@
111LIBS= @LIBS@
112LIBM= @LIBM@
113LIBC= @LIBC@
114RANLIB= @RANLIB@
115MACHDEP= @MACHDEP@
116SO= @SO@
117LDSHARED= @LDSHARED@
118CCSHARED= @CCSHARED@
119LINKFORSHARED= @LINKFORSHARED@
120
121# Install prefix for architecture-independent files
122prefix= /usr/local
123
124# Install prefix for architecture-dependent files
125exec_prefix= $(prefix)
126
127# === Fixed definitions ===
128
Guido van Rossumb0259bc1996-10-24 21:47:45 +0000129# Shell used by make (some versions default to the login shell, which is bad)
130SHELL= /bin/sh
131
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000132# Expanded directories
133BINDIR= $(exec_installdir)/bin
134LIBDIR= $(exec_prefix)/lib
135MANDIR= $(installdir)/man
136INCLUDEDIR= $(installdir)/include
137SCRIPTDIR= $(prefix)/lib
138
139# Detailed destination directories
140BINLIBDEST= $(LIBDIR)/python$(VERSION)
141LIBDEST= $(SCRIPTDIR)/python$(VERSION)
142INCLUDEPY= $(INCLUDEDIR)/python$(VERSION)
143LIBP= $(exec_installdir)/lib/python$(VERSION)
144
145LIBPL= $(LIBP)/config
146
147PYTHONLIBS= $(LIBPL)/libModules.a \
148 $(LIBPL)/libPython.a \
149 $(LIBPL)/libObjects.a \
150 $(LIBPL)/libParser.a
151
152MAKESETUP= $(LIBPL)/makesetup
153MAKEFILE= $(LIBPL)/Makefile
154CONFIGC= $(LIBPL)/config.c
155CONFIGCIN= $(LIBPL)/config.c.in
156SETUP= $(LIBPL)/Setup
157
158SYSLIBS= $(LIBM) $(LIBC)
159
160ADDOBJS= $(LIBPL)/main.o getpath.o config.o
161
162# === Fixed rules ===
163
164# Default target. This builds shared libraries only
165default: sharedmods
166
167# Build everything
Guido van Rossum434882e1996-10-08 17:21:11 +0000168all: static sharedmods
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000169
170# Build shared libraries from our extension modules
171sharedmods: $(SHAREDMODS)
172
173# Build a static Python binary containing our extension modules
Guido van Rossum434882e1996-10-08 17:21:11 +0000174static: $(TARGET)
175$(TARGET): $(ADDOBJS) lib.a $(PYTHONLIBS) Makefile $(BASELIB)
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000176 $(CC) $(LDFLAGS) $(ADDOBJS) lib.a $(PYTHONLIBS) \
Guido van Rossum434882e1996-10-08 17:21:11 +0000177 $(LINKPATH) $(BASELIB) $(MODLIBS) $(LIBS) $(SYSLIBS) \
178 -o $(TARGET)
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000179
180# Build the library containing our extension modules
181lib.a: $(MODOBJS)
182 -rm -f lib.a
183 ar cr lib.a $(MODOBJS)
184 -$(RANLIB) lib.a || \
185 echo "don't worry if ranlib fails -- probably SYSV or equiv"
186
187# This runs makesetup *twice* to use the BASESETUP definition from Setup
188config.c Makefile: Makefile.pre Setup $(BASESETUP) $(MAKESETUP)
189 $(MAKESETUP) \
190 -m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP)
191 $(MAKE) -f Makefile do-it-again
192
193# Internal target to run makesetup for the second time
194do-it-again:
195 $(MAKESETUP) \
196 -m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP)
197
198# Make config.o from the config.c created by makesetup
199config.o: config.c
200 $(CC) $(CFLAGS) -c config.c
201
202# Make our own private getpath.o from the installed source and our PYTHONPATH
203getpath.o: $(LIBPL)/getpath.c Makefile
204 $(CC) $(CFLAGS) -DPYTHONPATH=\"$(PYTHONPATH)\" -c $(LIBPL)/getpath.c
205
206# Setup is copied from Setup.in *only* if it doesn't yet exist
207Setup:
208 cp $(srcdir)/Setup.in Setup
209
210# Make the intermediate Makefile.pre from Makefile.pre.in
211Makefile.pre: Makefile.pre.in sedscript
212 sed -f sedscript $(srcdir)/Makefile.pre.in >Makefile.pre
213
214# Shortcuts to make the sed arguments on one line
215P=prefix
216E=exec_prefix
217H=Generated automatically from Makefile.pre.in by sedscript.
218L=LINKFORSHARED
219
220# Make the sed script used to create Makefile.pre from Makefile.pre.in
221sedscript: $(MAKEFILE)
222 sed -n \
223 -e '1s/.*/1i\\/p' \
224 -e '2s%.*%# $H%p' \
225 -e '/^VERSION=/s/^VERSION=[ ]*\(.*\)/s%@VERSION[@]%\1%/p' \
226 -e '/^CC=/s/^CC=[ ]*\(.*\)/s%@CC[@]%\1%/p' \
227 -e '/^OPT=/s/^OPT=[ ]*\(.*\)/s%@OPT[@]%\1%/p' \
228 -e '/^LDFLAGS=/s/^LDFLAGS=[ ]*\(.*\)/s%@LDFLAGS[@]%\1%/p' \
229 -e '/^DEFS=/s/^DEFS=[ ]*\(.*\)/s%@DEFS[@]%\1%/p' \
230 -e '/^LIBS=/s/^LIBS=[ ]*\(.*\)/s%@LIBS[@]%\1%/p' \
231 -e '/^LIBM=/s/^LIBM=[ ]*\(.*\)/s%@LIBM[@]%\1%/p' \
232 -e '/^LIBC=/s/^LIBC=[ ]*\(.*\)/s%@LIBC[@]%\1%/p' \
233 -e '/^RANLIB=/s/^RANLIB=[ ]*\(.*\)/s%@RANLIB[@]%\1%/p' \
234 -e '/^MACHDEP=/s/^MACHDEP=[ ]*\(.*\)/s%@MACHDEP[@]%\1%/p' \
235 -e '/^SO=/s/^SO=[ ]*\(.*\)/s%@SO[@]%\1%/p' \
236 -e '/^LDSHARED=/s/^LDSHARED=[ ]*\(.*\)/s%@LDSHARED[@]%\1%/p' \
237 -e '/^CCSHARED=/s/^CCSHARED=[ ]*\(.*\)/s%@CCSHARED[@]%\1%/p' \
238 -e '/^$L=/s/^$L=[ ]*\(.*\)/s%@$L[@]%\1%/p' \
239 -e '/^$P=/s/^$P=\(.*\)/s%^$P=.*%$P=\1%/p' \
240 -e '/^$E=/s/^$E=\(.*\)/s%^$E=.*%$E=\1%/p' \
241 $(MAKEFILE) >sedscript
242 echo "/^installdir=/s%=.*%= $(installdir)%" >>sedscript
243 echo "/^exec_installdir=/s%=.*%=$(exec_installdir)%" >>sedscript
244 echo "/^srcdir=/s%=.*%= $(srcdir)%" >>sedscript
245 echo "/^VPATH=/s%=.*%= $(VPATH)%" >>sedscript
246 echo "/^LINKPATH=/s%=.*%= $(LINKPATH)%" >>sedscript
247 echo "/^BASELIB=/s%=.*%= $(BASELIB)%" >>sedscript
248 echo "/^BASESETUP=/s%=.*%= $(BASESETUP)%" >>sedscript
249
250# Bootstrap target
Guido van Rossum43e66611996-10-10 19:12:47 +0000251boot: clobber
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000252 VERSION=`python -c "import sys; print sys.version[:3]"`; \
253 installdir=`python -c "import sys; print sys.prefix"`; \
254 exec_installdir=`python -c "import sys; print sys.exec_prefix"`; \
Guido van Rossum946cf891996-09-11 12:15:07 +0000255 $(MAKE) -f $(srcdir)/Makefile.pre.in VPATH=$(VPATH) srcdir=$(srcdir) \
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000256 VERSION=$$VERSION \
257 installdir=$$installdir \
Guido van Rossum946cf891996-09-11 12:15:07 +0000258 exec_installdir=$$exec_installdir \
259 Makefile
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000260
261# Handy target to remove intermediate files and backups
262clean:
263 -rm -f *.o *~
264
265# Handy target to remove everything that is easily regenerated
266clobber: clean
267 -rm -f *.a tags TAGS config.c Makefile.pre python sedscript
268 -rm -f *.so *.sl so_locations
269
270
271# Handy target to remove everything you don't want to distribute
272distclean: clobber
273 -rm -f Makefile Setup