bsd.port.mk revision 7710
153343Simp#-*- mode: Fundamental; tab-width: 4; -*-
267276Sjon#
367276Sjon#	bsd.port.mk - 940820 Jordan K. Hubbard.
453343Simp#	This file is in the public domain.
553343Simp#
653343Simp# $Id: bsd.port.mk,v 1.133 1995/04/09 09:59:42 asami Exp $
753343Simp#
853343Simp# Please view me with 4 column tabs!
967276Sjon
1067276Sjon
1153343Simp# Supported Variables and their behaviors:
1267276Sjon#
1367276Sjon# Variables that typically apply to all ports:
1467276Sjon# 
1553343Simp# PORTSDIR		- The root of the ports tree (default: /usr/ports).
1667276Sjon# DISTDIR 		- Where to get gzip'd, tarballed copies of original sources
1767276Sjon#				  (default: ${PORTSDIR}/distfiles).
1867276Sjon# PREFIX		- Where to install things in general (default: /usr/local).
1967276Sjon# MASTER_SITES	- Primary location(s) for distribution files if not found
2067276Sjon#				  locally (default:
2167276Sjon#				   ftp://ftp.freebsd.org/pub/FreeBSD/ports/distfiles)
2267276Sjon# PATCH_SITES	- Primary location(s) for distributed patch files
2367276Sjon#				  (see PATCHFILES below) if not found locally (default:
2467276Sjon#				   ftp://ftp.freebsd.org/pub/FreeBSD/ports/distfiles)
2567276Sjon#
2667276Sjon# MASTER_SITE_OVERRIDE - If set, override the MASTER_SITES setting with this
2753343Simp#				  value.
2867276Sjon# MASTER_SITE_FREEBSD - If set, only use the FreeBSD master repository for
2953343Simp#				  MASTER_SITES.
3053343Simp# PACKAGES		- A top level directory where all packages go (rather than
3167276Sjon#				  going locally to each port). (default: ${PORTSDIR}/packages).
3267276Sjon# GMAKE			- Set to path of GNU make if not in $PATH (default: gmake).
3367276Sjon# XMKMF			- Set to path of `xmkmf' if not in $PATH (default: xmkmf -a ).
3467276Sjon# MAINTAINER	- The e-mail address of the contact person for this port
3591355Simp#				  (default: ports@FreeBSD.ORG).
3691355Simp# CATEGORIES	- A list of descriptive categories into which this port falls
3791355Simp#				  (default: orphans).
3891355Simp# KEYWORDS		- A list of descriptive keywords that might index well for this
3991355Simp#				  port (default: orphans).
4053343Simp#
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}
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.if !target(pre-package)
420pre-package:
421	@${DO_NADA}
422.endif
423
424.if !target(package)
425package: pre-package
426	@if [ -e ${PKGDIR}/PLIST ]; then \
427		${ECHO_MSG} "===>  Building package for ${DISTNAME}"; \
428		if [ -d ${PACKAGES} ]; then \
429			if [ ! -d ${PKGREPOSITORY} ]; then \
430				if ! mkdir -p ${PKGREPOSITORY}; then \
431					${ECHO_MSG} ">> Can't create directory ${PKGREPOSITORY}."; \
432					exit 1; \
433				fi; \
434			fi; \
435		fi; \
436		${PKG_CMD} ${PKG_ARGS} ${PKGFILE}; \
437		if [ -d ${PACKAGES} ]; then \
438			rm -f ${PACKAGES}/*/${PKGNAME}${PKG_SUFX}; \
439			for cat in ${CATEGORIES}; do \
440				if [ ! -d ${PACKAGES}/$$cat ]; then \
441					if ! mkdir -p ${PACKAGES}/$$cat; then \
442						${ECHO_MSG} ">> Can't create directory ${PACKAGES}/$$cat."; \
443						exit 1; \
444					fi; \
445				fi; \
446				ln -s ../${PKGREPOSITORYSUBDIR}/${PKGNAME}${PKG_SUFX} ${PACKAGES}/$$cat; \
447			done; \
448		fi; \
449	fi
450.endif
451
452.if !target(depends)
453depends: exec_depends lib_depends misc_depends
454
455exec_depends:
456.if defined(EXEC_DEPENDS)
457.if defined(NO_DEPENDS)
458# Just print out messages
459	@for i in ${EXEC_DEPENDS}; do \
460		prog=`echo $$i | sed -e 's/:.*//'`; \
461		dir=`echo $$i | sed -e 's/.*://'`; \
462		${ECHO_MSG} "===>  ${DISTNAME} depends on executable:  $$prog ($$dir)"; \
463	done
464.else
465	@for i in ${EXEC_DEPENDS}; do \
466		prog=`echo $$i | sed -e 's/:.*//'`; \
467		dir=`echo $$i | sed -e 's/.*://'`; \
468		if which -s "$$prog"; then \
469			${ECHO_MSG} "===>  ${DISTNAME} depends on executable: $$prog - found"; \
470		else \
471			${ECHO_MSG} "===>  ${DISTNAME} depends on executable: $$prog - not found"; \
472			${ECHO_MSG} "===>  Verifying build for $$prog in $$dir"; \
473			if [ ! -d "$$dir" ]; then \
474				${ECHO_MSG} ">> No directory for $$prog.  Skipping.."; \
475			else \
476				(cd $$dir; ${MAKE} ${.MAKEFLAGS} is_depended) ; \
477				${ECHO_MSG} "===>  Returning to build of ${DISTNAME}"; \
478			fi; \
479		fi; \
480	done
481.endif
482.else
483	@${DO_NADA}
484.endif
485
486lib_depends:
487.if defined(LIB_DEPENDS)
488.if defined(NO_DEPENDS)
489# Just print out messages
490	@for i in ${LIB_DEPENDS}; do \
491		lib=`echo $$i | sed -e 's/:.*//'`; \
492		dir=`echo $$i | sed -e 's/.*://'`; \
493		${ECHO_MSG} "===>  ${DISTNAME} depends on shared library:  $$lib ($$dir)"; \
494	done
495.else
496	@for i in ${LIB_DEPENDS}; do \
497		lib=`echo $$i | sed -e 's/:.*//'`; \
498		dir=`echo $$i | sed -e 's/.*://'`; \
499		if ldconfig -r | grep -q -e "-l$$lib"; then \
500			${ECHO_MSG} "===>  ${DISTNAME} depends on shared library: $$lib - found"; \
501		else \
502			${ECHO_MSG} "===>  ${DISTNAME} depends on shared library: $$lib - not found"; \
503			${ECHO_MSG} "===>  Verifying build for $$lib in $$dir"; \
504			if [ ! -d "$$dir" ]; then \
505				${ECHO_MSG} ">> No directory for $$lib.  Skipping.."; \
506			else \
507				(cd $$dir; ${MAKE} ${.MAKEFLAGS} is_depended) ; \
508				${ECHO_MSG} "===>  Returning to build of ${DISTNAME}"; \
509			fi; \
510		fi; \
511	done
512.endif
513.else
514	@${DO_NADA}
515.endif
516
517misc_depends:
518.if defined(DEPENDS)
519	@${ECHO_MSG} "===>  ${DISTNAME} depends on:  ${DEPENDS}"
520.if !defined(NO_DEPENDS)
521	@for i in ${DEPENDS}; do \
522		${ECHO_MSG} "===>  Verifying build for $$i"; \
523		if [ ! -d $$i ]; then \
524			${ECHO_MSG} ">> No directory for $$i.  Skipping.."; \
525		else \
526			(cd $$i; ${MAKE} ${.MAKEFLAGS} is_depended) ; \
527		fi \
528	done
529	@${ECHO_MSG} "===>  Returning to build of ${DISTNAME}"
530.endif
531.else
532	@${DO_NADA}
533.endif
534
535.endif
536
537.if !target(pre-build)
538pre-build:
539	@${DO_NADA}
540.endif
541
542.if !target(build)
543build: configure ${BUILD_COOKIE}
544
545${BUILD_COOKIE}:
546	@${ECHO_MSG} "===>  Building for ${DISTNAME}"
547	@${MAKE} ${.MAKEFLAGS} pre-build
548.if defined(USE_GMAKE)
549	@(cd ${WRKSRC}; ${GMAKE} PREFIX=${PREFIX} ${MAKE_FLAGS} ${MAKEFILE} ${ALL_TARGET})
550.else defined(USE_GMAKE)
551	@(cd ${WRKSRC}; ${MAKE} PREFIX=${PREFIX} ${MAKE_FLAGS} ${MAKEFILE} ${ALL_TARGET})
552.endif
553	@if [ -f ${SCRIPTDIR}/post-build ]; then \
554		env CURDIR=${.CURDIR} DISTDIR=${DISTDIR} WRKDIR=${WRKDIR} \
555		  WRKSRC=${WRKSRC} PATCHDIR=${PATCHDIR} SCRIPTDIR=${SCRIPTDIR} \
556		  FILESDIR=${FILESDIR} PORTSDIR=${PORTSDIR} PREFIX=${PREFIX} \
557		  DEPENDS="${DEPENDS}" \
558		sh ${SCRIPTDIR}/post-build; \
559	fi
560	@${TOUCH} ${TOUCH_FLAGS} ${BUILD_COOKIE}
561.endif
562
563.if !target(pre-patch)
564pre-patch:
565	@${DO_NADA}
566.endif
567
568.if !target(patch)
569patch: extract ${PATCH_COOKIE}
570
571${PATCH_COOKIE}:
572	@${MAKE} ${.MAKEFLAGS} pre-patch
573.if defined(PATCHFILES)
574	@${ECHO_MSG} "===>  Applying distributed patches for ${DISTNAME}"
575.if defined(PATCH_DEBUG)
576	@(cd ${DISTDIR}; \
577	  for i in ${PATCHFILES}; do \
578		${ECHO_MSG} "===>   Applying distributed patch $$i" ; \
579		case $$i in \
580			*.Z|*.gz) \
581				zcat $$i | ${PATCH} ${PATCH_DIST_ARGS}; \
582				;; \
583			*) \
584				${PATCH} ${PATCH_DIST_ARGS} < $$i; \
585				;; \
586		esac; \
587	  done)
588.else
589	@(cd ${DISTDIR}; \
590	  for i in ${PATCHFILES}; do \
591		case $$i in \
592			*.Z|*.gz) \
593				zcat $$i | ${PATCH} ${PATCH_DIST_ARGS}; \
594				;; \
595			*) \
596				${PATCH} ${PATCH_DIST_ARGS} < $$i; \
597				;; \
598		esac; \
599	  done)
600.endif
601.endif
602.if defined(PATCH_DEBUG)
603	@if [ -d ${PATCHDIR} ]; then \
604		${ECHO_MSG} "===>  Applying FreeBSD patches for ${DISTNAME}" ; \
605		for i in ${PATCHDIR}/patch-*; do \
606			${ECHO_MSG} "===>   Applying FreeBSD patch $$i" ; \
607			${PATCH} ${PATCH_ARGS} < $$i; \
608		done; \
609	fi
610	@${TOUCH} ${TOUCH_FLAGS} ${PATCH_COOKIE}
611.else
612	@if [ -d ${PATCHDIR} ]; then \
613		${ECHO_MSG} "===>  Applying FreeBSD patches for ${DISTNAME}" ; \
614		for i in ${PATCHDIR}/patch-*; \
615			do ${PATCH} ${PATCH_ARGS} < $$i; \
616		done;\
617	fi
618	@${TOUCH} ${TOUCH_FLAGS} ${PATCH_COOKIE}
619.endif
620.endif
621
622.if !target(pre-configure)
623pre-configure:
624	@${DO_NADA}
625.endif
626
627.if !target(configure)
628configure: depends patch ${CONFIGURE_COOKIE}
629
630${CONFIGURE_COOKIE}:
631	@${ECHO_MSG} "===>  Configuring for ${DISTNAME}"
632	@${MAKE} ${.MAKEFLAGS} pre-configure
633	@if [ -f ${SCRIPTDIR}/pre-configure ]; then \
634		env CURDIR=${.CURDIR} DISTDIR=${DISTDIR} WRKDIR=${WRKDIR} \
635		  WRKSRC=${WRKSRC} PATCHDIR=${PATCHDIR} SCRIPTDIR=${SCRIPTDIR} \
636		  FILESDIR=${FILESDIR} PORTSDIR=${PORTSDIR} PREFIX=${PREFIX} \
637		  DEPENDS="${DEPENDS}" \
638		sh ${SCRIPTDIR}/pre-configure; \
639	fi
640	@if [ -f ${SCRIPTDIR}/configure ]; then \
641		env CURDIR=${.CURDIR} DISTDIR=${DISTDIR} WRKDIR=${WRKDIR} \
642		  WRKSRC=${WRKSRC} PATCHDIR=${PATCHDIR} SCRIPTDIR=${SCRIPTDIR} \
643		  FILESDIR=${FILESDIR} PORTSDIR=${PORTSDIR} PREFIX=${PREFIX} \
644		  DEPENDS="${DEPENDS}" \
645		sh ${SCRIPTDIR}/configure; \
646	fi
647.if defined(HAS_CONFIGURE)
648	@(cd ${WRKSRC}; CC="${CC}" ac_cv_path_CC="${CC}" CFLAGS="${CFLAGS}" \
649	    INSTALL="/usr/bin/install -c -o ${BINOWN} -g ${BINGRP}" \
650	    INSTALL_PROGRAM="/usr/bin/install ${COPY} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE}" \
651	    ./${CONFIGURE_SCRIPT} ${CONFIGURE_ARGS})
652.endif
653.if defined(USE_IMAKE)
654.if defined(USE_GMAKE)
655	@(cd ${WRKSRC}; ${XMKMF} && ${GMAKE} Makefiles)
656.else
657	@(cd ${WRKSRC}; ${XMKMF} && ${MAKE} Makefiles)
658.endif
659.endif
660	@if [ -f ${SCRIPTDIR}/post-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}/post-configure; \
666	fi
667	@${TOUCH} ${TOUCH_FLAGS} ${CONFIGURE_COOKIE}
668.endif
669
670.if !target(pre-fetch)
671pre-fetch:
672	@${DO_NADA}
673.endif
674
675.if !target(fetch)
676fetch: pre-fetch
677	@if [ ! -d ${DISTDIR} ]; then mkdir -p ${DISTDIR}; fi
678	@(cd ${DISTDIR}; \
679	 for file in ${DISTFILES}; do \
680		if [ ! -f $$file -a ! -f `basename $$file` ]; then \
681			${ECHO_MSG} ">> $$file doesn't seem to exist on this system."; \
682			for site in ${MASTER_SITES}; do \
683			    ${ECHO_MSG} ">> Attempting to fetch from $${site}"; \
684				if ${NCFTP} ${NCFTPFLAGS} $${site}$${file}; then \
685					break; \
686				fi \
687			done; \
688			if [ ! -f $$file -a ! -f `basename $$file` ]; then \
689				${ECHO_MSG} ">> Couldn't fetch it - please try to retreive this";\
690				${ECHO_MSG} ">> port manually into ${DISTDIR} and try again."; \
691				exit 1; \
692			fi; \
693	    fi \
694	 done)
695.if defined(PATCHFILES)
696	@(cd ${DISTDIR}; \
697	 for file in ${PATCHFILES}; do \
698		if [ ! -f $$file -a ! -f `basename $$file` ]; then \
699			${ECHO_MSG} ">> $$file doesn't seem to exist on this system."; \
700			for site in ${PATCH_SITES}; do \
701			    ${ECHO_MSG} ">> Attempting to fetch from $${site}."; \
702				if ${NCFTP} ${NCFTPFLAGS} $${site}$${file}; then \
703					break; \
704				fi \
705			done; \
706			if [ ! -f $$file -a ! -f `basename $$file` ]; then \
707				${ECHO_MSG} ">> Couldn't fetch it - please try to retreive this";\
708				${ECHO_MSG} ">> port manually into ${DISTDIR} and try again."; \
709				exit 1; \
710			fi; \
711	    fi \
712	 done)
713.endif
714.endif
715
716.if !target(fetch-list)
717fetch-list:
718	@if [ ! -d ${DISTDIR} ]; then mkdir -p ${DISTDIR}; fi
719	@(cd ${DISTDIR}; \
720	 for file in ${DISTFILES}; do \
721		if [ ! -f $$file -a ! -f `basename $$file` ]; then \
722			for site in ${MASTER_SITES}; do \
723				echo -n ${NCFTP} ${NCFTPFLAGS} $${site}$${file} '||' ; \
724					break; \
725			done; \
726			echo "echo $${file} not fetched" ; \
727		fi \
728	done)
729.if defined(PATCHFILES)
730	@(cd ${DISTDIR}; \
731	 for file in ${PATCHFILES}; do \
732		if [ ! -f $$file -a ! -f `basename $$file` ]; then \
733			for site in ${PATCH_SITES}; do \
734				echo -n ${NCFTP} ${NCFTPFLAGS} $${site}$${file} '||' ; \
735					break; \
736			done; \
737			echo "echo $${file} not fetched" ; \
738		fi \
739	done)
740.endif
741.endif
742
743.if !target(makesum)
744makesum: fetch
745	@if [ ! -d ${FILESDIR} ]; then mkdir -p ${FILESDIR}; fi
746	@if [ -f ${MD5_FILE} ]; then rm -f ${MD5_FILE}; fi
747	@(cd ${DISTDIR}; \
748	for file in ${DISTFILES} ${PATCHFILES}; do \
749		${MD5} $$file >> ${MD5_FILE}; \
750	done)
751.endif
752
753.if !target(checksum)
754checksum: fetch
755	@if [ ! -f ${MD5_FILE} ]; then \
756		${ECHO_MSG} ">> No MD5 checksum file."; \
757	else \
758		(cd ${DISTDIR}; OK=""; \
759		for file in ${DISTFILES} ${PATCHFILES}; do \
760			CKSUM=`${MD5} $$file | awk '{print $$4}'`; \
761			CKSUM2=`grep "($$file)" ${MD5_FILE} | awk '{print $$4}'`; \
762			if [ "$$CKSUM2" = "" ]; then \
763				${ECHO_MSG} ">> No checksum recorded for $$file"; \
764				OK="false"; \
765			elif [ "$$CKSUM" != "$$CKSUM2" ]; then \
766				${ECHO_MSG} ">> Checksum mismatch for $$file"; \
767				exit 1; \
768			fi; \
769			done; \
770			if [ "$$OK" = "" ]; then \
771				${ECHO_MSG} "Checksums OK."; \
772			else \
773				${ECHO_MSG} "Checksums OK for files that have them."; \
774   	     fi) ; \
775	fi
776.endif
777
778.if !target(pre-extract)
779pre-extract:
780	@${DO_NADA}
781.endif
782
783.if !target(extract)
784# We need to depend on .extract_done rather than the presence of ${WRKDIR}
785# because if the user interrupts the extract in the middle (and it's often
786# a long procedure), we get tricked into thinking that we've got a good dist
787# in ${WRKDIR}.
788extract: fetch ${EXTRACT_COOKIE}
789
790${EXTRACT_COOKIE}:
791	@${MAKE} ${.MAKEFLAGS} checksum pre-extract
792	@${ECHO_MSG} "===>  Extracting for ${DISTNAME}"
793	@rm -rf ${WRKDIR}
794	@mkdir -p ${WRKDIR}
795.if defined(EXTRACT_ONLY)
796	@for file in ${EXTRACT_ONLY}; do \
797		if ! (cd ${WRKDIR};${EXTRACT_CMD} ${EXTRACT_BEFORE_ARGS} ${DISTDIR}/$$file ${EXTRACT_AFTER_ARGS});\
798		then \
799			exit 1; \
800		fi \
801	done
802.else
803	@for file in ${DISTFILES}; do \
804		if ! (cd ${WRKDIR};${EXTRACT_CMD} ${EXTRACT_BEFORE_ARGS} ${DISTDIR}/$$file ${EXTRACT_AFTER_ARGS});\
805		then \
806			exit 1; \
807		fi \
808	done
809.endif
810	@${TOUCH} ${TOUCH_FLAGS} ${EXTRACT_COOKIE}
811.endif
812
813.if !target(pre-clean)
814pre-clean:
815	@${DO_NADA}
816.endif
817
818.if !target(clean)
819clean: pre-clean
820	@${ECHO_MSG} "===>  Cleaning for ${DISTNAME}"
821	@rm -f ${EXTRACT_COOKIE} ${CONFIGURE_COOKIE} ${INSTALL_COOKIE} \
822		${BUILD_COOKIE} ${PATCH_COOKIE}
823.if !defined(NO_WRKDIR)
824	@rm -rf ${WRKDIR}
825.endif
826.endif
827
828# No pre-targets for depend or tags.  It would be silly.
829
830# Depend is generally meaningless for arbitrary ports, but if someone wants
831# one they can override this.  This is just to catch people who've gotten into
832# the habit of typing `make depend all install' as a matter of course.
833#
834.if !target(depend)
835depend:
836.endif
837
838# Same goes for tags
839.if !target(tags)
840tags:
841.endif
842