blob: dcc57f2ad29a2086632eb47fa04569d05ad19f64 [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
129# Expanded directories
130BINDIR= $(exec_installdir)/bin
131LIBDIR= $(exec_prefix)/lib
132MANDIR= $(installdir)/man
133INCLUDEDIR= $(installdir)/include
134SCRIPTDIR= $(prefix)/lib
135
136# Detailed destination directories
137BINLIBDEST= $(LIBDIR)/python$(VERSION)
138LIBDEST= $(SCRIPTDIR)/python$(VERSION)
139INCLUDEPY= $(INCLUDEDIR)/python$(VERSION)
140LIBP= $(exec_installdir)/lib/python$(VERSION)
141
142LIBPL= $(LIBP)/config
143
144PYTHONLIBS= $(LIBPL)/libModules.a \
145 $(LIBPL)/libPython.a \
146 $(LIBPL)/libObjects.a \
147 $(LIBPL)/libParser.a
148
149MAKESETUP= $(LIBPL)/makesetup
150MAKEFILE= $(LIBPL)/Makefile
151CONFIGC= $(LIBPL)/config.c
152CONFIGCIN= $(LIBPL)/config.c.in
153SETUP= $(LIBPL)/Setup
154
155SYSLIBS= $(LIBM) $(LIBC)
156
157ADDOBJS= $(LIBPL)/main.o getpath.o config.o
158
159# === Fixed rules ===
160
161# Default target. This builds shared libraries only
162default: sharedmods
163
164# Build everything
Guido van Rossum434882e1996-10-08 17:21:11 +0000165all: static sharedmods
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000166
167# Build shared libraries from our extension modules
168sharedmods: $(SHAREDMODS)
169
170# Build a static Python binary containing our extension modules
Guido van Rossum434882e1996-10-08 17:21:11 +0000171static: $(TARGET)
172$(TARGET): $(ADDOBJS) lib.a $(PYTHONLIBS) Makefile $(BASELIB)
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000173 $(CC) $(LDFLAGS) $(ADDOBJS) lib.a $(PYTHONLIBS) \
Guido van Rossum434882e1996-10-08 17:21:11 +0000174 $(LINKPATH) $(BASELIB) $(MODLIBS) $(LIBS) $(SYSLIBS) \
175 -o $(TARGET)
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000176
177# Build the library containing our extension modules
178lib.a: $(MODOBJS)
179 -rm -f lib.a
180 ar cr lib.a $(MODOBJS)
181 -$(RANLIB) lib.a || \
182 echo "don't worry if ranlib fails -- probably SYSV or equiv"
183
184# This runs makesetup *twice* to use the BASESETUP definition from Setup
185config.c Makefile: Makefile.pre Setup $(BASESETUP) $(MAKESETUP)
186 $(MAKESETUP) \
187 -m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP)
188 $(MAKE) -f Makefile do-it-again
189
190# Internal target to run makesetup for the second time
191do-it-again:
192 $(MAKESETUP) \
193 -m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP)
194
195# Make config.o from the config.c created by makesetup
196config.o: config.c
197 $(CC) $(CFLAGS) -c config.c
198
199# Make our own private getpath.o from the installed source and our PYTHONPATH
200getpath.o: $(LIBPL)/getpath.c Makefile
201 $(CC) $(CFLAGS) -DPYTHONPATH=\"$(PYTHONPATH)\" -c $(LIBPL)/getpath.c
202
203# Setup is copied from Setup.in *only* if it doesn't yet exist
204Setup:
205 cp $(srcdir)/Setup.in Setup
206
207# Make the intermediate Makefile.pre from Makefile.pre.in
208Makefile.pre: Makefile.pre.in sedscript
209 sed -f sedscript $(srcdir)/Makefile.pre.in >Makefile.pre
210
211# Shortcuts to make the sed arguments on one line
212P=prefix
213E=exec_prefix
214H=Generated automatically from Makefile.pre.in by sedscript.
215L=LINKFORSHARED
216
217# Make the sed script used to create Makefile.pre from Makefile.pre.in
218sedscript: $(MAKEFILE)
219 sed -n \
220 -e '1s/.*/1i\\/p' \
221 -e '2s%.*%# $H%p' \
222 -e '/^VERSION=/s/^VERSION=[ ]*\(.*\)/s%@VERSION[@]%\1%/p' \
223 -e '/^CC=/s/^CC=[ ]*\(.*\)/s%@CC[@]%\1%/p' \
224 -e '/^OPT=/s/^OPT=[ ]*\(.*\)/s%@OPT[@]%\1%/p' \
225 -e '/^LDFLAGS=/s/^LDFLAGS=[ ]*\(.*\)/s%@LDFLAGS[@]%\1%/p' \
226 -e '/^DEFS=/s/^DEFS=[ ]*\(.*\)/s%@DEFS[@]%\1%/p' \
227 -e '/^LIBS=/s/^LIBS=[ ]*\(.*\)/s%@LIBS[@]%\1%/p' \
228 -e '/^LIBM=/s/^LIBM=[ ]*\(.*\)/s%@LIBM[@]%\1%/p' \
229 -e '/^LIBC=/s/^LIBC=[ ]*\(.*\)/s%@LIBC[@]%\1%/p' \
230 -e '/^RANLIB=/s/^RANLIB=[ ]*\(.*\)/s%@RANLIB[@]%\1%/p' \
231 -e '/^MACHDEP=/s/^MACHDEP=[ ]*\(.*\)/s%@MACHDEP[@]%\1%/p' \
232 -e '/^SO=/s/^SO=[ ]*\(.*\)/s%@SO[@]%\1%/p' \
233 -e '/^LDSHARED=/s/^LDSHARED=[ ]*\(.*\)/s%@LDSHARED[@]%\1%/p' \
234 -e '/^CCSHARED=/s/^CCSHARED=[ ]*\(.*\)/s%@CCSHARED[@]%\1%/p' \
235 -e '/^$L=/s/^$L=[ ]*\(.*\)/s%@$L[@]%\1%/p' \
236 -e '/^$P=/s/^$P=\(.*\)/s%^$P=.*%$P=\1%/p' \
237 -e '/^$E=/s/^$E=\(.*\)/s%^$E=.*%$E=\1%/p' \
238 $(MAKEFILE) >sedscript
239 echo "/^installdir=/s%=.*%= $(installdir)%" >>sedscript
240 echo "/^exec_installdir=/s%=.*%=$(exec_installdir)%" >>sedscript
241 echo "/^srcdir=/s%=.*%= $(srcdir)%" >>sedscript
242 echo "/^VPATH=/s%=.*%= $(VPATH)%" >>sedscript
243 echo "/^LINKPATH=/s%=.*%= $(LINKPATH)%" >>sedscript
244 echo "/^BASELIB=/s%=.*%= $(BASELIB)%" >>sedscript
245 echo "/^BASESETUP=/s%=.*%= $(BASESETUP)%" >>sedscript
246
247# Bootstrap target
248boot:
249 VERSION=`python -c "import sys; print sys.version[:3]"`; \
250 installdir=`python -c "import sys; print sys.prefix"`; \
251 exec_installdir=`python -c "import sys; print sys.exec_prefix"`; \
Guido van Rossum946cf891996-09-11 12:15:07 +0000252 $(MAKE) -f $(srcdir)/Makefile.pre.in VPATH=$(VPATH) srcdir=$(srcdir) \
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000253 VERSION=$$VERSION \
254 installdir=$$installdir \
Guido van Rossum946cf891996-09-11 12:15:07 +0000255 exec_installdir=$$exec_installdir \
256 Makefile
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000257
258# Handy target to remove intermediate files and backups
259clean:
260 -rm -f *.o *~
261
262# Handy target to remove everything that is easily regenerated
263clobber: clean
264 -rm -f *.a tags TAGS config.c Makefile.pre python sedscript
265 -rm -f *.so *.sl so_locations
266
267
268# Handy target to remove everything you don't want to distribute
269distclean: clobber
270 -rm -f Makefile Setup