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 | |
| 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 |
| 72 | installdir= /usr/local |
| 73 | |
| 74 | # The exec_prefix used by the same |
| 75 | exec_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.) |
| 81 | srcdir= . |
| 82 | VPATH= . |
| 83 | |
| 84 | # === Variables that you may want to customize (rarely) === |
| 85 | |
Guido van Rossum | 434882e | 1996-10-08 17:21:11 +0000 | [diff] [blame] | 86 | # (Static) build target |
| 87 | TARGET= python |
| 88 | |
Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 89 | # Add more -I and -D options here |
| 90 | CFLAGS= $(OPT) -I$(INCLUDEPY) -I$(LIBPL) $(DEFS) |
| 91 | |
| 92 | # These two variables can be set in Setup to merge extensions. |
| 93 | # See example[23]. |
| 94 | BASELIB= |
| 95 | BASESETUP= |
| 96 | |
| 97 | # === Variables set by makesetup === |
| 98 | |
| 99 | MODOBJS= _MODOBJS_ |
| 100 | MODLIBS= _MODLIBS_ |
| 101 | |
| 102 | # === Definitions added by makesetup === |
| 103 | |
| 104 | # === Variables from configure (through sedscript) === |
| 105 | |
| 106 | VERSION= @VERSION@ |
| 107 | CC= @CC@ |
| 108 | OPT= @OPT@ |
| 109 | LDFLAGS= @LDFLAGS@ |
| 110 | DEFS= @DEFS@ |
| 111 | LIBS= @LIBS@ |
| 112 | LIBM= @LIBM@ |
| 113 | LIBC= @LIBC@ |
| 114 | RANLIB= @RANLIB@ |
| 115 | MACHDEP= @MACHDEP@ |
| 116 | SO= @SO@ |
| 117 | LDSHARED= @LDSHARED@ |
| 118 | CCSHARED= @CCSHARED@ |
| 119 | LINKFORSHARED= @LINKFORSHARED@ |
| 120 | |
| 121 | # Install prefix for architecture-independent files |
| 122 | prefix= /usr/local |
| 123 | |
| 124 | # Install prefix for architecture-dependent files |
| 125 | exec_prefix= $(prefix) |
| 126 | |
| 127 | # === Fixed definitions === |
| 128 | |
Guido van Rossum | b0259bc | 1996-10-24 21:47:45 +0000 | [diff] [blame^] | 129 | # Shell used by make (some versions default to the login shell, which is bad) |
| 130 | SHELL= /bin/sh |
| 131 | |
Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 132 | # Expanded directories |
| 133 | BINDIR= $(exec_installdir)/bin |
| 134 | LIBDIR= $(exec_prefix)/lib |
| 135 | MANDIR= $(installdir)/man |
| 136 | INCLUDEDIR= $(installdir)/include |
| 137 | SCRIPTDIR= $(prefix)/lib |
| 138 | |
| 139 | # Detailed destination directories |
| 140 | BINLIBDEST= $(LIBDIR)/python$(VERSION) |
| 141 | LIBDEST= $(SCRIPTDIR)/python$(VERSION) |
| 142 | INCLUDEPY= $(INCLUDEDIR)/python$(VERSION) |
| 143 | LIBP= $(exec_installdir)/lib/python$(VERSION) |
| 144 | |
| 145 | LIBPL= $(LIBP)/config |
| 146 | |
| 147 | PYTHONLIBS= $(LIBPL)/libModules.a \ |
| 148 | $(LIBPL)/libPython.a \ |
| 149 | $(LIBPL)/libObjects.a \ |
| 150 | $(LIBPL)/libParser.a |
| 151 | |
| 152 | MAKESETUP= $(LIBPL)/makesetup |
| 153 | MAKEFILE= $(LIBPL)/Makefile |
| 154 | CONFIGC= $(LIBPL)/config.c |
| 155 | CONFIGCIN= $(LIBPL)/config.c.in |
| 156 | SETUP= $(LIBPL)/Setup |
| 157 | |
| 158 | SYSLIBS= $(LIBM) $(LIBC) |
| 159 | |
| 160 | ADDOBJS= $(LIBPL)/main.o getpath.o config.o |
| 161 | |
| 162 | # === Fixed rules === |
| 163 | |
| 164 | # Default target. This builds shared libraries only |
| 165 | default: sharedmods |
| 166 | |
| 167 | # Build everything |
Guido van Rossum | 434882e | 1996-10-08 17:21:11 +0000 | [diff] [blame] | 168 | all: static sharedmods |
Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 169 | |
| 170 | # Build shared libraries from our extension modules |
| 171 | sharedmods: $(SHAREDMODS) |
| 172 | |
| 173 | # Build a static Python binary containing our extension modules |
Guido van Rossum | 434882e | 1996-10-08 17:21:11 +0000 | [diff] [blame] | 174 | static: $(TARGET) |
| 175 | $(TARGET): $(ADDOBJS) lib.a $(PYTHONLIBS) Makefile $(BASELIB) |
Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 176 | $(CC) $(LDFLAGS) $(ADDOBJS) lib.a $(PYTHONLIBS) \ |
Guido van Rossum | 434882e | 1996-10-08 17:21:11 +0000 | [diff] [blame] | 177 | $(LINKPATH) $(BASELIB) $(MODLIBS) $(LIBS) $(SYSLIBS) \ |
| 178 | -o $(TARGET) |
Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 179 | |
| 180 | # Build the library containing our extension modules |
| 181 | lib.a: $(MODOBJS) |
| 182 | -rm -f lib.a |
| 183 | ar cr lib.a $(MODOBJS) |
| 184 | -$(RANLIB) lib.a || \ |
| 185 | echo "don't worry if ranlib fails -- probably SYSV or equiv" |
| 186 | |
| 187 | # This runs makesetup *twice* to use the BASESETUP definition from Setup |
| 188 | config.c Makefile: Makefile.pre Setup $(BASESETUP) $(MAKESETUP) |
| 189 | $(MAKESETUP) \ |
| 190 | -m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP) |
| 191 | $(MAKE) -f Makefile do-it-again |
| 192 | |
| 193 | # Internal target to run makesetup for the second time |
| 194 | do-it-again: |
| 195 | $(MAKESETUP) \ |
| 196 | -m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP) |
| 197 | |
| 198 | # Make config.o from the config.c created by makesetup |
| 199 | config.o: config.c |
| 200 | $(CC) $(CFLAGS) -c config.c |
| 201 | |
| 202 | # Make our own private getpath.o from the installed source and our PYTHONPATH |
| 203 | getpath.o: $(LIBPL)/getpath.c Makefile |
| 204 | $(CC) $(CFLAGS) -DPYTHONPATH=\"$(PYTHONPATH)\" -c $(LIBPL)/getpath.c |
| 205 | |
| 206 | # Setup is copied from Setup.in *only* if it doesn't yet exist |
| 207 | Setup: |
| 208 | cp $(srcdir)/Setup.in Setup |
| 209 | |
| 210 | # Make the intermediate Makefile.pre from Makefile.pre.in |
| 211 | Makefile.pre: Makefile.pre.in sedscript |
| 212 | sed -f sedscript $(srcdir)/Makefile.pre.in >Makefile.pre |
| 213 | |
| 214 | # Shortcuts to make the sed arguments on one line |
| 215 | P=prefix |
| 216 | E=exec_prefix |
| 217 | H=Generated automatically from Makefile.pre.in by sedscript. |
| 218 | L=LINKFORSHARED |
| 219 | |
| 220 | # Make the sed script used to create Makefile.pre from Makefile.pre.in |
| 221 | sedscript: $(MAKEFILE) |
| 222 | sed -n \ |
| 223 | -e '1s/.*/1i\\/p' \ |
| 224 | -e '2s%.*%# $H%p' \ |
| 225 | -e '/^VERSION=/s/^VERSION=[ ]*\(.*\)/s%@VERSION[@]%\1%/p' \ |
| 226 | -e '/^CC=/s/^CC=[ ]*\(.*\)/s%@CC[@]%\1%/p' \ |
| 227 | -e '/^OPT=/s/^OPT=[ ]*\(.*\)/s%@OPT[@]%\1%/p' \ |
| 228 | -e '/^LDFLAGS=/s/^LDFLAGS=[ ]*\(.*\)/s%@LDFLAGS[@]%\1%/p' \ |
| 229 | -e '/^DEFS=/s/^DEFS=[ ]*\(.*\)/s%@DEFS[@]%\1%/p' \ |
| 230 | -e '/^LIBS=/s/^LIBS=[ ]*\(.*\)/s%@LIBS[@]%\1%/p' \ |
| 231 | -e '/^LIBM=/s/^LIBM=[ ]*\(.*\)/s%@LIBM[@]%\1%/p' \ |
| 232 | -e '/^LIBC=/s/^LIBC=[ ]*\(.*\)/s%@LIBC[@]%\1%/p' \ |
| 233 | -e '/^RANLIB=/s/^RANLIB=[ ]*\(.*\)/s%@RANLIB[@]%\1%/p' \ |
| 234 | -e '/^MACHDEP=/s/^MACHDEP=[ ]*\(.*\)/s%@MACHDEP[@]%\1%/p' \ |
| 235 | -e '/^SO=/s/^SO=[ ]*\(.*\)/s%@SO[@]%\1%/p' \ |
| 236 | -e '/^LDSHARED=/s/^LDSHARED=[ ]*\(.*\)/s%@LDSHARED[@]%\1%/p' \ |
| 237 | -e '/^CCSHARED=/s/^CCSHARED=[ ]*\(.*\)/s%@CCSHARED[@]%\1%/p' \ |
| 238 | -e '/^$L=/s/^$L=[ ]*\(.*\)/s%@$L[@]%\1%/p' \ |
| 239 | -e '/^$P=/s/^$P=\(.*\)/s%^$P=.*%$P=\1%/p' \ |
| 240 | -e '/^$E=/s/^$E=\(.*\)/s%^$E=.*%$E=\1%/p' \ |
| 241 | $(MAKEFILE) >sedscript |
| 242 | echo "/^installdir=/s%=.*%= $(installdir)%" >>sedscript |
| 243 | echo "/^exec_installdir=/s%=.*%=$(exec_installdir)%" >>sedscript |
| 244 | echo "/^srcdir=/s%=.*%= $(srcdir)%" >>sedscript |
| 245 | echo "/^VPATH=/s%=.*%= $(VPATH)%" >>sedscript |
| 246 | echo "/^LINKPATH=/s%=.*%= $(LINKPATH)%" >>sedscript |
| 247 | echo "/^BASELIB=/s%=.*%= $(BASELIB)%" >>sedscript |
| 248 | echo "/^BASESETUP=/s%=.*%= $(BASESETUP)%" >>sedscript |
| 249 | |
| 250 | # Bootstrap target |
Guido van Rossum | 43e6661 | 1996-10-10 19:12:47 +0000 | [diff] [blame] | 251 | boot: clobber |
Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 252 | VERSION=`python -c "import sys; print sys.version[:3]"`; \ |
| 253 | installdir=`python -c "import sys; print sys.prefix"`; \ |
| 254 | exec_installdir=`python -c "import sys; print sys.exec_prefix"`; \ |
Guido van Rossum | 946cf89 | 1996-09-11 12:15:07 +0000 | [diff] [blame] | 255 | $(MAKE) -f $(srcdir)/Makefile.pre.in VPATH=$(VPATH) srcdir=$(srcdir) \ |
Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 256 | VERSION=$$VERSION \ |
| 257 | installdir=$$installdir \ |
Guido van Rossum | 946cf89 | 1996-09-11 12:15:07 +0000 | [diff] [blame] | 258 | exec_installdir=$$exec_installdir \ |
| 259 | Makefile |
Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 260 | |
| 261 | # Handy target to remove intermediate files and backups |
| 262 | clean: |
| 263 | -rm -f *.o *~ |
| 264 | |
| 265 | # Handy target to remove everything that is easily regenerated |
| 266 | clobber: clean |
| 267 | -rm -f *.a tags TAGS config.c Makefile.pre python sedscript |
| 268 | -rm -f *.so *.sl so_locations |
| 269 | |
| 270 | |
| 271 | # Handy target to remove everything you don't want to distribute |
| 272 | distclean: clobber |
| 273 | -rm -f Makefile Setup |