blob: 8954e6ac4d56ca2548a17594dc3592a46fade5c9 [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
Guido van Rossumbec74841996-11-27 19:38:53 +000053# Note: "make boot" implies "make clobber" -- it assumes that when you
54# bootstrap you may have changed platforms so it removes all previous
55# output files.
56
Guido van Rossum1631cbe1996-09-10 18:19:23 +000057# If you are building your extension as a shared library (your
58# Setup.in file starts with *shared*), run "make" or "make sharedmods"
59# to build the shared library files. If you are building a statically
60# linked Python binary (the only solution of your platform doesn't
61# support shared libraries, and sometimes handy if you want to
62# distribute or install the resulting Python binary), run "make
63# python".
64
65# Note: Each time you edit Makefile.pre.in or Setup, you must run
66# "make Makefile" before running "make".
67
68# Hint: if you want to use VPATH, you can start in an empty
69# subdirectory and say (e.g.):
70# make -f ../Makefile.pre.in boot srcdir=.. VPATH=..
71
72
73# === Bootstrap variables (edited through "make boot") ===
74
75# The prefix used by "make inclinstall libainstall" of core python
76installdir= /usr/local
77
78# The exec_prefix used by the same
79exec_installdir=$(installdir)
80
81# Source directory and VPATH in case you want to use VPATH.
82# (You will have to edit these two lines yourself -- there is no
83# automatic support as the Makefile is not generated by
84# config.status.)
85srcdir= .
86VPATH= .
87
88# === Variables that you may want to customize (rarely) ===
89
Guido van Rossum434882e1996-10-08 17:21:11 +000090# (Static) build target
91TARGET= python
92
Guido van Rossumbec74841996-11-27 19:38:53 +000093# Installed python binary (used only by boot target)
94PYTHON= python
95
Guido van Rossum1631cbe1996-09-10 18:19:23 +000096# Add more -I and -D options here
97CFLAGS= $(OPT) -I$(INCLUDEPY) -I$(LIBPL) $(DEFS)
98
99# These two variables can be set in Setup to merge extensions.
100# See example[23].
101BASELIB=
102BASESETUP=
103
104# === Variables set by makesetup ===
105
106MODOBJS= _MODOBJS_
107MODLIBS= _MODLIBS_
108
109# === Definitions added by makesetup ===
110
111# === Variables from configure (through sedscript) ===
112
113VERSION= @VERSION@
114CC= @CC@
115OPT= @OPT@
116LDFLAGS= @LDFLAGS@
117DEFS= @DEFS@
118LIBS= @LIBS@
119LIBM= @LIBM@
120LIBC= @LIBC@
121RANLIB= @RANLIB@
122MACHDEP= @MACHDEP@
123SO= @SO@
124LDSHARED= @LDSHARED@
125CCSHARED= @CCSHARED@
126LINKFORSHARED= @LINKFORSHARED@
127
128# Install prefix for architecture-independent files
129prefix= /usr/local
130
131# Install prefix for architecture-dependent files
132exec_prefix= $(prefix)
133
134# === Fixed definitions ===
135
Guido van Rossumb0259bc1996-10-24 21:47:45 +0000136# Shell used by make (some versions default to the login shell, which is bad)
137SHELL= /bin/sh
138
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000139# Expanded directories
140BINDIR= $(exec_installdir)/bin
141LIBDIR= $(exec_prefix)/lib
142MANDIR= $(installdir)/man
143INCLUDEDIR= $(installdir)/include
144SCRIPTDIR= $(prefix)/lib
145
146# Detailed destination directories
147BINLIBDEST= $(LIBDIR)/python$(VERSION)
148LIBDEST= $(SCRIPTDIR)/python$(VERSION)
149INCLUDEPY= $(INCLUDEDIR)/python$(VERSION)
150LIBP= $(exec_installdir)/lib/python$(VERSION)
151
152LIBPL= $(LIBP)/config
153
154PYTHONLIBS= $(LIBPL)/libModules.a \
155 $(LIBPL)/libPython.a \
156 $(LIBPL)/libObjects.a \
157 $(LIBPL)/libParser.a
158
159MAKESETUP= $(LIBPL)/makesetup
160MAKEFILE= $(LIBPL)/Makefile
161CONFIGC= $(LIBPL)/config.c
162CONFIGCIN= $(LIBPL)/config.c.in
163SETUP= $(LIBPL)/Setup
164
165SYSLIBS= $(LIBM) $(LIBC)
166
167ADDOBJS= $(LIBPL)/main.o getpath.o config.o
168
169# === Fixed rules ===
170
171# Default target. This builds shared libraries only
172default: sharedmods
173
174# Build everything
Guido van Rossum434882e1996-10-08 17:21:11 +0000175all: static sharedmods
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000176
177# Build shared libraries from our extension modules
178sharedmods: $(SHAREDMODS)
179
180# Build a static Python binary containing our extension modules
Guido van Rossum434882e1996-10-08 17:21:11 +0000181static: $(TARGET)
Guido van Rossum24c93591997-04-11 15:25:47 +0000182$(TARGET): $(ADDOBJS) lib.a $(PYTHONLIBS) Makefile $(BASELIB) buildno
183 expr `cat buildno` + 1 >@buildno
184 mv @buildno buildno
185 $(CC) -c $(CFLAGS) -DBUILD=`cat buildno` $(LIBPL)/getbuildinfo.c
186 $(CC) $(LDFLAGS) $(ADDOBJS) getbuildinfo.o lib.a $(PYTHONLIBS) \
Guido van Rossum434882e1996-10-08 17:21:11 +0000187 $(LINKPATH) $(BASELIB) $(MODLIBS) $(LIBS) $(SYSLIBS) \
188 -o $(TARGET)
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000189
Guido van Rossum24c93591997-04-11 15:25:47 +0000190buildno:
191 echo 0 >buildno
192
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000193# Build the library containing our extension modules
194lib.a: $(MODOBJS)
195 -rm -f lib.a
196 ar cr lib.a $(MODOBJS)
197 -$(RANLIB) lib.a || \
198 echo "don't worry if ranlib fails -- probably SYSV or equiv"
199
200# This runs makesetup *twice* to use the BASESETUP definition from Setup
201config.c Makefile: Makefile.pre Setup $(BASESETUP) $(MAKESETUP)
202 $(MAKESETUP) \
203 -m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP)
204 $(MAKE) -f Makefile do-it-again
205
206# Internal target to run makesetup for the second time
207do-it-again:
208 $(MAKESETUP) \
209 -m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP)
210
211# Make config.o from the config.c created by makesetup
212config.o: config.c
213 $(CC) $(CFLAGS) -c config.c
214
215# Make our own private getpath.o from the installed source and our PYTHONPATH
216getpath.o: $(LIBPL)/getpath.c Makefile
217 $(CC) $(CFLAGS) -DPYTHONPATH=\"$(PYTHONPATH)\" -c $(LIBPL)/getpath.c
218
219# Setup is copied from Setup.in *only* if it doesn't yet exist
220Setup:
221 cp $(srcdir)/Setup.in Setup
222
223# Make the intermediate Makefile.pre from Makefile.pre.in
224Makefile.pre: Makefile.pre.in sedscript
225 sed -f sedscript $(srcdir)/Makefile.pre.in >Makefile.pre
226
227# Shortcuts to make the sed arguments on one line
228P=prefix
229E=exec_prefix
230H=Generated automatically from Makefile.pre.in by sedscript.
231L=LINKFORSHARED
232
233# Make the sed script used to create Makefile.pre from Makefile.pre.in
234sedscript: $(MAKEFILE)
235 sed -n \
236 -e '1s/.*/1i\\/p' \
237 -e '2s%.*%# $H%p' \
238 -e '/^VERSION=/s/^VERSION=[ ]*\(.*\)/s%@VERSION[@]%\1%/p' \
239 -e '/^CC=/s/^CC=[ ]*\(.*\)/s%@CC[@]%\1%/p' \
240 -e '/^OPT=/s/^OPT=[ ]*\(.*\)/s%@OPT[@]%\1%/p' \
241 -e '/^LDFLAGS=/s/^LDFLAGS=[ ]*\(.*\)/s%@LDFLAGS[@]%\1%/p' \
242 -e '/^DEFS=/s/^DEFS=[ ]*\(.*\)/s%@DEFS[@]%\1%/p' \
243 -e '/^LIBS=/s/^LIBS=[ ]*\(.*\)/s%@LIBS[@]%\1%/p' \
244 -e '/^LIBM=/s/^LIBM=[ ]*\(.*\)/s%@LIBM[@]%\1%/p' \
245 -e '/^LIBC=/s/^LIBC=[ ]*\(.*\)/s%@LIBC[@]%\1%/p' \
246 -e '/^RANLIB=/s/^RANLIB=[ ]*\(.*\)/s%@RANLIB[@]%\1%/p' \
247 -e '/^MACHDEP=/s/^MACHDEP=[ ]*\(.*\)/s%@MACHDEP[@]%\1%/p' \
248 -e '/^SO=/s/^SO=[ ]*\(.*\)/s%@SO[@]%\1%/p' \
249 -e '/^LDSHARED=/s/^LDSHARED=[ ]*\(.*\)/s%@LDSHARED[@]%\1%/p' \
250 -e '/^CCSHARED=/s/^CCSHARED=[ ]*\(.*\)/s%@CCSHARED[@]%\1%/p' \
251 -e '/^$L=/s/^$L=[ ]*\(.*\)/s%@$L[@]%\1%/p' \
252 -e '/^$P=/s/^$P=\(.*\)/s%^$P=.*%$P=\1%/p' \
253 -e '/^$E=/s/^$E=\(.*\)/s%^$E=.*%$E=\1%/p' \
254 $(MAKEFILE) >sedscript
255 echo "/^installdir=/s%=.*%= $(installdir)%" >>sedscript
256 echo "/^exec_installdir=/s%=.*%=$(exec_installdir)%" >>sedscript
257 echo "/^srcdir=/s%=.*%= $(srcdir)%" >>sedscript
258 echo "/^VPATH=/s%=.*%= $(VPATH)%" >>sedscript
259 echo "/^LINKPATH=/s%=.*%= $(LINKPATH)%" >>sedscript
260 echo "/^BASELIB=/s%=.*%= $(BASELIB)%" >>sedscript
261 echo "/^BASESETUP=/s%=.*%= $(BASESETUP)%" >>sedscript
262
263# Bootstrap target
Guido van Rossum43e66611996-10-10 19:12:47 +0000264boot: clobber
Guido van Rossumbec74841996-11-27 19:38:53 +0000265 VERSION=`$(PYTHON) -c "import sys; print sys.version[:3]"`; \
266 installdir=`$(PYTHON) -c "import sys; print sys.prefix"`; \
267 exec_installdir=`$(PYTHON) -c "import sys; print sys.exec_prefix"`; \
Guido van Rossum946cf891996-09-11 12:15:07 +0000268 $(MAKE) -f $(srcdir)/Makefile.pre.in VPATH=$(VPATH) srcdir=$(srcdir) \
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000269 VERSION=$$VERSION \
270 installdir=$$installdir \
Guido van Rossum946cf891996-09-11 12:15:07 +0000271 exec_installdir=$$exec_installdir \
272 Makefile
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000273
274# Handy target to remove intermediate files and backups
275clean:
276 -rm -f *.o *~
277
278# Handy target to remove everything that is easily regenerated
279clobber: clean
Guido van Rossumbec74841996-11-27 19:38:53 +0000280 -rm -f *.a tags TAGS config.c Makefile.pre $(TARGET) sedscript
Guido van Rossum1631cbe1996-09-10 18:19:23 +0000281 -rm -f *.so *.sl so_locations
282
283
284# Handy target to remove everything you don't want to distribute
285distclean: clobber
286 -rm -f Makefile Setup