bsd.port.mk revision 4122
1# -*- mode: Fundamental; tab-width: 4; -*-
2#
3#	bsd.port.mk - 940820 Jordan K. Hubbard.
4#	This file is in the public domain.
5#
6# $Id: bsd.port.mk,v 1.63 1994/11/03 19:14:08 jkh Exp $
7#
8# Please view me with 4 column tabs!
9
10
11# Supported Variables and their behaviors:
12#
13# Variables that typically apply to all ports:
14# 
15# PORTSDIR		- The root of the ports tree (default: /usr/ports).
16# DISTDIR 		- Where to get gzip'd, tarballed copies of original sources
17#				  (default: ${PORTSDIR}/distfiles).
18# PREFIX		- Where to install things in general (default: /usr/local).
19# MASTER_SITES	- Primary location(s) for distribution files if not found
20#				  locally.
21# PACKAGES		- A top level directory where all packages go (rather than
22#				  going locally to each port). (default: ${PORTSDIR}/packages).
23# GMAKE			- Set to path of GNU make if not in $PATH (default: gmake).
24# XMKMF			- Set to path of `xmkmf' if not in $PATH (default: xmkmf).
25#
26# Variables that typically apply to an individual port:
27#
28# WRKDIR 		- A temporary working directory that gets *clobbered* on clean.
29# WRKSRC		- A subdirectory of ${WRKDIR} where the distribution actually
30#				  unpacks to.  (Default: ${WRKDIR}/${DISTNAME} unless
31#				  NO_WRKSUBDIR is set, in which case simply ${WRKDIR}).
32# DISTNAME		- Name of port or distribution.
33# DISTFILES		- Name(s) of archive file(s) containing distribution
34#				  (default: ${DISTDIR}/${DISTNAME}${EXTRACT_SUFX}).
35# EXTRACT_ONLY		- If defined, a subset of ${DISTFILES} you want to
36#			  	actually extract.
37# PATCHDIR 		- A directory containing any required patches.
38# SCRIPTDIR 	- A directory containing any auxilliary scripts.
39# FILESDIR 		- A directory containing any miscellaneous additional files.
40# PKGDIR 		- A direction containing any package creation files.
41#
42# NO_EXTRACT	- Use a dummy (do-nothing) extract target.
43# NO_CONFIGURE	- Use a dummy (do-nothing) configure target.
44# NO_BUILD		- Use a dummy (do-nothing) build target.
45# NO_PACKAGE	- Use a dummy (do-nothing) package target.
46# NO_INSTALL	- Use a dummy (do-nothing) install target.
47# NO_WRKSUBDIR	- Assume port unpacks directly into ${WRKDIR}.
48# NO_DEPENDS	- Don't verify build of dependencies.
49# USE_GMAKE		- Says that the port uses gmake.
50# USE_IMAKE		- Says that the port uses imake.
51# HAS_CONFIGURE	- Says that the port has its own configure script.
52# GNU_CONFIGURE	- Set if you are using GNU configure (optional).
53# CONFIGURE_ARGS - Pass these args to configure, if $HAS_CONFIGURE.
54# IS_INTERACTIVE - Set this if your port needs to interact with the user
55#				during a build.  User can then decide to skip this port by
56#				setting BATCH, or compile ONLY interactive ports by setting
57#				INTERACTIVE.
58# DEPENDS		- A list of other ports this package depends on being
59#				  made first, relative to ${PORTSDIR} (e.g. x11/tk, lang/tcl,
60#				  etc).
61# EXTRACT_CMD	- Command for extracting archive (default: tar).
62# EXTRACT_SUFX	- Suffix for archive names (default: .tar.gz).
63# EXTRACT_ARGS	- Arguments to ${EXTRACT_CMD} (default: -C ${WRKDIR} -xzf).
64#
65# NCFTP			- Full path to ncftp command if not in $PATH (default: ncftp).
66# NCFTP_ARGS	- Arguments to ${NCFTP} (default: -N).
67#
68#
69# Default targets and their behaviors:
70#
71# fetch			- Retrieves ${DISTFILES} into ${DISTDIR} as necessary.
72# extract		- Unpacks ${DISTFILES} into ${WRKDIR}.
73# configure		- Applies patches, if any, and runs either GNU configure, one
74#				  or more local configure scripts or nothing, depending on
75#				  what's available.
76# build			- Actually compile the sources.
77# install		- Install the results of a build.
78# reinstall		- Install the results of a build, ignoring "already installed"
79#				  flag.
80# package		- Create a package from a build.
81#
82# Default sequence for "all" is:  fetch extract configure build
83
84.if exists(${.CURDIR}/../Makefile.inc)
85.include "${.CURDIR}/../Makefile.inc"
86.endif
87
88# These need to be absolute since we don't know how deep in the ports
89# tree we are and thus can't go relative.  They can, of course, be overridden
90# by individual Makefiles.
91PORTSDIR?=		${DESTDIR}/usr/ports
92PREFIX?=		/usr/local
93DISTDIR?=		${PORTSDIR}/distfiles
94PACKAGES?=		${PORTSDIR}/packages
95WRKDIR?=		${.CURDIR}/work
96.if defined(NO_WRKSUBDIR)
97WRKSRC?=		${WRKDIR}
98.else
99WRKSRC?=		${WRKDIR}/${DISTNAME}
100.endif
101PATCHDIR?=		${.CURDIR}/patches
102SCRIPTDIR?=		${.CURDIR}/scripts
103FILESDIR?=		${.CURDIR}/files
104PKGDIR?=		${.CURDIR}/pkg
105
106.if exists(${PORTSDIR}/../Makefile.inc)
107.include "${PORTSDIR}/../Makefile.inc"
108.endif
109
110
111# Change these if you'd prefer to keep the cookies someplace else.
112EXTRACT_COOKIE?=	${WRKDIR}/.extract_done
113CONFIGURE_COOKIE?=	${WRKDIR}/.configure_done
114INSTALL_COOKIE?=	${WRKDIR}/.install_done
115BUILD_COOKIE?=		${WRKDIR}/.build_done
116
117# How to do nothing.  Override if you, for some strange reason, would rather
118# do something.
119DO_NADA?=		echo -n
120
121# Miscellaneous overridable commands:
122GMAKE?=			gmake
123XMKMF?=			xmkmf
124MAKE_FLAGS?=	-f
125MAKEFILE?=		Makefile
126
127NCFTP?=			ncftp
128NCFTPFLAGS?=	-N
129
130TOUCH?=			touch
131TOUCH_FLAGS?=	-f
132
133PATCH?=			patch
134PATCH_STRIP?=	-p0
135PATCH_ARGS?=	 -d ${WRKSRC} --quiet -E ${PATCH_STRIP}
136
137EXTRACT_CMD?=	tar
138EXTRACT_SUFX?=	.tar.gz
139EXTRACT_ARGS?=	-C ${WRKDIR} -xzf
140
141PKG_CMD?=		pkg_create
142PKG_ARGS?=		-v -c ${PKGDIR}/COMMENT -d ${PKGDIR}/DESCR -f ${PKGDIR}/PLIST -p ${PREFIX}
143PKG_SUFX?=		.tgz
144
145ALL_TARGET?=		all
146INSTALL_TARGET?=	install
147
148# I guess we're in the master distribution business! :)  As we gain mirror
149# sites for distfiles, add them to this list.
150MASTER_SITES+=	ftp://freebsd.cdrom.com/pub/FreeBSD/FreeBSD-current/ports/distfiles/
151
152# Derived names so that they're easily overridable.
153DISTFILES?=		${DISTNAME}${EXTRACT_SUFX}
154
155.if exists(${PACKAGES})
156PKGFILE?=		${PACKAGES}/${DISTNAME}${PKG_SUFX}
157.else
158PKGFILE?=		${DISTNAME}${PKG_SUFX}
159.endif
160
161.if defined(GNU_CONFIGURE)
162CONFIGURE_ARGS?=	--prefix=${PREFIX}
163HAS_CONFIGURE=		yes
164.endif
165
166.MAIN: all
167
168# If we're in BATCH mode and the port is interactive, or we're in
169# interactive mode and the port is non-interactive, skip all the important
170# targets.  The reason we have two modes is that one might want to leave
171# a build in BATCH mode running overnight, then come back in the morning
172# and do _only_ the interactive ones that required your intervention.
173# This allows you to do both.
174#
175.if (defined(IS_INTERACTIVE) && defined(BATCH)) || (!defined(IS_INTERACTIVE) && defined(INTERACTIVE))
176all:
177	@${DO_NADA}
178pre-build:
179	@${DO_NADA}
180build:
181	@${DO_NADA}
182pre-install:
183	@${DO_NADA}
184install:
185	@${DO_NADA}
186pre-fetch:
187	@${DO_NADA}
188fetch:
189	@${DO_NADA}
190pre-configure:
191	@${DO_NADA}
192configure:
193	@${DO_NADA}
194.endif
195
196.if !target(all)
197all: extract configure build
198.endif
199
200.if !target(is_depended)
201is_depended:	all install
202.endif
203
204# The following are used to create easy dummy targets for disabling some
205# bit of default target behavior you don't want.  They still check to see
206# if the target exists, and if so don't do anything, since you might want
207# to set this globally for a group of ports in a Makefile.inc, but still
208# be able to override from an individual Makefile (since you can't _undefine_
209# a variable in make!).
210.if defined(NO_EXTRACT) && !target(extract)
211extract:
212	@${TOUCH} ${TOUCH_FLAGS} ${EXTRACT_COOKIE}
213.endif
214.if defined(NO_CONFIGURE) && !target(configure)
215configure:
216	@${TOUCH} ${TOUCH_FLAGS} ${CONFIGURE_COOKIE}
217.endif
218.if defined(NO_BUILD) && !target(build)
219build:
220	@${TOUCH} ${TOUCH_FLAGS} ${BUILD_COOKIE}
221.endif
222.if defined(NO_PACKAGE) && !target(package)
223package:
224	@${DO_NADA}
225.endif
226.if defined(NO_INSTALL) && !target(install)
227install:
228	@${TOUCH} ${TOUCH_FLAGS} ${INSTALL_COOKIE}
229.endif
230
231# More standard targets start here.
232
233.if !target(reinstall)
234reinstall: pre-reinstall install
235
236pre-reinstall:
237	@rm -f ${INSTALL_COOKIE}
238.endif
239
240.if !target(pre-install)
241pre-install:
242	@${DO_NADA}
243.endif
244
245.if !target(install)
246install: ${INSTALL_COOKIE}
247
248${INSTALL_COOKIE}:
249	@echo "===>  Installing for ${DISTNAME}"
250	@${MAKE} ${.MAKEFLAGS} pre-install
251.if defined(USE_GMAKE)
252	@(cd ${WRKSRC}; ${GMAKE} PREFIX=${PREFIX} ${MAKE_FLAGS} ${MAKEFILE} ${INSTALL_TARGET})
253.else defined(USE_GMAKE)
254	@(cd ${WRKSRC}; ${MAKE} PREFIX=${PREFIX} ${MAKE_FLAGS} ${MAKEFILE} ${INSTALL_TARGET})
255.if defined(USE_IMAKE)
256	@(cd ${WRKSRC}; ${MAKE} ${MAKE_FLAGS} ${MAKEFILE} install.man)
257.endif
258.endif
259	@${TOUCH} ${TOUCH_FLAGS} ${INSTALL_COOKIE}
260.endif
261
262.if !target(pre-package)
263pre-package:
264	@${DO_NADA}
265.endif
266
267.if !target(package)
268package: pre-package
269# Makes some gross assumptions about a fairly simple package with no
270# install, require or deinstall scripts.  Override the arguments with
271# PKG_ARGS if your package is anything but run-of-the-mill.
272	@if [ -d ${PKGDIR} ]; then \
273		echo "===>  Building package for ${DISTNAME}"; \
274		${PKG_CMD} ${PKG_ARGS} ${PKGFILE}; \
275	fi
276.endif
277
278.if !target(pre-build)
279pre-build:
280	@${DO_NADA}
281.endif
282
283.if !target(build)
284build: configure pre-build ${BUILD_COOKIE}
285
286${BUILD_COOKIE}:
287	@echo "===>  Building for ${DISTNAME}"
288.if defined(DEPENDS)
289	@echo "===>  ${DISTNAME} depends on:  ${DEPENDS}"
290.if !defined(NO_DEPENDS)
291	@for i in ${DEPENDS}; do \
292		echo "===>  Verifying build for $$i"; \
293		if [ ! -d $$i ]; then \
294			echo ">> No directory for $$i.  Skipping.."; \
295		else \
296			(cd $$i; ${MAKE} ${.MAKEFLAGS} is_depended) ; \
297		fi \
298	done
299	@echo "===>  Returning to build of ${DISTNAME}"
300.endif
301.endif
302.if defined(USE_GMAKE)
303	@(cd ${WRKSRC}; ${GMAKE} ${MAKE_FLAGS} ${MAKEFILE} ${ALL_TARGET})
304.else defined(USE_GMAKE)
305	@(cd ${WRKSRC}; ${MAKE} ${MAKE_FLAGS} ${MAKEFILE} ${ALL_TARGET})
306.endif
307	@if [ -f ${SCRIPTDIR}/post-build ]; then \
308		env CURDIR=${.CURDIR} DISTDIR=${DISTDIR} WRKDIR=${WRKDIR} \
309		  WRKSRC=${WRKSRC} PATCHDIR=${PATCHDIR} SCRIPTDIR=${SCRIPTDIR} \
310		  FILESDIR=${FILESDIR} PORTSDIR=${PORTSDIR} PREFIX=${PREFIX} \
311		  DEPENDS="${DEPENDS}" \
312		sh ${SCRIPTDIR}/post-build; \
313	fi
314	@${TOUCH} ${TOUCH_FLAGS} ${BUILD_COOKIE}
315.endif
316
317.if !target(pre-configure)
318pre-configure:
319	@${DO_NADA}
320.endif
321
322.if !target(configure)
323configure: extract ${CONFIGURE_COOKIE}
324
325${CONFIGURE_COOKIE}:
326	@echo "===>  Configuring for ${DISTNAME}"
327	@${MAKE} ${.MAKEFLAGS} pre-configure
328	@if [ -d ${PATCHDIR} ]; then \
329		echo "===>  Applying patches for ${DISTNAME}" ; \
330		for i in ${PATCHDIR}/patch-*; do \
331			${PATCH} ${PATCH_ARGS} < $$i; \
332	done; \
333	fi
334	@if [ -f ${SCRIPTDIR}/pre-configure ]; then \
335		env CURDIR=${.CURDIR} DISTDIR=${DISTDIR} WRKDIR=${WRKDIR} \
336		  WRKSRC=${WRKSRC} PATCHDIR=${PATCHDIR} SCRIPTDIR=${SCRIPTDIR} \
337		  FILESDIR=${FILESDIR} PORTSDIR=${PORTSDIR} PREFIX=${PREFIX} \
338		  DEPENDS="${DEPENDS}" \
339		sh ${SCRIPTDIR}/pre-configure; \
340	fi
341	@if [ -f ${SCRIPTDIR}/configure ]; then \
342		env CURDIR=${.CURDIR} DISTDIR=${DISTDIR} WRKDIR=${WRKDIR} \
343		  WRKSRC=${WRKSRC} PATCHDIR=${PATCHDIR} SCRIPTDIR=${SCRIPTDIR} \
344		  FILESDIR=${FILESDIR} PORTSDIR=${PORTSDIR} PREFIX=${PREFIX} \
345		  DEPENDS="${DEPENDS}" \
346		sh ${SCRIPTDIR}/configure; \
347	fi
348.if defined(HAS_CONFIGURE)
349	@(cd ${WRKSRC}; ./configure ${CONFIGURE_ARGS})
350.endif
351.if defined(USE_IMAKE)
352	@(cd ${WRKSRC}; ${XMKMF} && ${MAKE} Makefiles)
353.endif
354	@if [ -f ${SCRIPTDIR}/post-configure ]; then \
355		env CURDIR=${.CURDIR} DISTDIR=${DISTDIR} WRKDIR=${WRKDIR} \
356		  WRKSRC=${WRKSRC} PATCHDIR=${PATCHDIR} SCRIPTDIR=${SCRIPTDIR} \
357		  FILESDIR=${FILESDIR} PORTSDIR=${PORTSDIR} PREFIX=${PREFIX} \
358		  DEPENDS="${DEPENDS}" \
359		sh ${SCRIPTDIR}/post-configure; \
360	fi
361	@${TOUCH} ${TOUCH_FLAGS} ${CONFIGURE_COOKIE}
362.endif
363
364.if !target(pre-fetch)
365pre-fetch:
366	@${DO_NADA}
367.endif
368
369.if !target(fetch)
370fetch: pre-fetch
371	@if [ ! -d ${DISTDIR} ]; then mkdir -p ${DISTDIR}; fi
372	@(cd ${DISTDIR}; \
373	 for file in ${DISTFILES}; do \
374		if [ ! -f $$file ]; then \
375			echo ">> $$file doesn't seem to exist on this system."; \
376			echo ">> Attempting to fetch it from a master site."; \
377			for site in ${MASTER_SITES}; do \
378				if ${NCFTP} ${NCFTPFLAGS} $${site}$${file}; then \
379					break; \
380				fi \
381			done; \
382			if [ ! -f $$file ]; then \
383				echo ">> Couldn't fetch it - please try to retreive this";\
384				echo ">> port manually into ${DISTDIR} and try again."; \
385				exit 1; \
386			fi; \
387	    fi \
388	 done)
389.endif
390
391.if !target(pre-extract)
392pre-extract:
393	@${DO_NADA}
394.endif
395
396.if !target(extract)
397# We need to depend on .extract_done rather than the presence of ${WRKDIR}
398# because if the user interrupts the extract in the middle (and it's often
399# a long procedure), we get tricked into thinking that we've got a good dist
400# in ${WRKDIR}.
401extract: fetch pre-extract ${EXTRACT_COOKIE}
402
403${EXTRACT_COOKIE}:
404	@echo "===>  Extracting for ${DISTNAME}"
405	@rm -rf ${WRKDIR}
406	@mkdir -p ${WRKDIR}
407.if defined(EXTRACT_ONLY)
408	@for file in ${EXTRACT_ONLY}; do \
409		${EXTRACT_CMD} ${EXTRACT_ARGS} ${DISTDIR}/$$file ; \
410	done
411.else
412	@for file in ${DISTFILES}; do \
413		${EXTRACT_CMD} ${EXTRACT_ARGS} ${DISTDIR}/$$file ; \
414	done
415.endif
416	@${TOUCH} ${TOUCH_FLAGS} ${EXTRACT_COOKIE}
417.endif
418
419.if !target(pre-clean)
420pre-clean:
421	@${DO_NADA}
422.endif
423
424.if !target(clean)
425clean: pre-clean
426	@echo "===>  Cleaning for ${DISTNAME}"
427	@rm -f ${EXTRACT_COOKIE} ${CONFIGURE_COOKIE} ${INSTALL_COOKIE} \
428		${BUILD_COOKIE}
429	@rm -rf ${WRKDIR}
430.endif
431
432# No pre-targets for depend or tags.  It would be silly.
433
434# Depend is generally meaningless for arbitrary ports, but if someone wants
435# one they can override this.  This is just to catch people who've gotten into
436# the habit of typing `make depend all install' as a matter of course.
437#
438.if !target(depend)
439depend:
440.endif
441
442# Same goes for tags
443.if !target(tags)
444tags:
445.endif
446