bsd.port.mk revision 3162
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.40 1994/09/22 07:45:30 swallace 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# MASTER_SITES	- Primary location(s) for distribution files if not found
19#				  locally.
20# PACKAGES		- A top level directory where all packages go (rather than
21#				  going locally to each port). (default: ${PORTSDIR}/packages).
22# GMAKE			- Set to path of GNU make if not in $PATH (default: gmake).
23# XMKMF			- Set to path of `xmkmf' if not in $PATH (default: xmkmf).
24#
25# Variables that typically apply to an individual port:
26#
27# WRKDIR 		- A temporary working directory that gets *clobbered* on clean.
28# WRKSRC		- A subdirectory of ${WRKDIR} where the distribution actually
29#				  unpacks to.  (Default: ${WRKDIR}/${DISTNAME} unless
30#				  NO_WRKSUBDIR is set, in which case simply ${WRKDIR}).
31# DISTNAME		- Name of port or distribution.
32# DISTFILES		- Name(s) of archive file(s) containing distribution
33#				  (default: ${DISTDIR}/${DISTNAME}${EXTRACT_SUFX}).
34# EXTRACT_ONLY		- If defined, a subset of ${DISTFILES} you want to
35#			  actually extract.
36# PATCHDIR 		- A directory containing any required patches.
37# SCRIPTDIR 	- A directory containing any auxilliary scripts.
38# FILESDIR 		- A directory containing any miscellaneous additional files.
39# PKGDIR 		- A direction containing any package creation files.
40#
41# NO_EXTRACT	- Use a dummy (do-nothing) extract target.
42# NO_CONFIGURE	- Use a dummy (do-nothing) configure target.
43# NO_BUILD		- Use a dummy (do-nothing) build target.
44# NO_PACKAGE	- Use a dummy (do-nothing) package target.
45# NO_INSTALL	- Use a dummy (do-nothing) install target.
46# NO_WRKSUBDIR	- Assume port unpacks directly into ${WRKDIR}.
47# USE_GMAKE		- Says that the port uses gmake.
48# USE_IMAKE		- Says that the port uses imake.
49# HAS_CONFIGURE	- Says that the port has its own configure script.
50# CONFIGURE_ARGS - Pass these args to configure, if $HAS_CONFIGURE.
51# DEPENDS		- A list of other ports this package depends on being
52#				  made first, relative to ${PORTSDIR} (e.g. x11/tk, lang/tcl,
53#				  etc).
54# EXTRACT_CMD	- Command for extracting archive (default: tar).
55# EXTRACT_SUFX	- Suffix for archive names (default: .tar.gz).
56# EXTRACT_ARGS	- Arguments to ${EXTRACT_CMD} (default: -C ${WRKDIR} -xzf).
57#
58# NCFTP			- Full path to ncftp command if not in $PATH (default: ncftp).
59# NCFTP_ARGS	- Arguments to ${NCFTP} (default: -N).
60#
61#
62# Default targets and their behaviors:
63#
64# fetch			- Retrieves ${DISTFILES} into ${DISTDIR} as necessary.
65# extract		- Unpacks ${DISTFILES} into ${WRKDIR}.
66# configure		- Applies patches, if any, and runs either GNU configure, one
67#				  or more local configure scripts or nothing, depending on
68#				  what's available.
69# build			- Actually compile the sources.
70# install		- Install the results of a build.
71# package		- Create a package from a build.
72#
73# Default sequence for "all" is:  fetch extract configure build
74
75.if exists(${.CURDIR}/../Makefile.inc)
76.include "${.CURDIR}/../Makefile.inc"
77.endif
78
79# These need to be absolute since we don't know how deep in the ports
80# tree we are and thus can't go relative.  They can, of course, be overridden
81# by individual Makefiles.
82PORTSDIR?=		${DESTDIR}/usr/ports
83DISTDIR?=		${PORTSDIR}/distfiles
84PACKAGES?=		${PORTSDIR}/packages
85WRKDIR?=		${.CURDIR}/work
86.if defined(NO_WRKSUBDIR)
87WRKSRC?=		${WRKDIR}
88.else
89WRKSRC?=		${WRKDIR}/${DISTNAME}
90.endif
91PATCHDIR?=		${.CURDIR}/patches
92SCRIPTDIR?=		${.CURDIR}/scripts
93FILESDIR?=		${.CURDIR}/files
94PKGDIR?=		${.CURDIR}/pkg
95
96.if exists(${PORTSDIR}/../Makefile.inc)
97.include "${PORTSDIR}/../Makefile.inc"
98.endif
99
100
101# Change these if you'd prefer to keep the cookies someplace else.
102EXTRACT_COOKIE?=	${WRKDIR}/.extract_done
103CONFIGURE_COOKIE?=	${WRKDIR}/.configure_done
104
105# How to do nothing.  Override if you, for some strange reason, would rather
106# do something.
107DO_NADA?=		echo -n
108
109# Miscellaneous overridable commands:
110GMAKE?=			gmake
111XMKMF?=			xmkmf
112MAKE_FLAGS?=	-f
113MAKEFILE?=		Makefile
114
115NCFTP?=			ncftp
116NCFTPFLAGS?=	-N
117
118PATCH?=			patch
119PATCH_STRIP?=	-p0
120PATCH_ARGS?=	 -d ${WRKSRC} --quiet -E ${PATCH_STRIP}
121
122EXTRACT_CMD?=	tar
123EXTRACT_SUFX?=	.tar.gz
124EXTRACT_ARGS?=	-C ${WRKDIR} -xzf
125
126PKG_CMD?=		pkg_create
127PKG_ARGS?=		-v -c ${PKGDIR}/COMMENT -d ${PKGDIR}/DESCR -f ${PKGDIR}/PLIST
128PKG_SUFX?=		.tgz
129
130# I guess we're in the master distribution business! :)  As we gain mirror
131# sites for distfiles, add them to this list.
132MASTER_SITES+=	ftp://freebsd.cdrom.com/pub/FreeBSD/FreeBSD-current/ports/distfiles/
133
134# Derived names so that they're easily overridable.
135DISTFILES?=		${DISTNAME}${EXTRACT_SUFX}
136
137.if exists(${PACKAGES})
138PKGFILE?=		${PACKAGES}/${DISTNAME}${PKG_SUFX}
139.else
140PKGFILE?=		${DISTNAME}${PKG_SUFX}
141.endif
142
143.MAIN: all
144all: extract configure build
145
146# The following are used to create easy dummy targets for disabling some
147# bit of default target behavior you don't want.  They still check to see
148# if the target exists, and if so don't do anything, since you might want
149# to set this globally for a group of ports in a Makefile.inc, but still
150# be able to override from an individual Makefile (since you can't _undefine_
151# a variable in make!).
152.if defined(NO_EXTRACT) && !target(extract)
153extract:
154	@touch -f ${EXTRACT_COOKIE}
155.endif
156.if defined(NO_CONFIGURE) && !target(configure)
157configure:
158	@touch -f ${CONFIGURE_COOKIE}
159.endif
160.if defined(NO_BUILD) && !target(build)
161build:
162	@${DO_NADA}
163.endif
164.if defined(NO_PACKAGE) && !target(package)
165package:
166	@${DO_NADA}
167.endif
168.if defined(NO_INSTALL) && !target(install)
169install:
170	@${DO_NADA}
171.endif
172
173# More standard targets start here.
174
175.if !target(pre-install)
176pre-install:
177	@${DO_NADA}
178.endif
179
180.if !target(install)
181install: pre-install
182	@echo "===>  Installing for ${DISTNAME}"
183.if defined(USE_GMAKE)
184	@(cd ${WRKSRC}; ${GMAKE} ${MAKE_FLAGS} ${MAKEFILE} install)
185.else defined(USE_GMAKE)
186	@(cd ${WRKSRC}; ${MAKE} ${MAKE_FLAGS} ${MAKEFILE} install)
187.endif
188.endif
189
190.if !target(pre-package)
191pre-package:
192	@${DO_NADA}
193.endif
194
195.if !target(package)
196package: pre-package
197# Makes some gross assumptions about a fairly simple package with no
198# install, require or deinstall scripts.  Override the arguments with
199# PKG_ARGS if your package is anything but run-of-the-mill.
200	@if [ -d ${PKGDIR} ]; then \
201		echo "===>  Building package for ${DISTNAME}"; \
202		${PKG_CMD} ${PKG_ARGS} ${PKGFILE}; \
203	fi
204.endif
205
206.if !target(pre-build)
207pre-build:
208	@${DO_NADA}
209.endif
210
211.if !target(build)
212build: configure pre-build
213	@echo "===>  Building for ${DISTNAME}"
214.if defined(DEPENDS)
215	@echo "===>  ${DISTNAME} depends on:  ${DEPENDS}"
216	@for i in ${DEPENDS}; do \
217		echo "===>  Verifying build for $$i"; \
218		if [ ! -d ${PORTSDIR}/$$i ]; then \
219			echo ">> No directory for ${PORTSDIR}/$$i.  Skipping.."; \
220		else \
221			(cd ${PORTSDIR}/$$i; ${MAKE} all install) ; \
222		fi \
223	done
224	@echo "===>  Returning to build of ${DISTNAME}"
225.endif
226.if defined(USE_GMAKE)
227	@(cd ${WRKSRC}; ${GMAKE} ${MAKE_FLAGS} ${MAKEFILE} all)
228.else defined(USE_GMAKE)
229	@(cd ${WRKSRC}; ${MAKE} ${MAKE_FLAGS} ${MAKEFILE} all)
230.endif
231	@if [ -f ${SCRIPTDIR}/post-build ]; then \
232		sh ${SCRIPTDIR}/post-build ${PORTSDIR} ${.CURDIR} ${WRKSRC}; \
233	fi
234.endif
235
236.if !target(pre-configure)
237pre-configure:
238	@${DO_NADA}
239.endif
240
241.if !target(configure)
242# This is done with a .configure because configures are often expensive,
243# and you don't want it done again gratuitously when you're trying to get
244# a make of the whole tree to work.
245configure: pre-configure extract ${CONFIGURE_COOKIE}
246
247${CONFIGURE_COOKIE}:
248	@echo "===>  Configuring for ${DISTNAME}"
249	@if [ -d ${PATCHDIR} ]; then \
250		echo "===>  Applying patches for ${DISTNAME}" ; \
251		for i in ${PATCHDIR}/patch-*; do \
252			${PATCH} ${PATCH_ARGS} < $$i; \
253	done; \
254	fi
255# We have a small convention for our local configure scripts, which
256# is that ${PORTSDIR}, ${.CURDIR} and ${WRKSRC} get passed as
257# command-line arguments since all other methods are a little
258# problematic.
259	@if [ -f ${SCRIPTDIR}/pre-configure ]; then \
260		sh ${SCRIPTDIR}/pre-configure ${PORTSDIR} ${.CURDIR} ${WRKSRC}; \
261	fi
262	@if [ -f ${SCRIPTDIR}/configure ]; then \
263		sh ${SCRIPTDIR}/configure ${PORTSDIR} ${.CURDIR} ${WRKSRC}; \
264	fi
265.if defined(HAS_CONFIGURE)
266	@(cd ${WRKSRC}; ./configure ${CONFIGURE_ARGS})
267.endif
268.if defined(USE_IMAKE)
269	@(cd ${WRKSRC}; ${XMKMF} && ${MAKE} Makefiles)
270.endif
271	@if [ -f ${SCRIPTDIR}/post-configure ]; then \
272		sh ${SCRIPTDIR}/post-configure ${PORTSDIR} ${.CURDIR} ${WRKSRC}; \
273	fi
274	@touch -f ${CONFIGURE_COOKIE}
275.endif
276
277.if !target(pre-fetch)
278pre-fetch:
279	@${DO_NADA}
280.endif
281
282.if !target(fetch)
283fetch: pre-fetch
284	@if [ ! -d ${DISTDIR} ]; then mkdir -p ${DISTDIR}; fi
285	@(cd ${DISTDIR}; \
286	 for file in ${DISTFILES}; do \
287		if [ ! -f $$file ]; then \
288			echo ">> $$file doesn't seem to exist on this system."; \
289			echo ">> Attempting to fetch it from a master site."; \
290			for site in ${MASTER_SITES}; do \
291				if ${NCFTP} ${NCFTPFLAGS} $${site}$${file}; then \
292					echo ">> $$file Fetched!" ; \
293					break; \
294				fi \
295			done; \
296			if [ ! -f $$file ]; then \
297				echo ">> Couldn't fetch it - please try to retreive this";\
298				echo ">> port manually into ${DISTDIR} and try again."; \
299				exit 1; \
300			fi; \
301	    fi \
302	 done)
303.endif
304
305.if !target(pre-extract)
306pre-extract:
307	@${DO_NADA}
308.endif
309
310.if !target(extract)
311# We need to depend on .extract_done rather than the presence of ${WRKDIR}
312# because if the user interrupts the extract in the middle (and it's often
313# a long procedure), we get tricked into thinking that we've got a good dist
314# in ${WRKDIR}.
315extract: fetch pre-extract ${EXTRACT_COOKIE}
316
317${EXTRACT_COOKIE}:
318	@echo "===>  Extracting for ${DISTNAME}"
319	@rm -rf ${WRKDIR}
320	@mkdir -p ${WRKDIR}
321.if defined(EXTRACT_ONLY)
322	@for file in ${EXTRACT_ONLY}; do \
323		${EXTRACT_CMD} ${EXTRACT_ARGS} ${DISTDIR}/$$file ; \
324	done
325.else
326	@for file in ${DISTFILES}; do \
327		${EXTRACT_CMD} ${EXTRACT_ARGS} ${DISTDIR}/$$file ; \
328	done
329.endif
330	@touch -f ${EXTRACT_COOKIE}
331.endif
332
333.if !target(pre-clean)
334pre-clean:
335	@${DO_NADA}
336.endif
337
338.if !target(clean)
339clean: pre-clean
340	@echo "===>  Cleaning for ${DISTNAME}"
341	@rm -f ${EXTRACT_COOKIE} ${CONFIGURE_COOKIE}
342	@rm -rf ${WRKDIR}
343.endif
344
345# No pre-targets for depend or tags.  It would be silly.
346
347# Depend is generally meaningless for arbitrary ports, but if someone wants
348# one they can override this.  This is just to catch people who've gotten into
349# the habit of typing `make depend all install' as a matter of course.
350#
351.if !target(depend)
352depend:
353.endif
354
355# Same goes for tags
356.if !target(tags)
357tags:
358.endif
359