2 # Universal Unix Makefile for Python extensions
3 # =============================================
8 # 1. Build and install Python (1.5 or newer).
9 # 2. "make -f Makefile.pre.in boot"
11 # You should now have a shared library.
16 # Build *and install* the basic Python 1.5 distribution. See the
17 # Python README for instructions. (This version of Makefile.pre.in
18 # only withs with Python 1.5, alpha 3 or newer.)
20 # Create a file Setup.in for your extension. This file follows the
21 # format of the Modules/Setup.in file; see the instructions there.
22 # For a simple module called "spam" on file "spammodule.c", it can
23 # contain a single line:
25 # You can build as many modules as you want in the same directory --
26 # just have a separate line for each of them in the Setup.in file.
28 # If you want to build your extension as a shared library, insert a
29 # line containing just the string
31 # at the top of your Setup.in file.
33 # Note that the build process copies Setup.in to Setup, and then works
34 # with Setup. It doesn't overwrite Setup when Setup.in is changed, so
35 # while you're in the process of debugging your Setup.in file, you may
36 # want to edit Setup instead, and copy it back to Setup.in later.
37 # (All this is done so you can distribute your extension easily and
38 # someone else can select the modules they actually want to build by
39 # commenting out lines in the Setup file, without editing the
40 # original. Editing Setup is also used to specify nonstandard
41 # locations for include or library files.)
43 # Copy this file (Misc/Makefile.pre.in) to the directory containing
46 # Run "make -f Makefile.pre.in boot". This creates Makefile
47 # (producing Makefile.pre and sedscript as intermediate files) and
48 # config.c, incorporating the values for sys.prefix, sys.exec_prefix
49 # and sys.version from the installed Python binary. For this to work,
50 # the python binary must be on your path. If this fails, try
51 # make -f Makefile.pre.in Makefile VERSION=1.5 installdir=<prefix>
52 # where <prefix> is the prefix used to install Python for installdir
53 # (and possibly similar for exec_installdir=<exec_prefix>).
55 # Note: "make boot" implies "make clobber" -- it assumes that when you
56 # bootstrap you may have changed platforms so it removes all previous
59 # If you are building your extension as a shared library (your
60 # Setup.in file starts with *shared*), run "make" or "make sharedmods"
61 # to build the shared library files. If you are building a statically
62 # linked Python binary (the only solution of your platform doesn't
63 # support shared libraries, and sometimes handy if you want to
64 # distribute or install the resulting Python binary), run "make
67 # Note: Each time you edit Makefile.pre.in or Setup, you must run
68 # "make Makefile" before running "make".
70 # Hint: if you want to use VPATH, you can start in an empty
71 # subdirectory and say (e.g.):
72 # make -f ../Makefile.pre.in boot srcdir=.. VPATH=..
75 # === Bootstrap variables (edited through "make boot") ===
77 # The prefix used by "make inclinstall libainstall" of core python
78 installdir= /usr/local
80 # The exec_prefix used by the same
81 exec_installdir=$(installdir)
83 # Source directory and VPATH in case you want to use VPATH.
84 # (You will have to edit these two lines yourself -- there is no
85 # automatic support as the Makefile is not generated by
90 # === Variables that you may want to customize (rarely) ===
92 # (Static) build target
95 # Installed python binary (used only by boot target)
98 # Add more -I and -D options here
99 CFLAGS= $(OPT) -I$(INCLUDEPY) -I$(EXECINCLUDEPY) $(DEFS)
101 # These two variables can be set in Setup to merge extensions.
106 # === Variables set by makesetup ===
111 # === Definitions added by makesetup ===
113 # === Variables from configure (through sedscript) ===
131 LINKFORSHARED= @LINKFORSHARED@
134 # Install prefix for architecture-independent files
137 # Install prefix for architecture-dependent files
138 exec_prefix= $(prefix)
140 # === Fixed definitions ===
142 # Shell used by make (some versions default to the login shell, which is bad)
145 # Expanded directories
146 BINDIR= $(exec_installdir)/bin
147 LIBDIR= $(exec_prefix)/lib
148 MANDIR= $(installdir)/man
149 INCLUDEDIR= $(installdir)/include
150 SCRIPTDIR= $(prefix)/lib
152 # Detailed destination directories
153 BINLIBDEST= $(LIBDIR)/python$(VERSION)
154 LIBDEST= $(SCRIPTDIR)/python$(VERSION)
155 INCLUDEPY= $(INCLUDEDIR)/python$(VERSION)
156 EXECINCLUDEPY= $(exec_installdir)/include/python$(VERSION)
157 LIBP= $(exec_installdir)/lib/python$(VERSION)
158 DESTSHARED= $(BINLIBDEST)/site-packages
160 LIBPL= $(LIBP)/config
162 PYTHONLIBS= $(LIBPL)/libpython$(VERSION).a
164 MAKESETUP= $(LIBPL)/makesetup
165 MAKEFILE= $(LIBPL)/Makefile
166 CONFIGC= $(LIBPL)/config.c
167 CONFIGCIN= $(LIBPL)/config.c.in
168 SETUP= $(LIBPL)/Setup
170 SYSLIBS= $(LIBM) $(LIBC)
172 ADDOBJS= $(LIBPL)/python.o config.o
174 # Portable install script (configure doesn't always guess right)
175 INSTALL= $(LIBPL)/install-sh -c
176 # Shared libraries must be installed with executable mode on some systems;
177 # rather than figuring out exactly which, we always give them executable mode.
178 # Also, making them read-only seems to be a good idea...
179 INSTALL_SHARED= ${INSTALL} -m 555
181 #---------------------------------------------------
182 # Possibly change some definintions for C++
184 LDSHARED=$(MY_LDSHARED)
191 # === Fixed rules ===
193 # Default target. This builds shared libraries only
194 default: $(HELPERLIB) sharedmods
197 all: static sharedmods
199 # Build shared libraries from our extension modules
200 sharedmods: $(SHAREDMODS)
202 # Build a static Python binary containing our extension modules
204 $(TARGET): $(ADDOBJS) lib.a $(PYTHONLIBS) Makefile $(BASELIB)
205 $(LINKCC) $(LDFLAGS) $(LINKFORSHARED) \
206 $(ADDOBJS) lib.a $(PYTHONLIBS) \
207 $(LINKPATH) $(BASELIB) $(MODLIBS) $(LIBS) $(SYSLIBS) \
208 -o $(TARGET) $(LDLAST)
210 #------------------------------------------------------------------------
211 #------------------------------------------------------------------------
212 # This is a default version of the install target for wxPython. It just
213 # redirects to wxInstall below...
218 # if test ! -d $(DESTSHARED) ; then \
219 # mkdir $(DESTSHARED) ; else true ; fi
220 # -for i in X $(SHAREDMODS); do \
221 # if test $$i != X; \
222 # then $(INSTALL_SHARED) $$i $(DESTSHARED)/$$i; \
227 # Build the library containing our extension modules
230 ar cr lib.a $(MODOBJS)
233 # This runs makesetup *twice* to use the BASESETUP definition from Setup
234 config.c Makefile: Makefile.pre Setup $(BASESETUP) $(MAKESETUP)
236 -m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP)
237 $(MAKE) -f Makefile do-it-again
239 # Internal target to run makesetup for the second time
242 -m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP)
244 # Make config.o from the config.c created by makesetup
246 $(CC) $(CFLAGS) -c config.c
248 # Setup is copied from Setup.in *only* if it doesn't yet exist
252 # Make the intermediate Makefile.pre from Makefile.pre.in
253 Makefile.pre: Makefile.pre.in sedscript
254 sed -f sedscript Makefile.pre.in >Makefile.pre
256 # Shortcuts to make the sed arguments on one line
259 H=Generated automatically from Makefile.pre.in by sedscript.
262 # Make the sed script used to create Makefile.pre from Makefile.pre.in
263 sedscript: $(MAKEFILE)
267 -e '/^VERSION=/s/^VERSION=[ ]*\(.*\)/s%@VERSION[@]%\1%/p' \
268 -e '/^CC=/s/^CC=[ ]*\(.*\)/s%@CC[@]%\1%/p' \
269 -e '/^CCC=/s/^CCC=[ ]*\(.*\)/s%#@SET_CCC[@]%CCC=\1%/p' \
270 -e '/^LINKCC=/s/^LINKCC=[ ]*\(.*\)/s%@LINKCC[@]%\1%/p' \
271 -e '/^OPT=/s/^OPT=[ ]*\(.*\)/s%@OPT[@]%\1%/p' \
272 -e '/^LDFLAGS=/s/^LDFLAGS=[ ]*\(.*\)/s%@LDFLAGS[@]%\1%/p' \
273 -e '/^DEFS=/s/^DEFS=[ ]*\(.*\)/s%@DEFS[@]%\1%/p' \
274 -e '/^LIBS=/s/^LIBS=[ ]*\(.*\)/s%@LIBS[@]%\1%/p' \
275 -e '/^LIBM=/s/^LIBM=[ ]*\(.*\)/s%@LIBM[@]%\1%/p' \
276 -e '/^LIBC=/s/^LIBC=[ ]*\(.*\)/s%@LIBC[@]%\1%/p' \
277 -e '/^RANLIB=/s/^RANLIB=[ ]*\(.*\)/s%@RANLIB[@]%\1%/p' \
278 -e '/^MACHDEP=/s/^MACHDEP=[ ]*\(.*\)/s%@MACHDEP[@]%\1%/p' \
279 -e '/^SO=/s/^SO=[ ]*\(.*\)/s%@SO[@]%\1%/p' \
280 -e '/^LDSHARED=/s/^LDSHARED=[ ]*\(.*\)/s%@LDSHARED[@]%\1%/p' \
281 -e '/^CCSHARED=/s/^CCSHARED=[ ]*\(.*\)/s%@CCSHARED[@]%\1%/p' \
282 -e '/^$L=/s/^$L=[ ]*\(.*\)/s%@$L[@]%\1%/p' \
283 -e '/^$P=/s/^$P=\(.*\)/s%^$P=.*%$P=\1%/p' \
284 -e '/^$E=/s/^$E=\(.*\)/s%^$E=.*%$E=\1%/p' \
285 $(MAKEFILE) >sedscript
286 echo "/^#@SET_CCC@/d" >>sedscript
287 echo "/^installdir=/s%=.*%= $(installdir)%" >>sedscript
288 echo "/^exec_installdir=/s%=.*%=$(exec_installdir)%" >>sedscript
289 echo "/^srcdir=/s%=.*%= $(srcdir)%" >>sedscript
290 echo "/^VPATH=/s%=.*%= $(VPATH)%" >>sedscript
291 echo "/^LINKPATH=/s%=.*%= $(LINKPATH)%" >>sedscript
292 echo "/^BASELIB=/s%=.*%= $(BASELIB)%" >>sedscript
293 echo "/^BASESETUP=/s%=.*%= $(BASESETUP)%" >>sedscript
297 VERSION=`$(PYTHON) -c "import sys; print sys.version[:3]"`; \
298 installdir=`$(PYTHON) -c "import sys; print sys.prefix"`; \
299 exec_installdir=`$(PYTHON) -c "import sys; print sys.exec_prefix"`; \
300 $(MAKE) -f Makefile.pre.in VPATH=$(VPATH) srcdir=$(srcdir) \
302 installdir=$$installdir \
303 exec_installdir=$$exec_installdir \
306 # Handy target to remove intermediate files and backups
310 # Handy target to remove everything that is easily regenerated
312 -rm -f *.a tags TAGS config.c Makefile.pre $(TARGET) sedscript
313 -rm -f *.so *.sl so_locations
316 # Handy target to remove everything you don't want to distribute
318 -rm -f Makefile Setup
323 #------------------------------------------------------------------------
324 #------------------------------------------------------------------------
325 # Custom rules and dependencies added for wxPython
330 SWIGFLAGS=-c++ -shadow -python -dnone -D__WXGTK__ $(SEPARATE)
333 PYMODULES = $(GENCODEDIR)/wx.py $(GENCODEDIR)/events.py \
334 $(GENCODEDIR)/windows.py $(GENCODEDIR)/misc.py \
335 $(GENCODEDIR)/gdi.py $(GENCODEDIR)/mdi.py \
336 $(GENCODEDIR)/controls.py $(GENCODEDIR)/controls2.py \
337 $(GENCODEDIR)/windows2.py $(GENCODEDIR)/cmndlgs.py \
338 $(GENCODEDIR)/stattool.py $(GENCODEDIR)/frames.py \
339 $(GENCODEDIR)/windows3.py __init__.py \
340 $(GENCODEDIR)/utils.py $(GENCODEDIR)/image.py \
341 $(GENCODEDIR)/printfw.py $(GENCODEDIR)/misc2.py \
342 $(GENCODEDIR)/glcanvas.py
345 # Implicit rules to run SWIG
346 $(GENCODEDIR)/%.cpp : %.i
347 swig $(SWIGFLAGS) -c -o $@ $<
349 $(GENCODEDIR)/%.py : %.i
350 swig $(SWIGFLAGS) -c -o $(GENCODEDIR)/tmp_wrap.cpp $<
351 rm $(GENCODEDIR)/tmp_wrap.cpp
353 # This one must leave out the -c flag so we define the whole rule
354 #$(GENCODEDIR)/wx.cpp $(GENCODEDIR)/wx.py : wx.i my_typemaps.i _defs.i _extras.py
355 # swig $(SWIGFLAGS) -o $(GENCODEDIR)/wx.cpp wx.i
358 # define some dependencies
359 $(GENCODEDIR)/wx.cpp $(GENCODEDIR)/wx.py : wx.i my_typemaps.i _defs.i _extras.py
360 $(GENCODEDIR)/windows.cpp $(GENCODEDIR)/windows.py : windows.i my_typemaps.i _defs.i
361 $(GENCODEDIR)/windows2.cpp $(GENCODEDIR)/windows2.py : windows2.i my_typemaps.i _defs.i
362 $(GENCODEDIR)/windows3.cpp $(GENCODEDIR)/windows3.py : windows3.i my_typemaps.i _defs.i
363 $(GENCODEDIR)/events.cpp $(GENCODEDIR)/events.py : events.i my_typemaps.i _defs.i
364 $(GENCODEDIR)/misc.cpp $(GENCODEDIR)/misc.py : misc.i my_typemaps.i _defs.i
365 $(GENCODEDIR)/misc2.cpp $(GENCODEDIR)/misc2.py : misc2.i my_typemaps.i _defs.i
366 $(GENCODEDIR)/gdi.cpp $(GENCODEDIR)/gdi.py : gdi.i my_typemaps.i _defs.i
367 $(GENCODEDIR)/mdi.cpp $(GENCODEDIR)/mdi.py : mdi.i my_typemaps.i _defs.i
368 $(GENCODEDIR)/controls.cpp $(GENCODEDIR)/controls.py : controls.i my_typemaps.i _defs.i
369 $(GENCODEDIR)/controls2.cpp $(GENCODEDIR)/controls2.py : controls2.i my_typemaps.i _defs.i
370 $(GENCODEDIR)/cmndlgs.cpp $(GENCODEDIR)/cmndlgs.py : cmndlgs.i my_typemaps.i _defs.i
371 $(GENCODEDIR)/frames.cpp $(GENCODEDIR)/frames.py : frames.i my_typemaps.i _defs.i
372 $(GENCODEDIR)/stattool.cpp $(GENCODEDIR)/stattool.py : stattool.i my_typemaps.i _defs.i
373 $(GENCODEDIR)/image.cpp $(GENCODEDIR)/image.py : image.i my_typemaps.i _defs.i
374 $(GENCODEDIR)/utils.cpp $(GENCODEDIR)/utils.py : utils.i my_typemaps.i _defs.i
375 $(GENCODEDIR)/printfw.cpp $(GENCODEDIR)/printfw.py : printfw.i my_typemaps.i _defs.i
376 $(GENCODEDIR)/glcanvas.cpp $(GENCODEDIR)/glcanvas.py : glcanvas.i my_typemaps.i _defs.i
378 $(GENCODEDIR)/helpers.cpp:
379 ln -s `pwd`/helpers.cpp $@
381 $(GENCODEDIR)/libpy.c:
382 ln -s `pwd`/libpy.c $@
384 $(GENCODEDIR)/_glcanvas.cpp:
385 -cp $(WXWIN)/utils/glcanvas/$(GENCODEDIR)/glcanvas.cpp $@
386 -cp $(WXWIN)/utils/glcanvas/$(GENCODEDIR)/glcanvas.h ./glcanvas.h
389 wxInstall : $(HELPERLIB) sharedmods $(PYMODULES)
390 if test ! -d $(TARGETDIR) ; then \
391 mkdir $(TARGETDIR) ; else true ; fi
392 if [ "$(SHAREDMODS)" != "" ]; then \
393 chmod 755 $(SHAREDMODS); \
394 cp $(SHAREDMODS) $(TARGETDIR); fi
395 -for i in $(PYMODULES); do \
396 cp $$i $(TARGETDIR); \
398 if [ "$(TARGETDIR)" != ".." ]; then \
399 mkdir $(TARGETDIR)/lib; \
400 mkdir $(TARGETDIR)/lib/sizers; \
401 mkdir $(TARGETDIR)/demo; \
402 mkdir $(TARGETDIR)/demo/bitmaps; \
403 cp ../lib/*.py $(TARGETDIR)/lib; \
404 cp ../lib/sizers/*.py $(TARGETDIR)/lib/sizers; \
405 cp ../demo/*.py $(TARGETDIR)/demo; \
406 cp ../lib/*.txt $(TARGETDIR)/lib; \
407 cp ../lib/sizers/*.txt $(TARGETDIR)/lib/sizers; \
408 cp ../demo/*.txt $(TARGETDIR)/demo; \
409 cp ../demo/bitmaps/[a-z]* $(TARGETDIR)/demo/bitmaps; \
411 if [ "$(TARGETDIR)" != ".." ]; then \
412 python $(LIBDEST)/compileall.py $(TARGETDIR); \
413 python -O $(LIBDEST)/compileall.py $(TARGETDIR); \
415 python $(LIBDEST)/compileall.py -l $(TARGETDIR); \
416 python -O $(LIBDEST)/compileall.py -l $(TARGETDIR);\
419 cp lib$(WXPYLIB)$(SO) $(WXPYLIBDIR)
420 @echo ---------------------------------------------------------
421 @echo You may have to run ldconfig, or set an environment
422 @echo variable in order for $(WXPYLIBDIR)/lib$(WXPYLIB)$(SO)
423 @echo to be found at runtime. See your man pages for ld.so or
425 @echo ---------------------------------------------------------
429 helpers.o: $(srcdir)/helpers.cpp; $(CCC) $(CCSHARED) $(C_DEFINES) $(C_FLAGS) $(CFLAGS) -c $(srcdir)/helpers.cpp
430 libpy.o: $(srcdir)/libpy.c; $(CC) $(CCSHARED) $(C_DEFINES) $(C_FLAGS) $(CFLAGS) -c $(srcdir)/libpy.c
432 $(HELPERLIB) : helpers.o libpy.o
433 $(LDSHARED) helpers.o libpy.o $(C_DEFINES) $(C_FLAGS) -Xlinker $(WX_CONFIG_LIBS) -o $@
439 libwxPython.a : lib.a
445 cd ../..; wxPython/distrib/maketgz $(WXP_VERSION)
448 cd ../distrib; ./makerpm $(WXP_VERSION)