Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 1 | # Universal Unix Makefile for Python extensions |
| 2 | # ============================================= |
| 3 | |
| 4 | # Short Instructions |
| 5 | # ------------------ |
| 6 | |
Guido van Rossum | bef03ae | 1997-07-19 22:52:43 +0000 | [diff] [blame] | 7 | # 1. Build and install Python (1.5 or newer). |
Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 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 | |
Guido van Rossum | bef03ae | 1997-07-19 22:52:43 +0000 | [diff] [blame] | 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.) |
Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 18 | |
| 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: |
| 23 | # spam spammodule.c |
| 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. |
| 26 | |
| 27 | # If you want to build your extension as a shared library, insert a |
| 28 | # line containing just the string |
| 29 | # *shared* |
| 30 | # at the top of your Setup.in file. |
| 31 | |
| 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.) |
| 41 | |
| 42 | # Copy this file (Misc/Makefile.pre.in) to the directory containing |
| 43 | # your extension. |
| 44 | |
| 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 |
Guido van Rossum | bef03ae | 1997-07-19 22:52:43 +0000 | [diff] [blame] | 50 | # make -f Makefile.pre.in Makefile VERSION=1.5 installdir=<prefix> |
Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 51 | # where <prefix> is the prefix used to install Python for installdir |
| 52 | # (and possibly similar for exec_installdir=<exec_prefix>). |
| 53 | |
Guido van Rossum | bec7484 | 1996-11-27 19:38:53 +0000 | [diff] [blame] | 54 | # Note: "make boot" implies "make clobber" -- it assumes that when you |
| 55 | # bootstrap you may have changed platforms so it removes all previous |
| 56 | # output files. |
| 57 | |
Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 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 |
| 64 | # python". |
| 65 | |
| 66 | # Note: Each time you edit Makefile.pre.in or Setup, you must run |
| 67 | # "make Makefile" before running "make". |
| 68 | |
| 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=.. |
| 72 | |
| 73 | |
| 74 | # === Bootstrap variables (edited through "make boot") === |
| 75 | |
| 76 | # The prefix used by "make inclinstall libainstall" of core python |
| 77 | installdir= /usr/local |
| 78 | |
| 79 | # The exec_prefix used by the same |
| 80 | exec_installdir=$(installdir) |
| 81 | |
| 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 |
| 85 | # config.status.) |
| 86 | srcdir= . |
| 87 | VPATH= . |
| 88 | |
| 89 | # === Variables that you may want to customize (rarely) === |
| 90 | |
Guido van Rossum | 434882e | 1996-10-08 17:21:11 +0000 | [diff] [blame] | 91 | # (Static) build target |
| 92 | TARGET= python |
| 93 | |
Guido van Rossum | bec7484 | 1996-11-27 19:38:53 +0000 | [diff] [blame] | 94 | # Installed python binary (used only by boot target) |
| 95 | PYTHON= python |
| 96 | |
Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 97 | # Add more -I and -D options here |
| 98 | CFLAGS= $(OPT) -I$(INCLUDEPY) -I$(LIBPL) $(DEFS) |
| 99 | |
| 100 | # These two variables can be set in Setup to merge extensions. |
| 101 | # See example[23]. |
| 102 | BASELIB= |
| 103 | BASESETUP= |
| 104 | |
| 105 | # === Variables set by makesetup === |
| 106 | |
| 107 | MODOBJS= _MODOBJS_ |
| 108 | MODLIBS= _MODLIBS_ |
| 109 | |
| 110 | # === Definitions added by makesetup === |
| 111 | |
| 112 | # === Variables from configure (through sedscript) === |
| 113 | |
| 114 | VERSION= @VERSION@ |
| 115 | CC= @CC@ |
| 116 | OPT= @OPT@ |
| 117 | LDFLAGS= @LDFLAGS@ |
| 118 | DEFS= @DEFS@ |
| 119 | LIBS= @LIBS@ |
| 120 | LIBM= @LIBM@ |
| 121 | LIBC= @LIBC@ |
| 122 | RANLIB= @RANLIB@ |
| 123 | MACHDEP= @MACHDEP@ |
| 124 | SO= @SO@ |
| 125 | LDSHARED= @LDSHARED@ |
| 126 | CCSHARED= @CCSHARED@ |
| 127 | LINKFORSHARED= @LINKFORSHARED@ |
| 128 | |
| 129 | # Install prefix for architecture-independent files |
| 130 | prefix= /usr/local |
| 131 | |
| 132 | # Install prefix for architecture-dependent files |
| 133 | exec_prefix= $(prefix) |
| 134 | |
| 135 | # === Fixed definitions === |
| 136 | |
Guido van Rossum | b0259bc | 1996-10-24 21:47:45 +0000 | [diff] [blame] | 137 | # Shell used by make (some versions default to the login shell, which is bad) |
| 138 | SHELL= /bin/sh |
| 139 | |
Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 140 | # Expanded directories |
| 141 | BINDIR= $(exec_installdir)/bin |
| 142 | LIBDIR= $(exec_prefix)/lib |
| 143 | MANDIR= $(installdir)/man |
| 144 | INCLUDEDIR= $(installdir)/include |
| 145 | SCRIPTDIR= $(prefix)/lib |
| 146 | |
| 147 | # Detailed destination directories |
| 148 | BINLIBDEST= $(LIBDIR)/python$(VERSION) |
| 149 | LIBDEST= $(SCRIPTDIR)/python$(VERSION) |
| 150 | INCLUDEPY= $(INCLUDEDIR)/python$(VERSION) |
| 151 | LIBP= $(exec_installdir)/lib/python$(VERSION) |
Fred Drake | bfeb74d | 1997-10-04 04:56:40 +0000 | [diff] [blame^] | 152 | DESTSHARED= $(BINLIBDEST)/site-packages |
Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 153 | |
| 154 | LIBPL= $(LIBP)/config |
| 155 | |
Guido van Rossum | bef03ae | 1997-07-19 22:52:43 +0000 | [diff] [blame] | 156 | PYTHONLIBS= $(LIBPL)/libpython$(VERSION).a |
Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 157 | |
| 158 | MAKESETUP= $(LIBPL)/makesetup |
| 159 | MAKEFILE= $(LIBPL)/Makefile |
| 160 | CONFIGC= $(LIBPL)/config.c |
| 161 | CONFIGCIN= $(LIBPL)/config.c.in |
| 162 | SETUP= $(LIBPL)/Setup |
| 163 | |
| 164 | SYSLIBS= $(LIBM) $(LIBC) |
| 165 | |
Guido van Rossum | bef03ae | 1997-07-19 22:52:43 +0000 | [diff] [blame] | 166 | ADDOBJS= $(LIBPL)/python.o config.o |
Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 167 | |
Fred Drake | bfeb74d | 1997-10-04 04:56:40 +0000 | [diff] [blame^] | 168 | # Portable install script (configure doesn't always guess right) |
| 169 | INSTALL= $(LIBPL)/install-sh -c |
| 170 | # Shared libraries must be installed with executable mode on some systems; |
| 171 | # rather than figuring out exactly which, we always give them executable mode. |
| 172 | # Also, making them read-only seems to be a good idea... |
| 173 | INSTALL_SHARED= ${INSTALL} -m 555 |
| 174 | |
Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 175 | # === Fixed rules === |
| 176 | |
| 177 | # Default target. This builds shared libraries only |
| 178 | default: sharedmods |
| 179 | |
| 180 | # Build everything |
Guido van Rossum | 434882e | 1996-10-08 17:21:11 +0000 | [diff] [blame] | 181 | all: static sharedmods |
Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 182 | |
| 183 | # Build shared libraries from our extension modules |
| 184 | sharedmods: $(SHAREDMODS) |
| 185 | |
| 186 | # Build a static Python binary containing our extension modules |
Guido van Rossum | 434882e | 1996-10-08 17:21:11 +0000 | [diff] [blame] | 187 | static: $(TARGET) |
Guido van Rossum | bef03ae | 1997-07-19 22:52:43 +0000 | [diff] [blame] | 188 | $(TARGET): $(ADDOBJS) lib.a $(PYTHONLIBS) Makefile $(BASELIB) |
| 189 | $(CC) $(LDFLAGS) $(ADDOBJS) lib.a $(PYTHONLIBS) \ |
Guido van Rossum | 434882e | 1996-10-08 17:21:11 +0000 | [diff] [blame] | 190 | $(LINKPATH) $(BASELIB) $(MODLIBS) $(LIBS) $(SYSLIBS) \ |
| 191 | -o $(TARGET) |
Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 192 | |
Fred Drake | bfeb74d | 1997-10-04 04:56:40 +0000 | [diff] [blame^] | 193 | install: sharedmods |
| 194 | if test ! -d $(DESTSHARED) ; then \ |
| 195 | mkdir $(DESTSHARED) ; else true ; fi |
| 196 | -for i in X $(SHAREDMODS); do \ |
| 197 | if test $$i != X; \ |
| 198 | then $(INSTALL_SHARED) $$i $(DESTSHARED)/$$i; \ |
| 199 | fi; \ |
| 200 | done |
| 201 | |
Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 202 | # Build the library containing our extension modules |
| 203 | lib.a: $(MODOBJS) |
| 204 | -rm -f lib.a |
| 205 | ar cr lib.a $(MODOBJS) |
Guido van Rossum | bef03ae | 1997-07-19 22:52:43 +0000 | [diff] [blame] | 206 | -$(RANLIB) lib.a |
Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 207 | |
| 208 | # This runs makesetup *twice* to use the BASESETUP definition from Setup |
| 209 | config.c Makefile: Makefile.pre Setup $(BASESETUP) $(MAKESETUP) |
| 210 | $(MAKESETUP) \ |
| 211 | -m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP) |
| 212 | $(MAKE) -f Makefile do-it-again |
| 213 | |
| 214 | # Internal target to run makesetup for the second time |
| 215 | do-it-again: |
| 216 | $(MAKESETUP) \ |
| 217 | -m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP) |
| 218 | |
| 219 | # Make config.o from the config.c created by makesetup |
| 220 | config.o: config.c |
| 221 | $(CC) $(CFLAGS) -c config.c |
| 222 | |
Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 223 | # Setup is copied from Setup.in *only* if it doesn't yet exist |
| 224 | Setup: |
| 225 | cp $(srcdir)/Setup.in Setup |
| 226 | |
| 227 | # Make the intermediate Makefile.pre from Makefile.pre.in |
| 228 | Makefile.pre: Makefile.pre.in sedscript |
| 229 | sed -f sedscript $(srcdir)/Makefile.pre.in >Makefile.pre |
| 230 | |
| 231 | # Shortcuts to make the sed arguments on one line |
| 232 | P=prefix |
| 233 | E=exec_prefix |
| 234 | H=Generated automatically from Makefile.pre.in by sedscript. |
| 235 | L=LINKFORSHARED |
| 236 | |
| 237 | # Make the sed script used to create Makefile.pre from Makefile.pre.in |
| 238 | sedscript: $(MAKEFILE) |
| 239 | sed -n \ |
| 240 | -e '1s/.*/1i\\/p' \ |
| 241 | -e '2s%.*%# $H%p' \ |
| 242 | -e '/^VERSION=/s/^VERSION=[ ]*\(.*\)/s%@VERSION[@]%\1%/p' \ |
| 243 | -e '/^CC=/s/^CC=[ ]*\(.*\)/s%@CC[@]%\1%/p' \ |
| 244 | -e '/^OPT=/s/^OPT=[ ]*\(.*\)/s%@OPT[@]%\1%/p' \ |
| 245 | -e '/^LDFLAGS=/s/^LDFLAGS=[ ]*\(.*\)/s%@LDFLAGS[@]%\1%/p' \ |
| 246 | -e '/^DEFS=/s/^DEFS=[ ]*\(.*\)/s%@DEFS[@]%\1%/p' \ |
| 247 | -e '/^LIBS=/s/^LIBS=[ ]*\(.*\)/s%@LIBS[@]%\1%/p' \ |
| 248 | -e '/^LIBM=/s/^LIBM=[ ]*\(.*\)/s%@LIBM[@]%\1%/p' \ |
| 249 | -e '/^LIBC=/s/^LIBC=[ ]*\(.*\)/s%@LIBC[@]%\1%/p' \ |
| 250 | -e '/^RANLIB=/s/^RANLIB=[ ]*\(.*\)/s%@RANLIB[@]%\1%/p' \ |
| 251 | -e '/^MACHDEP=/s/^MACHDEP=[ ]*\(.*\)/s%@MACHDEP[@]%\1%/p' \ |
| 252 | -e '/^SO=/s/^SO=[ ]*\(.*\)/s%@SO[@]%\1%/p' \ |
| 253 | -e '/^LDSHARED=/s/^LDSHARED=[ ]*\(.*\)/s%@LDSHARED[@]%\1%/p' \ |
| 254 | -e '/^CCSHARED=/s/^CCSHARED=[ ]*\(.*\)/s%@CCSHARED[@]%\1%/p' \ |
| 255 | -e '/^$L=/s/^$L=[ ]*\(.*\)/s%@$L[@]%\1%/p' \ |
| 256 | -e '/^$P=/s/^$P=\(.*\)/s%^$P=.*%$P=\1%/p' \ |
| 257 | -e '/^$E=/s/^$E=\(.*\)/s%^$E=.*%$E=\1%/p' \ |
| 258 | $(MAKEFILE) >sedscript |
| 259 | echo "/^installdir=/s%=.*%= $(installdir)%" >>sedscript |
| 260 | echo "/^exec_installdir=/s%=.*%=$(exec_installdir)%" >>sedscript |
| 261 | echo "/^srcdir=/s%=.*%= $(srcdir)%" >>sedscript |
| 262 | echo "/^VPATH=/s%=.*%= $(VPATH)%" >>sedscript |
| 263 | echo "/^LINKPATH=/s%=.*%= $(LINKPATH)%" >>sedscript |
| 264 | echo "/^BASELIB=/s%=.*%= $(BASELIB)%" >>sedscript |
| 265 | echo "/^BASESETUP=/s%=.*%= $(BASESETUP)%" >>sedscript |
| 266 | |
| 267 | # Bootstrap target |
Guido van Rossum | 43e6661 | 1996-10-10 19:12:47 +0000 | [diff] [blame] | 268 | boot: clobber |
Guido van Rossum | bec7484 | 1996-11-27 19:38:53 +0000 | [diff] [blame] | 269 | VERSION=`$(PYTHON) -c "import sys; print sys.version[:3]"`; \ |
| 270 | installdir=`$(PYTHON) -c "import sys; print sys.prefix"`; \ |
| 271 | exec_installdir=`$(PYTHON) -c "import sys; print sys.exec_prefix"`; \ |
Guido van Rossum | 946cf89 | 1996-09-11 12:15:07 +0000 | [diff] [blame] | 272 | $(MAKE) -f $(srcdir)/Makefile.pre.in VPATH=$(VPATH) srcdir=$(srcdir) \ |
Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 273 | VERSION=$$VERSION \ |
| 274 | installdir=$$installdir \ |
Guido van Rossum | 946cf89 | 1996-09-11 12:15:07 +0000 | [diff] [blame] | 275 | exec_installdir=$$exec_installdir \ |
| 276 | Makefile |
Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 277 | |
| 278 | # Handy target to remove intermediate files and backups |
| 279 | clean: |
| 280 | -rm -f *.o *~ |
| 281 | |
| 282 | # Handy target to remove everything that is easily regenerated |
| 283 | clobber: clean |
Guido van Rossum | bec7484 | 1996-11-27 19:38:53 +0000 | [diff] [blame] | 284 | -rm -f *.a tags TAGS config.c Makefile.pre $(TARGET) sedscript |
Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 285 | -rm -f *.so *.sl so_locations |
| 286 | |
| 287 | |
| 288 | # Handy target to remove everything you don't want to distribute |
| 289 | distclean: clobber |
| 290 | -rm -f Makefile Setup |