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 | |
| 129 | # Expanded directories |
| 130 | BINDIR= $(exec_installdir)/bin |
| 131 | LIBDIR= $(exec_prefix)/lib |
| 132 | MANDIR= $(installdir)/man |
| 133 | INCLUDEDIR= $(installdir)/include |
| 134 | SCRIPTDIR= $(prefix)/lib |
| 135 | |
| 136 | # Detailed destination directories |
| 137 | BINLIBDEST= $(LIBDIR)/python$(VERSION) |
| 138 | LIBDEST= $(SCRIPTDIR)/python$(VERSION) |
| 139 | INCLUDEPY= $(INCLUDEDIR)/python$(VERSION) |
| 140 | LIBP= $(exec_installdir)/lib/python$(VERSION) |
| 141 | |
| 142 | LIBPL= $(LIBP)/config |
| 143 | |
| 144 | PYTHONLIBS= $(LIBPL)/libModules.a \ |
| 145 | $(LIBPL)/libPython.a \ |
| 146 | $(LIBPL)/libObjects.a \ |
| 147 | $(LIBPL)/libParser.a |
| 148 | |
| 149 | MAKESETUP= $(LIBPL)/makesetup |
| 150 | MAKEFILE= $(LIBPL)/Makefile |
| 151 | CONFIGC= $(LIBPL)/config.c |
| 152 | CONFIGCIN= $(LIBPL)/config.c.in |
| 153 | SETUP= $(LIBPL)/Setup |
| 154 | |
| 155 | SYSLIBS= $(LIBM) $(LIBC) |
| 156 | |
| 157 | ADDOBJS= $(LIBPL)/main.o getpath.o config.o |
| 158 | |
| 159 | # === Fixed rules === |
| 160 | |
| 161 | # Default target. This builds shared libraries only |
| 162 | default: sharedmods |
| 163 | |
| 164 | # Build everything |
Guido van Rossum | 434882e | 1996-10-08 17:21:11 +0000 | [diff] [blame^] | 165 | all: static sharedmods |
Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 166 | |
| 167 | # Build shared libraries from our extension modules |
| 168 | sharedmods: $(SHAREDMODS) |
| 169 | |
| 170 | # Build a static Python binary containing our extension modules |
Guido van Rossum | 434882e | 1996-10-08 17:21:11 +0000 | [diff] [blame^] | 171 | static: $(TARGET) |
| 172 | $(TARGET): $(ADDOBJS) lib.a $(PYTHONLIBS) Makefile $(BASELIB) |
Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 173 | $(CC) $(LDFLAGS) $(ADDOBJS) lib.a $(PYTHONLIBS) \ |
Guido van Rossum | 434882e | 1996-10-08 17:21:11 +0000 | [diff] [blame^] | 174 | $(LINKPATH) $(BASELIB) $(MODLIBS) $(LIBS) $(SYSLIBS) \ |
| 175 | -o $(TARGET) |
Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 176 | |
| 177 | # Build the library containing our extension modules |
| 178 | lib.a: $(MODOBJS) |
| 179 | -rm -f lib.a |
| 180 | ar cr lib.a $(MODOBJS) |
| 181 | -$(RANLIB) lib.a || \ |
| 182 | echo "don't worry if ranlib fails -- probably SYSV or equiv" |
| 183 | |
| 184 | # This runs makesetup *twice* to use the BASESETUP definition from Setup |
| 185 | config.c Makefile: Makefile.pre Setup $(BASESETUP) $(MAKESETUP) |
| 186 | $(MAKESETUP) \ |
| 187 | -m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP) |
| 188 | $(MAKE) -f Makefile do-it-again |
| 189 | |
| 190 | # Internal target to run makesetup for the second time |
| 191 | do-it-again: |
| 192 | $(MAKESETUP) \ |
| 193 | -m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP) |
| 194 | |
| 195 | # Make config.o from the config.c created by makesetup |
| 196 | config.o: config.c |
| 197 | $(CC) $(CFLAGS) -c config.c |
| 198 | |
| 199 | # Make our own private getpath.o from the installed source and our PYTHONPATH |
| 200 | getpath.o: $(LIBPL)/getpath.c Makefile |
| 201 | $(CC) $(CFLAGS) -DPYTHONPATH=\"$(PYTHONPATH)\" -c $(LIBPL)/getpath.c |
| 202 | |
| 203 | # Setup is copied from Setup.in *only* if it doesn't yet exist |
| 204 | Setup: |
| 205 | cp $(srcdir)/Setup.in Setup |
| 206 | |
| 207 | # Make the intermediate Makefile.pre from Makefile.pre.in |
| 208 | Makefile.pre: Makefile.pre.in sedscript |
| 209 | sed -f sedscript $(srcdir)/Makefile.pre.in >Makefile.pre |
| 210 | |
| 211 | # Shortcuts to make the sed arguments on one line |
| 212 | P=prefix |
| 213 | E=exec_prefix |
| 214 | H=Generated automatically from Makefile.pre.in by sedscript. |
| 215 | L=LINKFORSHARED |
| 216 | |
| 217 | # Make the sed script used to create Makefile.pre from Makefile.pre.in |
| 218 | sedscript: $(MAKEFILE) |
| 219 | sed -n \ |
| 220 | -e '1s/.*/1i\\/p' \ |
| 221 | -e '2s%.*%# $H%p' \ |
| 222 | -e '/^VERSION=/s/^VERSION=[ ]*\(.*\)/s%@VERSION[@]%\1%/p' \ |
| 223 | -e '/^CC=/s/^CC=[ ]*\(.*\)/s%@CC[@]%\1%/p' \ |
| 224 | -e '/^OPT=/s/^OPT=[ ]*\(.*\)/s%@OPT[@]%\1%/p' \ |
| 225 | -e '/^LDFLAGS=/s/^LDFLAGS=[ ]*\(.*\)/s%@LDFLAGS[@]%\1%/p' \ |
| 226 | -e '/^DEFS=/s/^DEFS=[ ]*\(.*\)/s%@DEFS[@]%\1%/p' \ |
| 227 | -e '/^LIBS=/s/^LIBS=[ ]*\(.*\)/s%@LIBS[@]%\1%/p' \ |
| 228 | -e '/^LIBM=/s/^LIBM=[ ]*\(.*\)/s%@LIBM[@]%\1%/p' \ |
| 229 | -e '/^LIBC=/s/^LIBC=[ ]*\(.*\)/s%@LIBC[@]%\1%/p' \ |
| 230 | -e '/^RANLIB=/s/^RANLIB=[ ]*\(.*\)/s%@RANLIB[@]%\1%/p' \ |
| 231 | -e '/^MACHDEP=/s/^MACHDEP=[ ]*\(.*\)/s%@MACHDEP[@]%\1%/p' \ |
| 232 | -e '/^SO=/s/^SO=[ ]*\(.*\)/s%@SO[@]%\1%/p' \ |
| 233 | -e '/^LDSHARED=/s/^LDSHARED=[ ]*\(.*\)/s%@LDSHARED[@]%\1%/p' \ |
| 234 | -e '/^CCSHARED=/s/^CCSHARED=[ ]*\(.*\)/s%@CCSHARED[@]%\1%/p' \ |
| 235 | -e '/^$L=/s/^$L=[ ]*\(.*\)/s%@$L[@]%\1%/p' \ |
| 236 | -e '/^$P=/s/^$P=\(.*\)/s%^$P=.*%$P=\1%/p' \ |
| 237 | -e '/^$E=/s/^$E=\(.*\)/s%^$E=.*%$E=\1%/p' \ |
| 238 | $(MAKEFILE) >sedscript |
| 239 | echo "/^installdir=/s%=.*%= $(installdir)%" >>sedscript |
| 240 | echo "/^exec_installdir=/s%=.*%=$(exec_installdir)%" >>sedscript |
| 241 | echo "/^srcdir=/s%=.*%= $(srcdir)%" >>sedscript |
| 242 | echo "/^VPATH=/s%=.*%= $(VPATH)%" >>sedscript |
| 243 | echo "/^LINKPATH=/s%=.*%= $(LINKPATH)%" >>sedscript |
| 244 | echo "/^BASELIB=/s%=.*%= $(BASELIB)%" >>sedscript |
| 245 | echo "/^BASESETUP=/s%=.*%= $(BASESETUP)%" >>sedscript |
| 246 | |
| 247 | # Bootstrap target |
| 248 | boot: |
| 249 | VERSION=`python -c "import sys; print sys.version[:3]"`; \ |
| 250 | installdir=`python -c "import sys; print sys.prefix"`; \ |
| 251 | exec_installdir=`python -c "import sys; print sys.exec_prefix"`; \ |
Guido van Rossum | 946cf89 | 1996-09-11 12:15:07 +0000 | [diff] [blame] | 252 | $(MAKE) -f $(srcdir)/Makefile.pre.in VPATH=$(VPATH) srcdir=$(srcdir) \ |
Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 253 | VERSION=$$VERSION \ |
| 254 | installdir=$$installdir \ |
Guido van Rossum | 946cf89 | 1996-09-11 12:15:07 +0000 | [diff] [blame] | 255 | exec_installdir=$$exec_installdir \ |
| 256 | Makefile |
Guido van Rossum | 1631cbe | 1996-09-10 18:19:23 +0000 | [diff] [blame] | 257 | |
| 258 | # Handy target to remove intermediate files and backups |
| 259 | clean: |
| 260 | -rm -f *.o *~ |
| 261 | |
| 262 | # Handy target to remove everything that is easily regenerated |
| 263 | clobber: clean |
| 264 | -rm -f *.a tags TAGS config.c Makefile.pre python sedscript |
| 265 | -rm -f *.so *.sl so_locations |
| 266 | |
| 267 | |
| 268 | # Handy target to remove everything you don't want to distribute |
| 269 | distclean: clobber |
| 270 | -rm -f Makefile Setup |