# Sample Makefile to build an extended version of Python.
#
# Instructions:
#
# 0) Build and install the basic Python 1.0.1 distribution.  You must
# also install the headers ("make inclinstall") and the binary library
# files ("make libainstall").  If you use Python 1.0.0 you must 
# manually copy Modules/Setup and Modules/config.c.in as well.
#
# 1) Edit Makefile.pre.in (not any other file!!!) to change the
# definition of installdir and possibly exec_installdir.  These should
# match the prefix and exec_prefix used when installing Python.
#
# 2) Copy Setup.in to Setup and edit Setup to change the selection of
# modules you want to use.  Read the comments in Setup for more
# detailed instructions.
#
# 3) Run "make Makefile -f Makefile.pre.in".  This creates Makefile
# (producing Makefile.pre and sedscript as intermediate files) and
# config.c.
#
# 4) Run "make".  This creates a Python executable.  The set of
# built-in modules and features is a superset of that of the basic
# Python -- additions are taken from ./Setup.
#
# Note -- if you don't actually want to install the Python headers and
# binary library files, you can edit the "Fixed definitions" section
# below to point directly into the source and/or build tree.

# === Variables that you just *have* to customize manually ===

# The prefix used by "make inclinstall libainstall" of core python
installdir=	/usr/local

# The exec_prefix used by the same
exec_installdir=$(installdir)

# Source directory and VPATH in case you want to use VPATH.
# (You will have to edit these two lines yourself -- there is no
# automatic support as the Makefile is not generated by
# config.status.)
srcdir=		.
VPATH=		.

# === Variables that you may want to customize ===

# Add possible -L options here
LINKPATH=	

# You may want to change this to -O
OPT=		-g

# Add more -I and -D options here
CFLAGS=		$(OPT) -I$(INCLUDEPY) -I$(LIBPL) $(DEFS)

# === Variables set by makesetup ===

MODOBJS=	@MODOBJS@
MODLIBS=	@MODLIBS@

# === Definitions added by makesetup ===

# === Variables from configure (through sedscript) ===

DEFS=		@DEFS@
LIBS=		@LIBS@
LIBM=		@LIBM@
LIBC=		@LIBC@

# Install prefix for architecture-independent files
prefix=		/usr/local

# Install prefix for architecture-dependent files
exec_prefix=	$(prefix)

# === Fixed definitions ===

INCLUDEPY=	$(installdir)/include/Py
LIBP=		$(exec_installdir)/lib/python
LIBPL=		$(LIBP)/lib

PYTHONLIBS=	$(LIBPL)/libModules.a \
		$(LIBPL)/libPython.a \
		$(LIBPL)/libObjects.a \
		$(LIBPL)/libParser.a

# Edit these two variables to merge extensions -- see example[23]
BASELIB=	
BASESETUP=	

# XXX Ideally we would use the makesetup script from $(LIBPL) but
# XXX there's a last-minute bugfix that didn't make it to the 1.0.1
# XXX distribution so we use the one from Extensions.
MAKESETUP=	$(srcdir)/../makesetup
MAKEFILE=	$(LIBPL)/Makefile
CONFIGC=	$(LIBPL)/config.c
CONFIGCIN=	$(LIBPL)/config.c.in
SETUP=		$(LIBPL)/Setup

SYSLIBS=	$(LIBM) $(LIBC)

# === Fixed rules ===

all:		python

python:		config.o lib.a $(PYTHONLIBS) Makefile
		$(CC) config.o lib.a $(PYTHONLIBS) \
		 $(LINKPATH) $(BASELIB) $(MODLIBS) $(LIBS) $(SYSLIBS) -o python

lib.a:		$(MODOBJS)
		ar cr lib.a $(MODOBJS)

config.c Makefile:	Makefile.pre Setup $(BASESETUP) $(MAKESETUP)
		$(MAKESETUP) \
		 -m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP)

config.o:	config.c Makefile
		$(CC) $(CFLAGS) -DPYTHONPATH=\"$(PYTHONPATH)\" -c config.c

# Setup is copied from Setup.in *only* if it doesn't yet exist
Setup:
		cp $(srcdir)/Setup.in Setup

Makefile.pre: Makefile.pre.in sedscript
		sed -f sedscript Makefile.pre.in >Makefile.pre

# Shortcuts to make the sed arguments on one line
P=prefix
E=exec_prefix
H=Generated automatically from Makefile.pre.in by sedscript.
sedscript:	$(MAKEFILE)
		sed -n \
		  -e '1s/.*/1i\\/p' \
		  -e '2s/.*/# $H/p' \
		  -e '/^DEFS=/s/^DEFS=[ 	]*\(.*\)/s%@DEFS[@]%\1%/p' \
		  -e '/^LIBS=/s/^LIBS=[ 	]*\(.*\)/s%@LIBS[@]%\1%/p' \
		  -e '/^LIBM=/s/^LIBM=[ 	]*\(.*\)/s%@LIBM[@]%\1%/p' \
		  -e '/^LIBC=/s/^LIBC=[ 	]*\(.*\)/s%@LIBC[@]%\1%/p' \
		  -e '/^$P=/s/^$P=\(.*\)/s%^$P=.*%$P=\1%/p' \
		  -e '/^$E=/s/^$E=\(.*\)/s%^$E=.*%$E=\1%/p' \
		  $(MAKEFILE) >sedscript

clean:
		-rm -f *.o *~

clobber:	clean
		-rm -f python lib.a sedscript config.c Makefile.pre

distclean:	clobber
		-rm -f Makefile Setup

# === Rules added by makesetup ===

# DO NOT DELETE THIS LINE -- mkdep uses it.
# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
