1 # Universal Unix Makefile for Python extensions
2 # =============================================
7 # 1. Build and install Python (1.5 or newer).
8 # 2. "make -f Makefile.pre.in boot"
10 # You should now have a shared library.
15 # 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.)
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:
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.
27 # If you want to build your extension as a shared library, insert a
28 # line containing just the string
30 # at the top of your Setup.in file.
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.)
42 # Copy this file (Misc/Makefile.pre.in) to the directory containing
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
50 # make -f Makefile.pre.in Makefile VERSION=1.5 installdir=<prefix>
51 # where <prefix> is the prefix used to install Python for installdir
52 # (and possibly similar for exec_installdir=<exec_prefix>).
54 # Note: "make boot" implies "make clobber" -- it assumes that when you
55 # bootstrap you may have changed platforms so it removes all previous
58 # 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
66 # Note: Each time you edit Makefile.pre.in or Setup, you must run
67 # "make Makefile" before running "make".
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=..
74 # === Bootstrap variables (edited through "make boot") ===
76 # The prefix used by "make inclinstall libainstall" of core python
77 installdir= /usr/local
79 # The exec_prefix used by the same
80 exec_installdir=$(installdir)
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
89 # === Variables that you may want to customize (rarely) ===
91 # (Static) build target
94 # Installed python binary (used only by boot target)
97 # Add more -I and -D options here
98 CFLAGS= $(OPT) -I$(INCLUDEPY) -I$(EXECINCLUDEPY) $(DEFS)
100 # These two variables can be set in Setup to merge extensions.
105 # === Variables set by makesetup ===
110 # === Definitions added by makesetup ===
112 # === Variables from configure (through sedscript) ===
130 LINKFORSHARED= @LINKFORSHARED@
133 # Install prefix for architecture-independent files
136 # Install prefix for architecture-dependent files
137 exec_prefix= $(prefix)
139 # === Fixed definitions ===
141 # Shell used by make (some versions default to the login shell, which is bad)
144 # Expanded directories
145 BINDIR= $(exec_installdir)/bin
146 LIBDIR= $(exec_prefix)/lib
147 MANDIR= $(installdir)/man
148 INCLUDEDIR= $(installdir)/include
149 SCRIPTDIR= $(prefix)/lib
151 # Detailed destination directories
152 BINLIBDEST= $(LIBDIR)/python$(VERSION)
153 LIBDEST= $(SCRIPTDIR)/python$(VERSION)
154 INCLUDEPY= $(INCLUDEDIR)/python$(VERSION)
155 EXECINCLUDEPY= $(exec_installdir)/include/python$(VERSION)
156 LIBP= $(exec_installdir)/lib/python$(VERSION)
157 DESTSHARED= $(BINLIBDEST)/site-packages
159 LIBPL= $(LIBP)/config
161 PYTHONLIBS= $(LIBPL)/libpython$(VERSION).a
163 MAKESETUP= $(LIBPL)/makesetup
164 MAKEFILE= $(LIBPL)/Makefile
165 CONFIGC= $(LIBPL)/config.c
166 CONFIGCIN= $(LIBPL)/config.c.in
167 SETUP= $(LIBPL)/Setup
169 SYSLIBS= $(LIBM) $(LIBC)
171 ADDOBJS= $(LIBPL)/python.o config.o
173 # Portable install script (configure doesn't always guess right)
174 INSTALL= $(LIBPL)/install-sh -c
175 # Shared libraries must be installed with executable mode on some systems;
176 # rather than figuring out exactly which, we always give them executable mode.
177 # Also, making them read-only seems to be a good idea...
178 INSTALL_SHARED= ${INSTALL} -m 555
180 # === Fixed rules ===
182 # Default target. This builds shared libraries only
186 all: static sharedmods
188 # Build shared libraries from our extension modules
189 sharedmods: $(SHAREDMODS)
191 # Build a static Python binary containing our extension modules
193 $(TARGET): $(ADDOBJS) lib.a $(PYTHONLIBS) Makefile $(BASELIB)
194 $(LINKCC) $(LDFLAGS) $(LINKFORSHARED) \
195 $(ADDOBJS) lib.a $(PYTHONLIBS) \
196 $(LINKPATH) $(BASELIB) $(MODLIBS) $(LIBS) $(SYSLIBS) \
197 -o $(TARGET) $(LDLAST)
199 #------------------------------------------------------------------------
200 #------------------------------------------------------------------------
201 # This is a defaul version of the install target for wxPython. It just
202 # redirects to wxInstall below...
207 # if test ! -d $(DESTSHARED) ; then \
208 # mkdir $(DESTSHARED) ; else true ; fi
209 # -for i in X $(SHAREDMODS); do \
210 # if test $$i != X; \
211 # then $(INSTALL_SHARED) $$i $(DESTSHARED)/$$i; \
216 # Build the library containing our extension modules
219 ar cr lib.a $(MODOBJS)
222 # This runs makesetup *twice* to use the BASESETUP definition from Setup
223 config.c Makefile: Makefile.pre Setup $(BASESETUP) $(MAKESETUP)
225 -m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP)
226 $(MAKE) -f Makefile do-it-again
228 # Internal target to run makesetup for the second time
231 -m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP)
233 # Make config.o from the config.c created by makesetup
235 $(CC) $(CFLAGS) -c config.c
237 # Setup is copied from Setup.in *only* if it doesn't yet exist
239 cp $(srcdir)/Setup.in Setup
241 # Make the intermediate Makefile.pre from Makefile.pre.in
242 Makefile.pre: Makefile.pre.in sedscript
243 sed -f sedscript $(srcdir)/Makefile.pre.in >Makefile.pre
245 # Shortcuts to make the sed arguments on one line
248 H=Generated automatically from Makefile.pre.in by sedscript.
251 # Make the sed script used to create Makefile.pre from Makefile.pre.in
252 sedscript: $(MAKEFILE)
256 -e '/^VERSION=/s/^VERSION=[ ]*\(.*\)/s%@VERSION[@]%\1%/p' \
257 -e '/^CC=/s/^CC=[ ]*\(.*\)/s%@CC[@]%\1%/p' \
258 -e '/^CCC=/s/^CCC=[ ]*\(.*\)/s%#@SET_CCC[@]%CCC=\1%/p' \
259 -e '/^LINKCC=/s/^LINKCC=[ ]*\(.*\)/s%@LINKCC[@]%\1%/p' \
260 -e '/^OPT=/s/^OPT=[ ]*\(.*\)/s%@OPT[@]%\1%/p' \
261 -e '/^LDFLAGS=/s/^LDFLAGS=[ ]*\(.*\)/s%@LDFLAGS[@]%\1%/p' \
262 -e '/^DEFS=/s/^DEFS=[ ]*\(.*\)/s%@DEFS[@]%\1%/p' \
263 -e '/^LIBS=/s/^LIBS=[ ]*\(.*\)/s%@LIBS[@]%\1%/p' \
264 -e '/^LIBM=/s/^LIBM=[ ]*\(.*\)/s%@LIBM[@]%\1%/p' \
265 -e '/^LIBC=/s/^LIBC=[ ]*\(.*\)/s%@LIBC[@]%\1%/p' \
266 -e '/^RANLIB=/s/^RANLIB=[ ]*\(.*\)/s%@RANLIB[@]%\1%/p' \
267 -e '/^MACHDEP=/s/^MACHDEP=[ ]*\(.*\)/s%@MACHDEP[@]%\1%/p' \
268 -e '/^SO=/s/^SO=[ ]*\(.*\)/s%@SO[@]%\1%/p' \
269 -e '/^LDSHARED=/s/^LDSHARED=[ ]*\(.*\)/s%@LDSHARED[@]%\1%/p' \
270 -e '/^CCSHARED=/s/^CCSHARED=[ ]*\(.*\)/s%@CCSHARED[@]%\1%/p' \
271 -e '/^$L=/s/^$L=[ ]*\(.*\)/s%@$L[@]%\1%/p' \
272 -e '/^$P=/s/^$P=\(.*\)/s%^$P=.*%$P=\1%/p' \
273 -e '/^$E=/s/^$E=\(.*\)/s%^$E=.*%$E=\1%/p' \
274 $(MAKEFILE) >sedscript
275 echo "/^#@SET_CCC@/d" >>sedscript
276 echo "/^installdir=/s%=.*%= $(installdir)%" >>sedscript
277 echo "/^exec_installdir=/s%=.*%=$(exec_installdir)%" >>sedscript
278 echo "/^srcdir=/s%=.*%= $(srcdir)%" >>sedscript
279 echo "/^VPATH=/s%=.*%= $(VPATH)%" >>sedscript
280 echo "/^LINKPATH=/s%=.*%= $(LINKPATH)%" >>sedscript
281 echo "/^BASELIB=/s%=.*%= $(BASELIB)%" >>sedscript
282 echo "/^BASESETUP=/s%=.*%= $(BASESETUP)%" >>sedscript
286 VERSION=`$(PYTHON) -c "import sys; print sys.version[:3]"`; \
287 installdir=`$(PYTHON) -c "import sys; print sys.prefix"`; \
288 exec_installdir=`$(PYTHON) -c "import sys; print sys.exec_prefix"`; \
289 $(MAKE) -f $(srcdir)/Makefile.pre.in VPATH=$(VPATH) srcdir=$(srcdir) \
291 installdir=$$installdir \
292 exec_installdir=$$exec_installdir \
295 # Handy target to remove intermediate files and backups
299 # Handy target to remove everything that is easily regenerated
301 -rm -f *.a tags TAGS config.c Makefile.pre $(TARGET) sedscript
302 -rm -f *.so *.sl so_locations
305 # Handy target to remove everything you don't want to distribute
307 -rm -f Makefile Setup
312 #------------------------------------------------------------------------
313 #------------------------------------------------------------------------
314 # Custom rules and dependencies added for wxPython
317 SWIGFLAGS=-c++ -shadow -python -dnone -D__WXGTK__
320 PYMODULES = $(GENCODEDIR)/wxp.py $(GENCODEDIR)/events.py \
321 $(GENCODEDIR)/windows.py $(GENCODEDIR)/misc.py \
322 $(GENCODEDIR)/gdi.py $(GENCODEDIR)/mdi.py \
323 $(GENCODEDIR)/controls.py $(GENCODEDIR)/controls2.py \
324 $(GENCODEDIR)/windows2.py $(GENCODEDIR)/cmndlgs.py \
328 # Implicit rules to run SWIG
329 $(GENCODEDIR)/%.cpp : %.i
330 swig $(SWIGFLAGS) -c -o $@ $<
331 move $*.py $(GENCODEDIR)
333 $(GENCODEDIR)/%.py : %.i
334 swig $(SWIGFLAGS) -c -o $@ $<
335 move $*.py $(GENCODEDIR)
338 # This one must leave out the -c flag so we define the whole rule
339 $(GENCODEDIR)/wxp.cpp $(GENCODEDIR)/wxp.py : wxp.i my_typemaps.i _defs.i _extras.py
340 swig $(SWIGFLAGS) -o $(GENCODEDIR)/wxp.cpp wxp.i
341 move wxp.py $(GENCODEDIR)
344 # define some dependencies
345 $(GENCODEDIR)/windows.cpp $(GENCODEDIR)/windows.py : windows.i my_typemaps.i _defs.i
346 $(GENCODEDIR)/windows2.cpp $(GENCODEDIR)/windows2.py : windows2.i my_typemaps.i _defs.i
347 $(GENCODEDIR)/events.cpp $(GENCODEDIR)/events.py : events.i my_typemaps.i _defs.i
348 $(GENCODEDIR)/misc.cpp $(GENCODEDIR)/misc.py : misc.i my_typemaps.i _defs.i
349 $(GENCODEDIR)/gdi.cpp $(GENCODEDIR)/gdi.py : gdi.i my_typemaps.i _defs.i
350 $(GENCODEDIR)/mdi.cpp $(GENCODEDIR)/mdi.py : mdi.i my_typemaps.i _defs.i
351 $(GENCODEDIR)/controls.cpp $(GENCODEDIR)/controls.py : controls.i my_typemaps.i _defs.i
352 $(GENCODEDIR)/controls2.cpp $(GENCODEDIR)/controls2.py : controls2.i my_typemaps.i _defs.i
353 $(GENCODEDIR)/cmndlgs.cpp $(GENCODEDIR)/cmndlgs.py : cmndlgs.i my_typemaps.i _defs.i
357 wxInstall : sharedmods $(PYMODULES)
358 if test ! -d $(TARGETDIR) ; then \
359 mkdir $(TARGETDIR) ; else true ; fi
360 -for i in $(SHAREDMODS); do \
361 $(INSTALL_SHARED) $$i $(TARGETDIR)/$$i; \
363 -for i in $(PYMODULES); do \
364 $(INSTALL) $$i $(TARGETDIR)/$$i; \
366 python $(LIBDEST)/compileall.py -l $(TARGETDIR)
367 python -O $(LIBDEST)/compileall.py -l $(TARGETDIR)