bsd.port.mk revision 2282
1#	bsd.port.mk - 940820 Jordan K. Hubbard.
2#	This file is in the public domain.
3#
4# $Id: bsd.port.mk,v 1.18 1994/08/25 13:56:08 jkh Exp $
5
6#
7# Supported Variables and their behaviors:
8#
9# GMAKE		- Set to path of GNU make if not in $PATH.
10# DISTDIR 	- Where to get gzip'd, tarballed copies of original sources.
11# DISTNAME	- Name of package or distribution.
12# WRKDIR 	- A temporary working directory that gets *clobbered* on clean.
13# WRKSRC	- A subdirectory of ${WRKDIR} where the distribution actually
14#		  unpacks to.  Defaults to ${WRKDIR}/${DISTNAME}.
15# PATCHDIR 	- A directory containing required patches.
16# SCRIPTDIR 	- A directory containing auxilliary scripts.
17# FILESDIR 	- A directory containing any miscellaneous additional files.
18# PKGDIR 	- Package creation files.
19#
20# USE_GMAKE	- Says that the package uses gmake.
21# HAS_CONFIGURE	- Says that the package has its own configure script.
22# CONFIGURE_ARGS - Pass these args to configure, if $HAS_CONFIGURE.
23# HOME_LOCATION	- site/path name (or user's email address) describing
24#		  where this package came from or can be obtained if the
25#		  tarball is missing.
26# DEPENDS	- A list of other packages this package depends on being
27#		  made first.
28# 
29#
30# Default targets and their behaviors:
31#
32# extract	- Unpacks ${DISTDIR}/${DISTNAME}.tar.gz into ${WRKDIR}.
33# configure	- Applys patches, if any, and runs either GNU configure, one
34#		  or more local configure scripts or nothing, depending on
35#		  what's available.
36# build		- Actually compile the sources.
37# install	- Install the results of a build.
38# package	- Create a package from a build.
39# bundle	- From an unextracted source tree, re-create tarballs.
40
41
42.if exists(${.CURDIR}/../Makefile.inc)
43.include "${.CURDIR}/../Makefile.inc"
44.endif
45
46GMAKE?=		gmake
47
48# These need to be absolute since we don't know how deep in the ports
49# tree we are and thus can't go relative.  It can, of course, be overridden
50# by individual Makefiles.
51PORTSDIR?=	/usr/ports
52DISTDIR?=	${PORTSDIR}/distfiles
53PACKAGES?=	${PORTSDIR}/packages
54
55WRKDIR?=	${.CURDIR}/work
56WRKSRC?=	${WRKDIR}/${DISTNAME}
57PATCHDIR?=	${.CURDIR}/patches
58SCRIPTDIR?=	${.CURDIR}/scripts
59FILESDIR?=	${.CURDIR}/files
60PKGDIR?=	${.CURDIR}/pkg
61
62# Change these if you'd prefer to keep the cookies someplace else.
63EXTRACT_COOKIE?=	${.CURDIR}/.extract_done
64CONFIGURE_COOKIE?=	${.CURDIR}/.configure_done
65
66# Miscellaneous overridable commands:
67EXTRACT_CMD?=	tar
68EXTRACT_SUFX?=	.tar.gz
69EXTRACT_ARGS?=	-C ${WRKDIR} -xzf
70
71BUNDLE_CMD?=	tar
72BUNDLE_ARGS?=	-C ${WRKDIR} -czf
73
74PKG_CMD?=	pkg_create
75PKG_ARGS?=	-v -c ${PKGDIR}/COMMENT -d ${PKGDIR}/DESCR -f ${PKGDIR}/PLIST
76PKG_SUFX?=	.tgz
77
78HOME_LOCATION?=	<original site unknown>
79
80.MAIN: all
81all: extract configure build
82
83.if !target(pre-install)
84pre-install:
85	@echo -n
86.endif
87
88.if !target(install)
89install: pre-install
90	@echo "===>  Installing for ${DISTNAME}"
91.if defined(USE_GMAKE)
92	@(cd ${WRKSRC}; ${GMAKE} install)
93.else defined(USE_GMAKE)
94	@(cd ${WRKSRC}; ${MAKE} install)
95.endif
96.endif
97
98.if !target(pre-package)
99pre-package:
100	@echo -n
101.endif
102
103.if !target(package)
104package: pre-package
105# Makes some gross assumptions about a fairly simple package with no
106# install, require or deinstall scripts.  Override the arguments with
107# PKG_ARGS if your package is anything but run-of-the-mill.
108	@if [ -d ${PKGDIR} ]; then \
109	   if [ -d ${PACKAGES} ]; then \
110	   	echo "===>  Building package for ${DISTNAME} in ${PACKAGES}"; \
111		${PKG_CMD} ${PKG_ARGS} ${PACKAGES}/${DISTNAME}${PKG_SUFX}; \
112	   else \
113	   	echo "===>  Building package for ${DISTNAME} in ${.CURDIR}"; \
114	   	${PKG_CMD} ${PKG_ARGS} ${DISTNAME}${PKG_SUFX}; \
115	   fi; \
116	fi
117.endif
118
119.if !target(pre-build)
120pre-build:
121	@echo -n
122.endif
123
124.if !target(build)
125build: configure pre-build
126	@echo "===>  Building for ${DISTNAME}"
127.if defined(DEPENDS)
128	@echo "===>  ${DISTNAME} depends on:  ${DEPENDS}"
129	@for i in $(DEPENDS); do \
130	   echo "===>  Verifying build for $$i"; \
131	   if [ ! -d ${PORTSDIR}/$$i ]; then \
132		echo ">> No directory for ${PORTSDIR}/$$i.  Skipping.."; \
133	   else \
134		(cd ${PORTSDIR}/$$i; ${MAKE}) ; \
135	   fi \
136	done
137	@echo "===>  Returning to build of ${DISTNAME}"
138.endif
139.if defined(USE_GMAKE)
140	@(cd ${WRKSRC}; ${GMAKE} all)
141.else defined(USE_GMAKE)
142	@(cd ${WRKSRC}; ${MAKE} all)
143.endif
144.endif
145
146# No pre-configure stuff since that's handled differently.  We wrap
147# pre-configure and post-configure scripts around what is generally
148# an originally-provided script file, and easier to pre/post install for
149# than change.
150
151.if !target(configure)
152# This is done with a .configure because configures are often expensive,
153# and you don't want it done again gratuitously when you're trying to get
154# a make of the whole tree to work.
155configure: extract ${CONFIGURE_COOKIE}
156
157${CONFIGURE_COOKIE}:
158	@echo "===>  Configuring for ${DISTNAME}"
159	@if [ -d ${PATCHDIR} ]; then \
160	   echo "===>  Applying patches for ${DISTNAME}" ; \
161	   for i in ${PATCHDIR}/patch-*; do \
162		patch -d ${WRKSRC} --quiet -E -p0 < $$i; \
163	   done; \
164	fi
165# We have a small convention for our local configure scripts, which
166# is that ${PORTSDIR}, ${.CURDIR} and ${WRKSRC} get passed as
167# command-line arguments since all other methods are a little
168# problematic.
169	@if [ -f ${SCRIPTDIR}/pre-configure ]; then \
170	   sh ${SCRIPTDIR}/pre-configure ${PORTSDIR} ${.CURDIR} ${WRKSRC}; \
171	fi
172	@if [ -f ${SCRIPTDIR}/configure ]; then \
173	   sh ${SCRIPTDIR}/configure ${PORTSDIR} ${.CURDIR} ${WRKSRC}; \
174	fi
175.if defined(HAS_CONFIGURE)
176	@(cd ${WRKSRC}; ./configure ${CONFIGURE_ARGS})
177.endif
178.if defined(USE_IMAKE)
179	@(cd ${WRKSRC}; xmkmf && make Makefiles)
180.endif
181	@if [ -f ${SCRIPTDIR}/post-configure ]; then \
182	   sh ${SCRIPTDIR}/post-configure ${PORTSDIR} ${.CURDIR} ${WRKSRC}; \
183	fi
184	@touch -f ${CONFIGURE_COOKIE}
185.endif
186
187.if !target(pre-bundle)
188pre-bundle:
189	@echo -n
190.endif
191
192.if !target(bundle)
193bundle: pre-bundle
194	@echo "===>  Bundling for ${DISTNAME}"
195	@if [ ! -f ${EXTRACT_COOKIE} ]; then \
196	   echo ">> There doesn't appear to be a properly extracted"; \
197	   echo ">> distribution for ${DISTNAME}. Skipping.."; \
198	   exit 0; \
199	fi
200	@if [ -f ${CONFIGURE_COOKIE} ]; then \
201	   echo ">> WARNING:  This source has been configured and may"; \
202	   echo ">> produce a tainted distfile!"; \
203	fi
204	${BUNDLE_CMD} ${BUNDLE_ARGS} ${DISTDIR}/${DISTNAME}${EXTRACT_SUFX} \
205		${DISTNAME}
206.endif
207
208.if !target(pre-extract)
209pre-extract:
210	@echo -n
211.endif
212
213.if !target(extract)
214# We need to depend on .extract_done rather than the presence of ${WRKDIR}
215# because if the user interrupts the extract in the middle (and it's often
216# a long procedure), we get tricked into thinking that we've got a good dist
217# in ${WRKDIR}.
218extract: pre-extract ${EXTRACT_COOKIE}
219
220${EXTRACT_COOKIE}:
221	@echo "===>  Extracting for ${DISTNAME}"
222	@rm -rf ${WRKDIR}
223	@mkdir -p ${WRKDIR}
224	@if [ ! -f ${DISTDIR}/${DISTNAME}${EXTRACT_SUFX} ]; then \
225	   echo ">> Sorry, can't find: ${DISTDIR}/${DISTNAME}${EXTRACT_SUFX}"; \
226	   echo ">> Please obtain this file from:"; \
227	   echo ">>	${HOME_LOCATION}"; \
228	   echo ">>before proceeding."; \
229	   exit 1; \
230	fi
231	@${EXTRACT_CMD} ${EXTRACT_ARGS} ${DISTDIR}/${DISTNAME}${EXTRACT_SUFX}
232	@touch -f ${EXTRACT_COOKIE}
233.endif
234
235# No pre-targets for clean, depend or tags.  It would be silly.
236
237.if !target(clean)
238clean:
239	@echo "===>  Cleaning for ${DISTNAME}"
240	@rm -f ${EXTRACT_COOKIE} ${CONFIGURE_COOKIE}
241	@rm -rf ${WRKDIR}
242.endif
243
244# Depend is generally meaningless for arbitrary ports, but if someone wants
245# one they can override this.  This is just to catch people who've gotten into
246# the habit of typing `make depend all install' as a matter of course.
247#
248.if !target(depend)
249depend:
250.endif
251
252# Same goes for tags
253.if !target(tags)
254tags:
255.endif
256