bsd.port.mk revision 7734
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.136 1995/04/09 15:00:56 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 (default:
21#				   ftp://ftp.freebsd.org/pub/FreeBSD/ports/distfiles)
22# PATCH_SITES	- Primary location(s) for distributed patch files
23#				  (see PATCHFILES below) if not found locally (default:
24#				   ftp://ftp.freebsd.org/pub/FreeBSD/ports/distfiles)
25#
26# MASTER_SITE_OVERRIDE - If set, override the MASTER_SITES setting with this
27#				  value.
28# MASTER_SITE_FREEBSD - If set, only use the FreeBSD master repository for
29#				  MASTER_SITES.
30# PACKAGES		- A top level directory where all packages go (rather than
31#				  going locally to each port). (default: ${PORTSDIR}/packages).
32# GMAKE			- Set to path of GNU make if not in $PATH (default: gmake).
33# XMKMF			- Set to path of `xmkmf' if not in $PATH (default: xmkmf -a ).
34# MAINTAINER	- The e-mail address of the contact person for this port
35#				  (default: ports@FreeBSD.ORG).
36# CATEGORIES	- A list of descriptive categories into which this port falls
37#				  (default: orphans).
38# KEYWORDS		- A list of descriptive keywords that might index well for this
39#				  port (default: orphans).
40#
41# Variables that typically apply to an individual port.  Non-Boolean
42# variables without defaults are *mandatory*.
43# 
44#
45# WRKDIR 		- A temporary working directory that gets *clobbered* on clean
46#				  (default: ${.CURDIR}/work).
47# WRKSRC		- A subdirectory of ${WRKDIR} where the distribution actually
48#				  unpacks to.  (Default: ${WRKDIR}/${DISTNAME} unless
49#				  NO_WRKSUBDIR is set, in which case simply ${WRKDIR}).
50# DISTNAME		- Name of port or distribution.
51# DISTFILES		- Name(s) of archive file(s) containing distribution
52#				  (default: ${DISTDIR}/${DISTNAME}${EXTRACT_SUFX}).
53# PATCHFILES	- Name(s) of additional files that contain distributed
54#				  patches (default: none).  make will look for them at
55#				  PATCH_SITES (see above).  They will automatically be
56#				  uncompressed before patching if the names end with
57#				  ".gz" or ".Z".
58# PKGNAME		- Name of the package file to create if the DISTNAME 
59#				  isn't really relevant for the port/package
60#				  (default: ${DISTNAME}).
61# EXTRACT_ONLY	- If defined, a subset of ${DISTFILES} you want to
62#			  	  actually extract.
63# PATCHDIR 		- A directory containing any additional patches you made
64#				  to port this software to FreeBSD (default:
65#				  ${.CURDIR}/patches)
66# SCRIPTDIR 	- A directory containing any auxiliary scripts
67#				  (default: ${.CURDIR}/scripts)
68# FILESDIR 		- A directory containing any miscellaneous additional files.
69#				  (default: ${.CURDIR}/files)
70# PKGDIR 		- A direction containing any package creation files.
71#				  (default: ${.CURDIR}/pkg)
72#
73# NO_EXTRACT	- Use a dummy (do-nothing) extract target.
74# NO_CONFIGURE	- Use a dummy (do-nothing) configure target.
75# NO_BUILD		- Use a dummy (do-nothing) build target.
76# NO_PACKAGE	- Use a dummy (do-nothing) package target.
77# NO_INSTALL	- Use a dummy (do-nothing) install target.
78# NO_WRKSUBDIR	- Assume port unpacks directly into ${WRKDIR}.
79# NO_WRKDIR		- There's no work directory at all; port does this someplace
80#				  else.
81# NO_DEPENDS	- Don't verify build of dependencies.
82# USE_GMAKE		- Says that the port uses gmake.
83# USE_IMAKE		- Says that the port uses imake.
84# USE_X11		- Says that the port uses X11.
85# NO_INSTALL_MANPAGES - For imake ports that don't like the install.man
86#						target.
87# HAS_CONFIGURE	- Says that the port has its own configure script.
88# GNU_CONFIGURE	- Set if you are using GNU configure (optional).
89# CONFIGURE_SCRIPT - Name of configure script, defaults to 'configure'.
90# CONFIGURE_ARGS - Pass these args to configure, if ${HAS_CONFIGURE} set.
91# IS_INTERACTIVE - Set this if your port needs to interact with the user
92#				  during a build.  User can then decide to skip this port by
93#				  setting ${BATCH}, or compiling only the interactive ports
94#				  by setting ${INTERACTIVE}.
95# EXEC_DEPENDS	- A list of "prog:dir" pairs of other ports this
96#				  package depends on.  "prog" is the name of an
97#				  executable.  make will search your $PATH for it and go
98#				  into "dir" to do a "make all install" if it's not found.
99# LIB_DEPENDS	- A list of "lib:dir" pairs of other ports this package
100#				  depends on.  "lib" is the name of a shared library.
101#				  make will use "ldconfig -r" to search for the
102#				  library.  Note that lib can be any regular expression,
103#				  and you need two backslashes in front of dots (.) to
104#				  supress its special meaning (e.g., use
105#				  "foo\\.2\\.:${PORTSDIR}/utils/foo" to match "libfoo.2.*").
106# DEPENDS		- A list of other ports this package depends on being
107#				  made first.  Use this for things that don't fall into
108#				  the above two categories.
109# EXTRACT_CMD	- Command for extracting archive (default: tar).
110# EXTRACT_SUFX	- Suffix for archive names (default: .tar.gz).
111# EXTRACT_BEFORE_ARGS -
112#				  Arguments to ${EXTRACT_CMD} before filename
113#				  (default: -C ${WRKDIR} -xzf).
114# EXTRACT_AFTER_ARGS -
115#				  Arguments to ${EXTRACT_CMD} following filename
116#				  (default: none).
117#
118# NCFTP			- Full path to ncftp command if not in $PATH (default: ncftp).
119# NCFTPFLAGS    - Arguments to ${NCFTP} (default: -N).
120#
121#
122# Default targets and their behaviors:
123#
124# fetch			- Retrieves ${DISTFILES} (and ${PATCHFILES} if defined)
125#				  into ${DISTDIR} as necessary.
126# fetch-list	- Show list of files that would be retrieved by fetch
127# extract		- Unpacks ${DISTFILES} into ${WRKDIR}.
128# patch			- Apply any provided patches to the source.
129# configure		- Runs either GNU configure, one or more local configure
130#				  scripts or nothing, depending on what's available.
131# build			- Actually compile the sources.
132# install		- Install the results of a build.
133# reinstall		- Install the results of a build, ignoring "already installed"
134#				  flag.
135# package		- Create a package from an _installed_ port.
136# describe		- Try to generate a one-line description for each port for
137#				  use in INDEX files and the like.
138# checksum		- Use files/md5 to ensure that your distfiles are valid
139# makesum		- Generate files/md5 (only do this for your own ports!)
140#
141# Default sequence for "all" is:  fetch extract patch configure build
142
143.if exists(${.CURDIR}/../Makefile.inc)
144.include "${.CURDIR}/../Makefile.inc"
145.endif
146
147# These need to be absolute since we don't know how deep in the ports
148# tree we are and thus can't go relative.  They can, of course, be overridden
149# by individual Makefiles.
150PORTSDIR?=		${DESTDIR}/usr/ports
151X11BASE?=		/usr/X11R6
152DISTDIR?=		${PORTSDIR}/distfiles
153PACKAGES?=		${PORTSDIR}/packages
154.if !defined(NO_WRKDIR)
155WRKDIR?=		${.CURDIR}/work
156.else
157WRKDIR?=		${.CURDIR}
158.endif
159.if defined(NO_WRKSUBDIR)
160WRKSRC?=		${WRKDIR}
161.else
162WRKSRC?=		${WRKDIR}/${DISTNAME}
163.endif
164PATCHDIR?=		${.CURDIR}/patches
165SCRIPTDIR?=		${.CURDIR}/scripts
166FILESDIR?=		${.CURDIR}/files
167PKGDIR?=		${.CURDIR}/pkg
168.if defined(USE_IMAKE) || defined(USE_X11)
169PREFIX?=		${X11BASE}
170.else
171PREFIX?=		/usr/local
172.endif
173.if defined(USE_GMAKE)
174EXEC_DEPENDS+=               gmake:${PORTSDIR}/devel/gmake
175.endif
176
177.if exists(${PORTSDIR}/../Makefile.inc)
178.include "${PORTSDIR}/../Makefile.inc"
179.endif
180
181
182# Change these if you'd prefer to keep the cookies someplace else.
183EXTRACT_COOKIE?=	${WRKDIR}/.extract_done
184CONFIGURE_COOKIE?=	${WRKDIR}/.configure_done
185INSTALL_COOKIE?=	${WRKDIR}/.install_done
186BUILD_COOKIE?=		${WRKDIR}/.build_done
187PATCH_COOKIE?=		${WRKDIR}/.patch_done
188
189# How to do nothing.  Override if you, for some strange reason, would rather
190# do something.
191DO_NADA?=		echo -n
192
193# Miscellaneous overridable commands:
194GMAKE?=			gmake
195XMKMF?=			xmkmf -a
196MD5?=			/sbin/md5
197MD5_FILE?=		${FILESDIR}/md5
198MAKE_FLAGS?=	-f
199MAKEFILE?=		Makefile
200
201NCFTP?=			ncftp
202NCFTPFLAGS?=	-N
203
204TOUCH?=			touch
205TOUCH_FLAGS?=	-f
206
207PATCH?=			patch
208PATCH_STRIP?=	-p0
209PATCH_DIST_STRIP?=	-p0
210.if defined(PATCH_DEBUG)
211PATCH_ARGS?=	-d ${WRKSRC} -E ${PATCH_STRIP}
212PATCH_DIST_ARGS?=	-d ${WRKSRC} -E ${PATCH_DIST_STRIP}
213.else
214PATCH_ARGS?=	-d ${WRKSRC} --forward --quiet -E ${PATCH_STRIP}
215PATCH_DIST_ARGS?=	-d ${WRKSRC} --forward --quiet -E ${PATCH_DIST_STRIP}
216.endif
217
218EXTRACT_CMD?=	tar
219EXTRACT_SUFX?=	.tar.gz
220# Backwards compatability.
221.if defined(EXTRACT_ARGS)
222EXTRACT_BEFORE_ARGS?=   ${EXTRACT_ARGS}
223.else
224EXTRACT_BEFORE_ARGS?=   -xzf
225.endif
226
227PKG_CMD?=		pkg_create
228.if !defined(PKG_ARGS)
229PKG_ARGS=		-v -c ${PKGDIR}/COMMENT -d ${PKGDIR}/DESCR -f ${PKGDIR}/PLIST -p ${PREFIX} -P "`${MAKE} package-depends|sort|uniq`"
230.if exists(${PKGDIR}/INSTALL)
231PKG_ARGS+=		-i ${PKGDIR}/INSTALL
232.endif
233.if exists(${PKGDIR}/DEINSTALL)
234PKG_ARGS+=		-k ${PKGDIR}/DEINSTALL
235.endif
236.if exists(${PKGDIR}/REQ)
237PKG_ARGS+=		-r ${PKGDIR}/REQ
238.endif
239.endif
240PKG_SUFX?=		.tgz
241
242ECHO_MSG?=		echo
243
244ALL_TARGET?=		all
245INSTALL_TARGET?=	install
246
247.if defined(MASTER_SITE_FREEBSD)
248MASTER_SITE_OVERRIDE=  ftp://freebsd.cdrom.com/pub/FreeBSD/FreeBSD-current/ports/distfiles/ 
249.endif
250
251# I guess we're in the master distribution business! :)  As we gain mirror
252# sites for distfiles, add them to this list.
253.if !defined(MASTER_SITE_OVERRIDE)
254MASTER_SITES+=	ftp://ftp.freebsd.org/pub/FreeBSD/FreeBSD-current/ports/distfiles/
255PATCH_SITES+=	ftp://ftp.freebsd.org/pub/FreeBSD/FreeBSD-current/ports/distfiles/
256.else
257MASTER_SITES=	${MASTER_SITE_OVERRIDE}
258PATCH_SITES=	${MASTER_SITE_OVERRIDE}
259.endif
260
261# Derived names so that they're easily overridable.
262DISTFILES?=		${DISTNAME}${EXTRACT_SUFX}
263PKGNAME?=		${DISTNAME}
264
265# Documentation
266MAINTAINER?=	ports@FreeBSD.ORG
267CATEGORIES?=	orphans
268CATEGORIES+=	all
269KEYWORDS+=		${CATEGORIES}
270
271PKGREPOSITORYSUBDIR?=	.package
272PKGREPOSITORY?=		${PACKAGES}/${PKGREPOSITORYSUBDIR}
273.if exists(${PACKAGES})
274PKGFILE?=		${PKGREPOSITORY}/${PKGNAME}${PKG_SUFX}
275.else
276PKGFILE?=		${PKGNAME}${PKG_SUFX}
277.endif
278
279CONFIGURE_SCRIPT?=	configure
280
281.if defined(GNU_CONFIGURE)
282CONFIGURE_ARGS?=	--prefix=${PREFIX}
283HAS_CONFIGURE=		yes
284.endif
285
286.MAIN: all
287
288# If we're in BATCH mode and the port is interactive, or we're in
289# interactive mode and the port is non-interactive, skip all the important
290# targets.  The reason we have two modes is that one might want to leave
291# a build in BATCH mode running overnight, then come back in the morning
292# and do _only_ the interactive ones that required your intervention.
293# This allows you to do both.
294#
295.if (defined(IS_INTERACTIVE) && defined(BATCH)) || (!defined(IS_INTERACTIVE) && defined(INTERACTIVE))
296all:
297	@${DO_NADA}
298pre-build:
299	@${DO_NADA}
300build:
301	@${DO_NADA}
302pre-install:
303	@${DO_NADA}
304install:
305	@${DO_NADA}
306pre-fetch:
307	@${DO_NADA}
308fetch:
309	@${DO_NADA}
310pre-configure:
311	@${DO_NADA}
312configure:
313	@${DO_NADA}
314package:
315	@${DO_NADA}
316.endif
317
318.if !target(all)
319all: extract configure build
320.endif
321
322.if !target(is_depended)
323is_depended:	all install
324.endif
325
326# The following are used to create easy dummy targets for disabling some
327# bit of default target behavior you don't want.  They still check to see
328# if the target exists, and if so don't do anything, since you might want
329# to set this globally for a group of ports in a Makefile.inc, but still
330# be able to override from an individual Makefile (since you can't _undefine_
331# a variable in make!).
332.if defined(NO_EXTRACT) && !target(extract)
333extract:
334	@${TOUCH} ${TOUCH_FLAGS} ${EXTRACT_COOKIE}
335checksum:
336	@${DO_NADA}
337makesum:
338	@${DO_NADA}
339.endif
340.if defined(NO_CONFIGURE) && !target(configure)
341configure:
342	@${TOUCH} ${TOUCH_FLAGS} ${CONFIGURE_COOKIE}
343.endif
344.if defined(NO_BUILD) && !target(build)
345build:
346	@${TOUCH} ${TOUCH_FLAGS} ${BUILD_COOKIE}
347.endif
348.if defined(NO_PACKAGE) && !target(package)
349package:
350	@${DO_NADA}
351.endif
352.if defined(NO_INSTALL) && !target(install)
353install:
354	@${TOUCH} ${TOUCH_FLAGS} ${INSTALL_COOKIE}
355.endif
356.if defined(NO_PATCH) && !target(patch)
357patch:
358	@${TOUCH} ${TOUCH_FLAGS} ${PATCH_COOKIE}
359.endif
360
361# More standard targets start here.
362
363# This target generates an index entry suitable for aggregation into
364# a large index.  Format is:
365#
366# distribution-name|port-path|installation-prefix|comment| \
367#  description-file|maintainer
368#
369.if !target(describe)
370describe:
371	@echo -n "${DISTNAME}|${.CURDIR}/${DISTNAME}|"
372	@echo -n "${PREFIX}|"
373	@if [ -f ${PKGDIR}/COMMENT ]; then \
374		echo -n "`cat ${PKGDIR}/COMMENT`"; \
375	else \
376		echo -n "** No Description"; \
377	fi
378	@if [ -f ${PKGDIR}/DESCR ]; then \
379		echo -n "|${PKGDIR}/DESCR"; \
380	else \
381		echo -n "|/dev/null"; \
382	fi
383	@echo -n "|${MAINTAINER}|${CATEGORIES}|${KEYWORDS}"
384	@echo ""
385.endif
386
387.if !target(reinstall)
388reinstall: pre-reinstall install
389
390pre-reinstall:
391	@rm -f ${INSTALL_COOKIE}
392.endif
393
394.if !target(pre-install)
395pre-install:
396	@${DO_NADA}
397.endif
398
399.if !target(install)
400install: build ${INSTALL_COOKIE}
401
402${INSTALL_COOKIE}:
403	@${ECHO_MSG} "===>  Installing for ${DISTNAME}"
404	@${MAKE} ${.MAKEFLAGS} pre-install
405.if defined(USE_GMAKE)
406	@(cd ${WRKSRC}; ${GMAKE} PREFIX=${PREFIX} ${MAKE_FLAGS} ${MAKEFILE} ${INSTALL_TARGET})
407.if defined(USE_IMAKE) && !defined(NO_INSTALL_MANPAGES)
408	@(cd ${WRKSRC}; ${GMAKE} ${MAKE_FLAGS} ${MAKEFILE} install.man)
409.endif
410.else defined(USE_GMAKE)
411	@(cd ${WRKSRC}; ${MAKE} PREFIX=${PREFIX} ${MAKE_FLAGS} ${MAKEFILE} ${INSTALL_TARGET})
412.if defined(USE_IMAKE) && !defined(NO_INSTALL_MANPAGES)
413	@(cd ${WRKSRC}; ${MAKE} ${MAKE_FLAGS} ${MAKEFILE} install.man)
414.endif
415.endif
416	@${TOUCH} ${TOUCH_FLAGS} ${INSTALL_COOKIE}
417.endif
418
419# package-name and package-depends are internal targets and really
420# shouldn't be touched by anybody but the release engineers.
421
422# Nobody should want to override this unless PKGNAME is simply bogus.
423.if !target(package-name)
424package-name:
425.if !defined(NO_PACKAGE)
426	@echo ${PKGNAME}
427.endif
428.endif
429
430# Show (recursively) all the packages this package depends on.
431.if !target(package-depends)
432package-depends:
433	@for i in ${EXEC_DEPENDS} ${LIB_DEPENDS} ${DEPENDS}; do \
434		dir=`echo $$i | sed -e 's/.*://'`; \
435		(cd $$dir ; ${MAKE} package-name package-depends); \
436	done
437.endif
438
439.if !target(pre-package)
440pre-package:
441	@${DO_NADA}
442.endif
443
444.if !target(package)
445package: pre-package
446	@if [ -e ${PKGDIR}/PLIST ]; then \
447		${ECHO_MSG} "===>  Building package for ${DISTNAME}"; \
448		if [ -d ${PACKAGES} ]; then \
449			if [ ! -d ${PKGREPOSITORY} ]; then \
450				if ! mkdir -p ${PKGREPOSITORY}; then \
451					${ECHO_MSG} ">> Can't create directory ${PKGREPOSITORY}."; \
452					exit 1; \
453				fi; \
454			fi; \
455		fi; \
456		${PKG_CMD} ${PKG_ARGS} ${PKGFILE}; \
457		if [ -d ${PACKAGES} ]; then \
458			rm -f ${PACKAGES}/*/${PKGNAME}${PKG_SUFX}; \
459			for cat in ${CATEGORIES}; do \
460				if [ ! -d ${PACKAGES}/$$cat ]; then \
461					if ! mkdir -p ${PACKAGES}/$$cat; then \
462						${ECHO_MSG} ">> Can't create directory ${PACKAGES}/$$cat."; \
463						exit 1; \
464					fi; \
465				fi; \
466				ln -s ../${PKGREPOSITORYSUBDIR}/${PKGNAME}${PKG_SUFX} ${PACKAGES}/$$cat; \
467			done; \
468		fi; \
469	fi
470.endif
471
472.if !target(depends)
473depends: exec_depends lib_depends misc_depends
474
475exec_depends:
476.if defined(EXEC_DEPENDS)
477.if defined(NO_DEPENDS)
478# Just print out messages
479	@for i in ${EXEC_DEPENDS}; do \
480		prog=`echo $$i | sed -e 's/:.*//'`; \
481		dir=`echo $$i | sed -e 's/.*://'`; \
482		${ECHO_MSG} "===>  ${DISTNAME} depends on executable:  $$prog ($$dir)"; \
483	done
484.else
485	@for i in ${EXEC_DEPENDS}; do \
486		prog=`echo $$i | sed -e 's/:.*//'`; \
487		dir=`echo $$i | sed -e 's/.*://'`; \
488		if which -s "$$prog"; then \
489			${ECHO_MSG} "===>  ${DISTNAME} depends on executable: $$prog - found"; \
490		else \
491			${ECHO_MSG} "===>  ${DISTNAME} depends on executable: $$prog - not found"; \
492			${ECHO_MSG} "===>  Verifying build for $$prog in $$dir"; \
493			if [ ! -d "$$dir" ]; then \
494				${ECHO_MSG} ">> No directory for $$prog.  Skipping.."; \
495			else \
496				(cd $$dir; ${MAKE} ${.MAKEFLAGS} is_depended) ; \
497				${ECHO_MSG} "===>  Returning to build of ${DISTNAME}"; \
498			fi; \
499		fi; \
500	done
501.endif
502.else
503	@${DO_NADA}
504.endif
505
506lib_depends:
507.if defined(LIB_DEPENDS)
508.if defined(NO_DEPENDS)
509# Just print out messages
510	@for i in ${LIB_DEPENDS}; do \
511		lib=`echo $$i | sed -e 's/:.*//'`; \
512		dir=`echo $$i | sed -e 's/.*://'`; \
513		${ECHO_MSG} "===>  ${DISTNAME} depends on shared library:  $$lib ($$dir)"; \
514	done
515.else
516	@for i in ${LIB_DEPENDS}; do \
517		lib=`echo $$i | sed -e 's/:.*//'`; \
518		dir=`echo $$i | sed -e 's/.*://'`; \
519		if ldconfig -r | grep -q -e "-l$$lib"; then \
520			${ECHO_MSG} "===>  ${DISTNAME} depends on shared library: $$lib - found"; \
521		else \
522			${ECHO_MSG} "===>  ${DISTNAME} depends on shared library: $$lib - not found"; \
523			${ECHO_MSG} "===>  Verifying build for $$lib in $$dir"; \
524			if [ ! -d "$$dir" ]; then \
525				${ECHO_MSG} ">> No directory for $$lib.  Skipping.."; \
526			else \
527				(cd $$dir; ${MAKE} ${.MAKEFLAGS} is_depended) ; \
528				${ECHO_MSG} "===>  Returning to build of ${DISTNAME}"; \
529			fi; \
530		fi; \
531	done
532.endif
533.else
534	@${DO_NADA}
535.endif
536
537misc_depends:
538.if defined(DEPENDS)
539	@${ECHO_MSG} "===>  ${DISTNAME} depends on:  ${DEPENDS}"
540.if !defined(NO_DEPENDS)
541	@for i in ${DEPENDS}; do \
542		${ECHO_MSG} "===>  Verifying build for $$i"; \
543		if [ ! -d $$i ]; then \
544			${ECHO_MSG} ">> No directory for $$i.  Skipping.."; \
545		else \
546			(cd $$i; ${MAKE} ${.MAKEFLAGS} is_depended) ; \
547		fi \
548	done
549	@${ECHO_MSG} "===>  Returning to build of ${DISTNAME}"
550.endif
551.else
552	@${DO_NADA}
553.endif
554
555.endif
556
557.if !target(pre-build)
558pre-build:
559	@${DO_NADA}
560.endif
561
562.if !target(build)
563build: configure ${BUILD_COOKIE}
564
565${BUILD_COOKIE}:
566	@${ECHO_MSG} "===>  Building for ${DISTNAME}"
567	@${MAKE} ${.MAKEFLAGS} pre-build
568.if defined(USE_GMAKE)
569	@(cd ${WRKSRC}; ${GMAKE} PREFIX=${PREFIX} ${MAKE_FLAGS} ${MAKEFILE} ${ALL_TARGET})
570.else defined(USE_GMAKE)
571	@(cd ${WRKSRC}; ${MAKE} PREFIX=${PREFIX} ${MAKE_FLAGS} ${MAKEFILE} ${ALL_TARGET})
572.endif
573	@if [ -f ${SCRIPTDIR}/post-build ]; then \
574		env CURDIR=${.CURDIR} DISTDIR=${DISTDIR} WRKDIR=${WRKDIR} \
575		  WRKSRC=${WRKSRC} PATCHDIR=${PATCHDIR} SCRIPTDIR=${SCRIPTDIR} \
576		  FILESDIR=${FILESDIR} PORTSDIR=${PORTSDIR} PREFIX=${PREFIX} \
577		  DEPENDS="${DEPENDS}" \
578		sh ${SCRIPTDIR}/post-build; \
579	fi
580	@${TOUCH} ${TOUCH_FLAGS} ${BUILD_COOKIE}
581.endif
582
583.if !target(pre-patch)
584pre-patch:
585	@${DO_NADA}
586.endif
587
588.if !target(patch)
589patch: extract ${PATCH_COOKIE}
590
591${PATCH_COOKIE}:
592	@${MAKE} ${.MAKEFLAGS} pre-patch
593.if defined(PATCHFILES)
594	@${ECHO_MSG} "===>  Applying distributed patches for ${DISTNAME}"
595.if defined(PATCH_DEBUG)
596	@(cd ${DISTDIR}; \
597	  for i in ${PATCHFILES}; do \
598		${ECHO_MSG} "===>   Applying distributed patch $$i" ; \
599		case $$i in \
600			*.Z|*.gz) \
601				zcat $$i | ${PATCH} ${PATCH_DIST_ARGS}; \
602				;; \
603			*) \
604				${PATCH} ${PATCH_DIST_ARGS} < $$i; \
605				;; \
606		esac; \
607	  done)
608.else
609	@(cd ${DISTDIR}; \
610	  for i in ${PATCHFILES}; do \
611		case $$i in \
612			*.Z|*.gz) \
613				zcat $$i | ${PATCH} ${PATCH_DIST_ARGS}; \
614				;; \
615			*) \
616				${PATCH} ${PATCH_DIST_ARGS} < $$i; \
617				;; \
618		esac; \
619	  done)
620.endif
621.endif
622.if defined(PATCH_DEBUG)
623	@if [ -d ${PATCHDIR} ]; then \
624		${ECHO_MSG} "===>  Applying FreeBSD patches for ${DISTNAME}" ; \
625		for i in ${PATCHDIR}/patch-*; do \
626			${ECHO_MSG} "===>   Applying FreeBSD patch $$i" ; \
627			${PATCH} ${PATCH_ARGS} < $$i; \
628		done; \
629	fi
630	@${TOUCH} ${TOUCH_FLAGS} ${PATCH_COOKIE}
631.else
632	@if [ -d ${PATCHDIR} ]; then \
633		${ECHO_MSG} "===>  Applying FreeBSD patches for ${DISTNAME}" ; \
634		for i in ${PATCHDIR}/patch-*; \
635			do ${PATCH} ${PATCH_ARGS} < $$i; \
636		done;\
637	fi
638	@${TOUCH} ${TOUCH_FLAGS} ${PATCH_COOKIE}
639.endif
640.endif
641
642.if !target(pre-configure)
643pre-configure:
644	@${DO_NADA}
645.endif
646
647.if !target(configure)
648configure: depends patch ${CONFIGURE_COOKIE}
649
650${CONFIGURE_COOKIE}:
651	@${ECHO_MSG} "===>  Configuring for ${DISTNAME}"
652	@${MAKE} ${.MAKEFLAGS} pre-configure
653	@if [ -f ${SCRIPTDIR}/pre-configure ]; then \
654		env CURDIR=${.CURDIR} DISTDIR=${DISTDIR} WRKDIR=${WRKDIR} \
655		  WRKSRC=${WRKSRC} PATCHDIR=${PATCHDIR} SCRIPTDIR=${SCRIPTDIR} \
656		  FILESDIR=${FILESDIR} PORTSDIR=${PORTSDIR} PREFIX=${PREFIX} \
657		  DEPENDS="${DEPENDS}" \
658		sh ${SCRIPTDIR}/pre-configure; \
659	fi
660	@if [ -f ${SCRIPTDIR}/configure ]; then \
661		env CURDIR=${.CURDIR} DISTDIR=${DISTDIR} WRKDIR=${WRKDIR} \
662		  WRKSRC=${WRKSRC} PATCHDIR=${PATCHDIR} SCRIPTDIR=${SCRIPTDIR} \
663		  FILESDIR=${FILESDIR} PORTSDIR=${PORTSDIR} PREFIX=${PREFIX} \
664		  DEPENDS="${DEPENDS}" \
665		sh ${SCRIPTDIR}/configure; \
666	fi
667.if defined(HAS_CONFIGURE)
668	@(cd ${WRKSRC}; CC="${CC}" ac_cv_path_CC="${CC}" CFLAGS="${CFLAGS}" \
669	    INSTALL="/usr/bin/install -c -o ${BINOWN} -g ${BINGRP}" \
670	    INSTALL_PROGRAM="/usr/bin/install ${COPY} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE}" \
671	    ./${CONFIGURE_SCRIPT} ${CONFIGURE_ARGS})
672.endif
673.if defined(USE_IMAKE)
674.if defined(USE_GMAKE)
675	@(cd ${WRKSRC}; ${XMKMF} && ${GMAKE} Makefiles)
676.else
677	@(cd ${WRKSRC}; ${XMKMF} && ${MAKE} Makefiles)
678.endif
679.endif
680	@if [ -f ${SCRIPTDIR}/post-configure ]; then \
681		env CURDIR=${.CURDIR} DISTDIR=${DISTDIR} WRKDIR=${WRKDIR} \
682		  WRKSRC=${WRKSRC} PATCHDIR=${PATCHDIR} SCRIPTDIR=${SCRIPTDIR} \
683		  FILESDIR=${FILESDIR} PORTSDIR=${PORTSDIR} PREFIX=${PREFIX} \
684		  DEPENDS="${DEPENDS}" \
685		sh ${SCRIPTDIR}/post-configure; \
686	fi
687	@${TOUCH} ${TOUCH_FLAGS} ${CONFIGURE_COOKIE}
688.endif
689
690.if !target(pre-fetch)
691pre-fetch:
692	@${DO_NADA}
693.endif
694
695.if !target(fetch)
696fetch: pre-fetch
697	@if [ ! -d ${DISTDIR} ]; then mkdir -p ${DISTDIR}; fi
698	@(cd ${DISTDIR}; \
699	 for file in ${DISTFILES}; do \
700		if [ ! -f $$file -a ! -f `basename $$file` ]; then \
701			${ECHO_MSG} ">> $$file doesn't seem to exist on this system."; \
702			for site in ${MASTER_SITES}; do \
703			    ${ECHO_MSG} ">> Attempting to fetch from $${site}"; \
704				if ${NCFTP} ${NCFTPFLAGS} $${site}$${file}; then \
705					break; \
706				fi \
707			done; \
708			if [ ! -f $$file -a ! -f `basename $$file` ]; then \
709				${ECHO_MSG} ">> Couldn't fetch it - please try to retreive this";\
710				${ECHO_MSG} ">> port manually into ${DISTDIR} and try again."; \
711				exit 1; \
712			fi; \
713	    fi \
714	 done)
715.if defined(PATCHFILES)
716	@(cd ${DISTDIR}; \
717	 for file in ${PATCHFILES}; do \
718		if [ ! -f $$file -a ! -f `basename $$file` ]; then \
719			${ECHO_MSG} ">> $$file doesn't seem to exist on this system."; \
720			for site in ${PATCH_SITES}; do \
721			    ${ECHO_MSG} ">> Attempting to fetch from $${site}."; \
722				if ${NCFTP} ${NCFTPFLAGS} $${site}$${file}; then \
723					break; \
724				fi \
725			done; \
726			if [ ! -f $$file -a ! -f `basename $$file` ]; then \
727				${ECHO_MSG} ">> Couldn't fetch it - please try to retreive this";\
728				${ECHO_MSG} ">> port manually into ${DISTDIR} and try again."; \
729				exit 1; \
730			fi; \
731	    fi \
732	 done)
733.endif
734.endif
735
736.if !target(fetch-list)
737fetch-list:
738	@if [ ! -d ${DISTDIR} ]; then mkdir -p ${DISTDIR}; fi
739	@(cd ${DISTDIR}; \
740	 for file in ${DISTFILES}; do \
741		if [ ! -f $$file -a ! -f `basename $$file` ]; then \
742			for site in ${MASTER_SITES}; do \
743				echo -n ${NCFTP} ${NCFTPFLAGS} $${site}$${file} '||' ; \
744					break; \
745			done; \
746			echo "echo $${file} not fetched" ; \
747		fi \
748	done)
749.if defined(PATCHFILES)
750	@(cd ${DISTDIR}; \
751	 for file in ${PATCHFILES}; do \
752		if [ ! -f $$file -a ! -f `basename $$file` ]; then \
753			for site in ${PATCH_SITES}; do \
754				echo -n ${NCFTP} ${NCFTPFLAGS} $${site}$${file} '||' ; \
755					break; \
756			done; \
757			echo "echo $${file} not fetched" ; \
758		fi \
759	done)
760.endif
761.endif
762
763.if !target(makesum)
764makesum: fetch
765	@if [ ! -d ${FILESDIR} ]; then mkdir -p ${FILESDIR}; fi
766	@if [ -f ${MD5_FILE} ]; then rm -f ${MD5_FILE}; fi
767	@(cd ${DISTDIR}; \
768	for file in ${DISTFILES} ${PATCHFILES}; do \
769		${MD5} $$file >> ${MD5_FILE}; \
770	done)
771.endif
772
773.if !target(checksum)
774checksum: fetch
775	@if [ ! -f ${MD5_FILE} ]; then \
776		${ECHO_MSG} ">> No MD5 checksum file."; \
777	else \
778		(cd ${DISTDIR}; OK=""; \
779		for file in ${DISTFILES} ${PATCHFILES}; do \
780			CKSUM=`${MD5} $$file | awk '{print $$4}'`; \
781			CKSUM2=`grep "($$file)" ${MD5_FILE} | awk '{print $$4}'`; \
782			if [ "$$CKSUM2" = "" ]; then \
783				${ECHO_MSG} ">> No checksum recorded for $$file"; \
784				OK="false"; \
785			elif [ "$$CKSUM" != "$$CKSUM2" ]; then \
786				${ECHO_MSG} ">> Checksum mismatch for $$file"; \
787				exit 1; \
788			fi; \
789			done; \
790			if [ "$$OK" = "" ]; then \
791				${ECHO_MSG} "Checksums OK."; \
792			else \
793				${ECHO_MSG} "Checksums OK for files that have them."; \
794   	     fi) ; \
795	fi
796.endif
797
798.if !target(pre-extract)
799pre-extract:
800	@${DO_NADA}
801.endif
802
803.if !target(extract)
804# We need to depend on .extract_done rather than the presence of ${WRKDIR}
805# because if the user interrupts the extract in the middle (and it's often
806# a long procedure), we get tricked into thinking that we've got a good dist
807# in ${WRKDIR}.
808extract: fetch ${EXTRACT_COOKIE}
809
810${EXTRACT_COOKIE}:
811	@${MAKE} ${.MAKEFLAGS} checksum pre-extract
812	@${ECHO_MSG} "===>  Extracting for ${DISTNAME}"
813	@rm -rf ${WRKDIR}
814	@mkdir -p ${WRKDIR}
815.if defined(EXTRACT_ONLY)
816	@for file in ${EXTRACT_ONLY}; do \
817		if ! (cd ${WRKDIR};${EXTRACT_CMD} ${EXTRACT_BEFORE_ARGS} ${DISTDIR}/$$file ${EXTRACT_AFTER_ARGS});\
818		then \
819			exit 1; \
820		fi \
821	done
822.else
823	@for file in ${DISTFILES}; do \
824		if ! (cd ${WRKDIR};${EXTRACT_CMD} ${EXTRACT_BEFORE_ARGS} ${DISTDIR}/$$file ${EXTRACT_AFTER_ARGS});\
825		then \
826			exit 1; \
827		fi \
828	done
829.endif
830	@${TOUCH} ${TOUCH_FLAGS} ${EXTRACT_COOKIE}
831.endif
832
833.if !target(pre-clean)
834pre-clean:
835	@${DO_NADA}
836.endif
837
838.if !target(clean)
839clean: pre-clean
840	@${ECHO_MSG} "===>  Cleaning for ${DISTNAME}"
841	@rm -f ${EXTRACT_COOKIE} ${CONFIGURE_COOKIE} ${INSTALL_COOKIE} \
842		${BUILD_COOKIE} ${PATCH_COOKIE}
843.if !defined(NO_WRKDIR)
844	@rm -rf ${WRKDIR}
845.endif
846.endif
847
848# No pre-targets for depend or tags.  It would be silly.
849
850# Depend is generally meaningless for arbitrary ports, but if someone wants
851# one they can override this.  This is just to catch people who've gotten into
852# the habit of typing `make depend all install' as a matter of course.
853#
854.if !target(depend)
855depend:
856.endif
857
858# Same goes for tags
859.if !target(tags)
860tags:
861.endif
862