bsd.port.mk revision 10410
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.175 1995/08/18 10:06:28 asami 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/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/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# PATCH_PRFX	- Filename prefix for distribution patches (default: none)
59#				  typically ${DISTNAME}/ or foo-
60# PKGNAME		- Name of the package file to create if the DISTNAME 
61#				  isn't really relevant for the port/package
62#				  (default: ${DISTNAME}).
63# EXTRACT_ONLY	- If defined, a subset of ${DISTFILES} you want to
64#			  	  actually extract.
65# PATCHDIR 		- A directory containing any additional patches you made
66#				  to port this software to FreeBSD (default:
67#				  ${.CURDIR}/patches)
68# SCRIPTDIR 	- A directory containing any auxiliary scripts
69#				  (default: ${.CURDIR}/scripts)
70# FILESDIR 		- A directory containing any miscellaneous additional files.
71#				  (default: ${.CURDIR}/files)
72# PKGDIR 		- A direction containing any package creation files.
73#				  (default: ${.CURDIR}/pkg)
74# PKG_DBDIR		- Where package installation is recorded (default: /var/db/pkg)
75# FORCE_PKG_REGISTER - If set, it will overwrite any existing package
76#				  registration information in ${PKG_DBDIR}/${PKGNAME}.
77# NO_MTREE		- If set, will not invoke mtree from bsd.port.mk from
78#				  the "install" target.  This is the default if
79#				  USE_IMAKE or USE_X11 is set.
80#
81# NO_EXTRACT	- Use a dummy (do-nothing) extract target.
82# NO_CONFIGURE	- Use a dummy (do-nothing) configure target.
83# NO_BUILD		- Use a dummy (do-nothing) build target.
84# NO_PACKAGE	- Use a dummy (do-nothing) package target.
85# NO_INSTALL	- Use a dummy (do-nothing) install target.
86# NO_WRKSUBDIR	- Assume port unpacks directly into ${WRKDIR}.
87# NO_WRKDIR		- There's no work directory at all; port does this someplace
88#				  else.
89# NO_DEPENDS	- Don't verify build of dependencies.
90# USE_GMAKE		- Says that the port uses gmake.
91# USE_IMAKE		- Says that the port uses imake.
92# USE_X11		- Says that the port uses X11.
93# NO_INSTALL_MANPAGES - For imake ports that don't like the install.man
94#						target.
95# HAS_CONFIGURE	- Says that the port has its own configure script.
96# GNU_CONFIGURE	- Set if you are using GNU configure (optional).
97# CONFIGURE_SCRIPT - Name of configure script, defaults to 'configure'.
98# CONFIGURE_ARGS - Pass these args to configure, if ${HAS_CONFIGURE} set.
99# IS_INTERACTIVE - Set this if your port needs to interact with the user
100#				  during a build.  User can then decide to skip this port by
101#				  setting ${BATCH}, or compiling only the interactive ports
102#				  by setting ${INTERACTIVE}.
103# EXEC_DEPENDS	- A list of "prog:dir" pairs of other ports this
104#				  package depends on.  "prog" is the name of an
105#				  executable.  make will search your $PATH for it and go
106#				  into "dir" to do a "make all install" if it's not found.
107# LIB_DEPENDS	- A list of "lib:dir" pairs of other ports this package
108#				  depends on.  "lib" is the name of a shared library.
109#				  make will use "ldconfig -r" to search for the
110#				  library.  Note that lib can be any regular expression,
111#				  and you need two backslashes in front of dots (.) to
112#				  supress its special meaning (e.g., use
113#				  "foo\\.2\\.:${PORTSDIR}/utils/foo" to match "libfoo.2.*").
114# DEPENDS		- A list of other ports this package depends on being
115#				  made first.  Use this for things that don't fall into
116#				  the above two categories.
117# EXTRACT_CMD	- Command for extracting archive (default: tar).
118# EXTRACT_SUFX	- Suffix for archive names (default: .tar.gz).
119# EXTRACT_BEFORE_ARGS -
120#				  Arguments to ${EXTRACT_CMD} before filename
121#				  (default: -C ${WRKDIR} -xzf).
122# EXTRACT_AFTER_ARGS -
123#				  Arguments to ${EXTRACT_CMD} following filename
124#				  (default: none).
125#
126# NCFTP			- Full path to ncftp command if not in $PATH (default: ncftp).
127# NCFTPFLAGS    - Arguments to ${NCFTP} (default: -N).
128#
129#
130# Variables to change if you want a special behavior:
131#
132# ECHO_MSG		- Used to print all the '===>' style prompts - override this
133#				  to turn them off (default: /bin/echo).
134# IS_DEPENDED_TARGET -
135#				  The target to execute when a port is called as a
136#				  dependency (default: install).  E.g., "make fetch
137#				  IS_DEPENDED_TARGET=fetch" will fetch all the distfiles,
138#				  including those of dependencies, without actually building
139#				  any of them).
140#
141# 
142# Default targets and their behaviors:
143#
144# fetch			- Retrieves ${DISTFILES} (and ${PATCHFILES} if defined)
145#				  into ${DISTDIR} as necessary.
146# fetch-list	- Show list of files that would be retrieved by fetch
147# extract		- Unpacks ${DISTFILES} into ${WRKDIR}.
148# patch			- Apply any provided patches to the source.
149# configure		- Runs either GNU configure, one or more local configure
150#				  scripts or nothing, depending on what's available.
151# build			- Actually compile the sources.
152# install		- Install the results of a build.
153# reinstall		- Install the results of a build, ignoring "already installed"
154#				  flag.
155# package		- Create a package from an _installed_ port.
156# describe		- Try to generate a one-line description for each port for
157#				  use in INDEX files and the like.
158# checkpatch	- Do a "patch -C" instead of a "patch".  Note that it may
159#				  give incorrect results if multiple patches deal with
160#				  the same file.
161# checksum		- Use files/md5 to ensure that your distfiles are valid
162# makesum		- Generate files/md5 (only do this for your own ports!)
163#
164# Default sequence for "all" is:  fetch checksum extract patch configure build
165#
166# Please read the comments in the targets section below, you
167# should be able to use the pre-* or post-* targets/scripts
168# (which are available for every stage except checksum) or
169# override the do-* targets to do pretty much anything you want.
170#
171# NEVER override the "regular" targets unless you want to open
172# a major can of worms.
173
174.if exists(${.CURDIR}/../Makefile.inc)
175.include "${.CURDIR}/../Makefile.inc"
176.endif
177
178# These need to be absolute since we don't know how deep in the ports
179# tree we are and thus can't go relative.  They can, of course, be overridden
180# by individual Makefiles.
181PORTSDIR?=		${DESTDIR}/usr/ports
182X11BASE?=		/usr/X11R6
183DISTDIR?=		${PORTSDIR}/distfiles
184PACKAGES?=		${PORTSDIR}/packages
185.if !defined(NO_WRKDIR)
186WRKDIR?=		${.CURDIR}/work
187.else
188WRKDIR?=		${.CURDIR}
189.endif
190.if defined(NO_WRKSUBDIR)
191WRKSRC?=		${WRKDIR}
192.else
193WRKSRC?=		${WRKDIR}/${DISTNAME}
194.endif
195PATCHDIR?=		${.CURDIR}/patches
196SCRIPTDIR?=		${.CURDIR}/scripts
197FILESDIR?=		${.CURDIR}/files
198PKGDIR?=		${.CURDIR}/pkg
199.if defined(USE_IMAKE) || defined(USE_X11)
200PREFIX?=		${X11BASE}
201.else
202PREFIX?=		/usr/local
203.endif
204.if defined(USE_GMAKE)
205EXEC_DEPENDS+=               gmake:${PORTSDIR}/devel/gmake
206.endif
207
208.if exists(${PORTSDIR}/../Makefile.inc)
209.include "${PORTSDIR}/../Makefile.inc"
210.endif
211
212# Don't change these!!!  These names are built into the _TARGET_USE macro,
213# there is no way to refer to them cleanly from within the macro AFAIK.
214EXTRACT_COOKIE?=	${WRKDIR}/.extract_done
215CONFIGURE_COOKIE?=	${WRKDIR}/.configure_done
216INSTALL_COOKIE?=	${WRKDIR}/.install_done
217BUILD_COOKIE?=		${WRKDIR}/.build_done
218PATCH_COOKIE?=		${WRKDIR}/.patch_done
219PACKAGE_COOKIE?=	${WRKDIR}/.package_done
220
221# How to do nothing.  Override if you, for some strange reason, would rather
222# do something.
223DO_NADA?=		echo -n
224
225# Miscellaneous overridable commands:
226GMAKE?=			gmake
227XMKMF?=			xmkmf -a
228MD5?=			/sbin/md5
229MD5_FILE?=		${FILESDIR}/md5
230MAKE_FLAGS?=	-f
231MAKEFILE?=		Makefile
232
233NCFTP?=			/usr/bin/ncftp
234NCFTPFLAGS?=	-N
235
236TOUCH?=			/usr/bin/touch
237TOUCH_FLAGS?=	-f
238
239PATCH?=			/usr/bin/patch
240PATCH_STRIP?=	-p0
241PATCH_DIST_STRIP?=	-p0
242.if defined(PATCH_DEBUG)
243PATCH_ARGS?=	-d ${WRKSRC} -E ${PATCH_STRIP}
244PATCH_DIST_ARGS?=	-d ${WRKSRC} -E ${PATCH_DIST_STRIP}
245.else
246PATCH_ARGS?=	-d ${WRKSRC} --forward --quiet -E ${PATCH_STRIP}
247PATCH_DIST_ARGS?=	-d ${WRKSRC} --forward --quiet -E ${PATCH_DIST_STRIP}
248.endif
249
250.if defined(PATCH_CHECK_ONLY)
251PATCH_ARGS+=	-C
252PATCH_DIST_ARGS+=	-C
253.endif
254
255EXTRACT_CMD?=	/usr/bin/tar
256EXTRACT_SUFX?=	.tar.gz
257# Backwards compatability.
258.if defined(EXTRACT_ARGS)
259EXTRACT_BEFORE_ARGS?=   ${EXTRACT_ARGS}
260.else
261EXTRACT_BEFORE_ARGS?=   -xzf
262.endif
263
264# Figure out where the local mtree file is
265.if !defined(MTREE_LOCAL) && exists(/etc/mtree/BSD.local.dist)
266MTREE_LOCAL=	/etc/mtree/BSD.local.dist
267.endif
268MTREE_CMD?=	/usr/sbin/mtree
269MTREE_ARGS?=	-U -f ${MTREE_LOCAL} -d -e -p
270.if defined(USE_X11) || defined(USE_IMAKE) || !defined(MTREE_LOCAL)
271NO_MTREE=	yes
272.endif
273
274# The user can override the NO_PACKAGE by specifying this from
275# the make command line
276.if defined(FORCE_PACKAGE)
277.undef NO_PACKAGE
278.endif
279
280PKG_CMD?=		/usr/sbin/pkg_create
281.if !defined(PKG_ARGS)
282PKG_ARGS=		-v -c ${PKGDIR}/COMMENT -d ${PKGDIR}/DESCR -f ${PKGDIR}/PLIST -p ${PREFIX} -P "`${MAKE} package-depends|sort|uniq`"
283.if exists(${PKGDIR}/INSTALL)
284PKG_ARGS+=		-i ${PKGDIR}/INSTALL
285.endif
286.if exists(${PKGDIR}/DEINSTALL)
287PKG_ARGS+=		-k ${PKGDIR}/DEINSTALL
288.endif
289.if exists(${PKGDIR}/REQ)
290PKG_ARGS+=		-r ${PKGDIR}/REQ
291.endif
292.if !defined(USE_X11) && !defined(USE_IMAKE) && defined(MTREE_LOCAL)
293PKG_ARGS+=		-m ${MTREE_LOCAL}
294.endif
295.endif
296PKG_SUFX?=		.tgz
297# where pkg_add records its dirty deeds.
298PKG_DBDIR?=		/var/db/pkg
299
300# Used to print all the '===>' style prompts - override this to turn them off.
301ECHO_MSG?=		/bin/echo
302
303ALL_TARGET?=		all
304INSTALL_TARGET?=	install
305
306# If the user has this set, go to the FreeBSD respository for everything.
307.if defined(MASTER_SITE_FREEBSD)
308MASTER_SITE_OVERRIDE=  ftp://ftp.freebsd.org/pub/FreeBSD/distfiles/ 
309.endif
310
311# I guess we're in the master distribution business! :)  As we gain mirror
312# sites for distfiles, add them to this list.
313.if !defined(MASTER_SITE_OVERRIDE)
314MASTER_SITES+=	ftp://ftp.freebsd.org/pub/FreeBSD/distfiles/
315PATCH_SITES+=	ftp://ftp.freebsd.org/pub/FreeBSD/distfiles/${PATCH_PRFX}
316.else
317MASTER_SITES:=	${MASTER_SITE_OVERRIDE} ${MASTER_SITES}
318PATCH_SITES:=	${MASTER_SITE_OVERRIDE}${PATCH_PRFX} ${PATCH_SITES}
319.endif
320
321.if defined(PATCH_PRFX)
322PATCHDIST!=	/bin/echo ${PATCH_PRFX} | sed 's|^\(.*\)/$$|/\1|'
323PATCHDIST:=	${DISTDIR}${PATCHDIST}
324.else
325PATCHDIST:=	${DISTDIR}
326.endif
327
328# Derived names so that they're easily overridable.
329DISTFILES?=		${DISTNAME}${EXTRACT_SUFX}
330PKGNAME?=		${DISTNAME}
331
332# This is what is actually going to be extracted, and is overridable
333#  by user.
334EXTRACT_ONLY?=	${DISTFILES}
335
336# Documentation
337MAINTAINER?=	ports@FreeBSD.ORG
338CATEGORIES?=	orphans
339KEYWORDS+=		${CATEGORIES}
340
341# Note this has to start with a capital letter (or more accurately, it
342#  shouldn't match "[a-z]*"), see the target "delete-package-links" below.
343PKGREPOSITORYSUBDIR?=	All
344PKGREPOSITORY?=		${PACKAGES}/${PKGREPOSITORYSUBDIR}
345.if exists(${PACKAGES})
346PKGFILE?=		${PKGREPOSITORY}/${PKGNAME}${PKG_SUFX}
347.else
348PKGFILE?=		${PKGNAME}${PKG_SUFX}
349.endif
350
351CONFIGURE_SCRIPT?=	configure
352
353.if defined(GNU_CONFIGURE)
354CONFIGURE_ARGS?=	--prefix=${PREFIX}
355HAS_CONFIGURE=		yes
356.endif
357
358.MAIN: all
359
360################################################################
361# If we're in BATCH mode and the port is interactive, or we're
362# in interactive mode and the port is non-interactive, skip all
363# the important targets.  The reason we have two modes is that
364# one might want to leave a build in BATCH mode running
365# overnight, then come back in the morning and do _only_ the
366# interactive ones that required your intervention.
367#
368# This allows you to do both.
369################################################################
370
371.if (defined(IS_INTERACTIVE) && defined(BATCH)) || (!defined(IS_INTERACTIVE) && defined(INTERACTIVE))
372all:
373	@${DO_NADA}
374build:
375	@${DO_NADA}
376install:
377	@${DO_NADA}
378fetch:
379	@${DO_NADA}
380configure:
381	@${DO_NADA}
382package:
383	@${DO_NADA}
384.endif
385
386.if !target(all)
387all: build
388.endif
389
390.if !defined(IS_DEPENDED_TARGET)
391IS_DEPENDED_TARGET=	install
392.endif
393
394.if !target(is_depended)
395is_depended:	${IS_DEPENDED_TARGET}
396.endif
397
398################################################################
399# The following are used to create easy dummy targets for
400# disabling some bit of default target behavior you don't want.
401# They still check to see if the target exists, and if so don't
402# do anything, since you might want to set this globally for a
403# group of ports in a Makefile.inc, but still be able to
404# override from an individual Makefile.
405################################################################
406
407.if defined(NO_EXTRACT) && !target(extract)
408extract: checksum
409	@${TOUCH} ${TOUCH_FLAGS} ${EXTRACT_COOKIE}
410checksum: fetch
411	@${DO_NADA}
412makesum:
413	@${DO_NADA}
414.endif
415.if defined(NO_CONFIGURE) && !target(configure)
416configure: patch
417	@${TOUCH} ${TOUCH_FLAGS} ${CONFIGURE_COOKIE}
418.endif
419.if defined(NO_BUILD) && !target(build)
420build: configure
421	@${TOUCH} ${TOUCH_FLAGS} ${BUILD_COOKIE}
422.endif
423.if defined(NO_PACKAGE) && !target(package)
424package:
425	@${DO_NADA}
426.endif
427.if defined(NO_PACKAGE) && !target(repackage)
428repackage:
429	@${DO_NADA}
430.endif
431.if defined(NO_INSTALL) && !target(install)
432install: build
433	@${TOUCH} ${TOUCH_FLAGS} ${INSTALL_COOKIE}
434.endif
435.if defined(NO_PATCH) && !target(patch)
436patch: extract
437	@${TOUCH} ${TOUCH_FLAGS} ${PATCH_COOKIE}
438.endif
439
440################################################################
441# More standard targets start here.
442#
443# These are the body of the build/install framework.  If you are
444# not happy with the default actions, and you can't solve it by
445# adding pre-* or post-* targets/scripts, override these.
446################################################################
447
448# Fetch
449
450.if !target(do-fetch)
451do-fetch:
452	@if [ ! -d ${DISTDIR} ]; then /bin/mkdir -p ${DISTDIR}; fi
453	@(cd ${DISTDIR}; \
454	 for file in ${DISTFILES}; do \
455		if [ ! -f $$file -a ! -f `/usr/bin/basename $$file` ]; then \
456			${ECHO_MSG} ">> $$file doesn't seem to exist on this system."; \
457			for site in ${MASTER_SITES}; do \
458			    ${ECHO_MSG} ">> Attempting to fetch from $${site}"; \
459				if ${NCFTP} ${NCFTPFLAGS} $${site}$${file}; then \
460					break; \
461				fi \
462			done; \
463			if [ ! -f $$file -a ! -f `/usr/bin/basename $$file` ]; then \
464				${ECHO_MSG} ">> Couldn't fetch it - please try to retreive this";\
465				${ECHO_MSG} ">> port manually into ${DISTDIR} and try again."; \
466				exit 1; \
467			fi; \
468	    fi \
469	 done)
470.if defined(PATCHFILES)
471	@if [ ! -d ${PATCHDIST} ]; then /bin/mkdir -p ${PATCHDIST}; fi
472	@(cd ${PATCHDIST}; \
473	 for file in ${PATCHFILES}; do \
474		if [ ! -f $$file -a ! -f `/usr/bin/basename $$file` ]; then \
475			${ECHO_MSG} ">> $$file doesn't seem to exist on this system."; \
476			for site in ${PATCH_SITES}; do \
477			    ${ECHO_MSG} ">> Attempting to fetch from $${site}."; \
478				if ${NCFTP} ${NCFTPFLAGS} $${site}$${file}; then \
479					break; \
480				fi \
481			done; \
482			if [ ! -f $$file -a ! -f `/usr/bin/basename $$file` ]; then \
483				${ECHO_MSG} ">> Couldn't fetch it - please try to retreive this";\
484				${ECHO_MSG} ">> port manually into ${PATCHDIST} and try again."; \
485				exit 1; \
486			fi; \
487	    fi \
488	 done)
489.endif
490.endif
491
492# Extract
493
494.if !target(do-extract)
495do-extract:
496	@/bin/rm -rf ${WRKDIR}
497	@/bin/mkdir -p ${WRKDIR}
498	@for file in ${EXTRACT_ONLY}; do \
499		if ! (cd ${WRKDIR};${EXTRACT_CMD} ${EXTRACT_BEFORE_ARGS} ${DISTDIR}/$$file ${EXTRACT_AFTER_ARGS});\
500		then \
501			exit 1; \
502		fi \
503	done
504.endif
505
506# Patch
507
508.if !target(do-patch)
509do-patch:
510.if defined(PATCHFILES)
511	@${ECHO_MSG} "===>  Applying distributed patches for ${PKGNAME}"
512.if defined(PATCH_DEBUG)
513	@(cd ${PATCHDIST}; \
514	  for i in ${PATCHFILES}; do \
515		${ECHO_MSG} "===>   Applying distributed patch $$i" ; \
516		case $$i in \
517			*.Z|*.gz) \
518				/usr/bin/gzcat $$i | ${PATCH} ${PATCH_DIST_ARGS}; \
519				;; \
520			*) \
521				${PATCH} ${PATCH_DIST_ARGS} < $$i; \
522				;; \
523		esac; \
524	  done)
525.else
526	@(cd ${PATCHDIST}; \
527	  for i in ${PATCHFILES}; do \
528		case $$i in \
529			*.Z|*.gz) \
530				/usr/bin/gzcat $$i | ${PATCH} ${PATCH_DIST_ARGS}; \
531				;; \
532			*) \
533				${PATCH} ${PATCH_DIST_ARGS} < $$i; \
534				;; \
535		esac; \
536	  done)
537.endif
538.endif
539.if defined(PATCH_DEBUG)
540	@if [ -d ${PATCHDIR} ]; then \
541		${ECHO_MSG} "===>  Applying FreeBSD patches for ${PKGNAME}" ; \
542		for i in ${PATCHDIR}/patch-*; do \
543			${ECHO_MSG} "===>   Applying FreeBSD patch $$i" ; \
544			${PATCH} ${PATCH_ARGS} < $$i; \
545		done; \
546	fi
547.else
548	@if [ -d ${PATCHDIR} ]; then \
549		${ECHO_MSG} "===>  Applying FreeBSD patches for ${PKGNAME}" ; \
550		for i in ${PATCHDIR}/patch-*; \
551			do ${PATCH} ${PATCH_ARGS} < $$i; \
552		done;\
553	fi
554.endif
555.endif
556
557# Configure
558
559.if !target(do-configure)
560do-configure:
561	@if [ -f ${SCRIPTDIR}/configure ]; then \
562		/usr/bin/env CURDIR=${.CURDIR} DISTDIR=${DISTDIR} WRKDIR=${WRKDIR} \
563		  WRKSRC=${WRKSRC} PATCHDIR=${PATCHDIR} SCRIPTDIR=${SCRIPTDIR} \
564		  FILESDIR=${FILESDIR} PORTSDIR=${PORTSDIR} PREFIX=${PREFIX} \
565		  DEPENDS="${DEPENDS}" X11BASE=${X11BASE} \
566		/bin/sh ${SCRIPTDIR}/configure; \
567	fi
568.if defined(HAS_CONFIGURE)
569	@(cd ${WRKSRC}; CC="${CC}" ac_cv_path_CC="${CC}" CFLAGS="${CFLAGS}" \
570	    INSTALL="/usr/bin/install -c -o ${BINOWN} -g ${BINGRP}" \
571	    INSTALL_PROGRAM="/usr/bin/install ${COPY} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE}" \
572	    ./${CONFIGURE_SCRIPT} ${CONFIGURE_ARGS})
573.endif
574.if defined(USE_IMAKE)
575	@(cd ${WRKSRC}; ${XMKMF})
576.endif
577.endif
578
579# Build
580
581.if !target(do-build)
582do-build:
583.if defined(USE_GMAKE)
584	@(cd ${WRKSRC}; ${GMAKE} PREFIX=${PREFIX} X11BASE=${X11BASE} ${MAKE_FLAGS} ${MAKEFILE} ${ALL_TARGET})
585.else defined(USE_GMAKE)
586	@(cd ${WRKSRC}; ${MAKE} PREFIX=${PREFIX} X11BASE=${X11BASE} ${MAKE_FLAGS} ${MAKEFILE} ${ALL_TARGET})
587.endif
588.endif
589
590# Install
591
592.if !target(do-install)
593do-install:
594.if defined(USE_GMAKE)
595	@(cd ${WRKSRC}; ${GMAKE} PREFIX=${PREFIX} X11BASE=${X11BASE} ${MAKE_FLAGS} ${MAKEFILE} ${INSTALL_TARGET})
596.if defined(USE_IMAKE) && !defined(NO_INSTALL_MANPAGES)
597	@(cd ${WRKSRC}; ${GMAKE} ${MAKE_FLAGS} ${MAKEFILE} install.man)
598.endif
599.else defined(USE_GMAKE)
600	@(cd ${WRKSRC}; ${MAKE} PREFIX=${PREFIX} X11BASE=${X11BASE} ${MAKE_FLAGS} ${MAKEFILE} ${INSTALL_TARGET})
601.if defined(USE_IMAKE) && !defined(NO_INSTALL_MANPAGES)
602	@(cd ${WRKSRC}; ${MAKE} ${MAKE_FLAGS} ${MAKEFILE} install.man)
603.endif
604.endif
605.endif
606
607# Package
608
609.if !target(do-package)
610do-package:
611	@if [ -e ${PKGDIR}/PLIST ]; then \
612		${ECHO_MSG} "===>  Building package for ${PKGNAME}"; \
613		if [ -d ${PACKAGES} ]; then \
614			if [ ! -d ${PKGREPOSITORY} ]; then \
615				if ! /bin/mkdir -p ${PKGREPOSITORY}; then \
616					${ECHO_MSG} ">> Can't create directory ${PKGREPOSITORY}."; \
617					exit 1; \
618				fi; \
619			fi; \
620		fi; \
621		if ${PKG_CMD} ${PKG_ARGS} ${PKGFILE}; then \
622			if [ -d ${PACKAGES} ]; then \
623				${MAKE} ${.MAKEFLAGS} package-links; \
624			fi; \
625		else \
626			${MAKE} ${.MAKEFLAGS} delete-package; \
627			exit 1; \
628		fi; \
629	fi
630.endif
631
632# Some support rules for do-package
633
634.if !target(package-links)
635package-links:
636	@${MAKE} ${.MAKEFLAGS} delete-package-links
637	@for cat in ${CATEGORIES}; do \
638		if [ ! -d ${PACKAGES}/$$cat ]; then \
639			if ! /bin/mkdir -p ${PACKAGES}/$$cat; then \
640				${ECHO_MSG} ">> Can't create directory ${PACKAGES}/$$cat."; \
641				exit 1; \
642			fi; \
643		fi; \
644		ln -s ../${PKGREPOSITORYSUBDIR}/${PKGNAME}${PKG_SUFX} ${PACKAGES}/$$cat; \
645	done;
646.endif
647
648.if !target(delete-package-links)
649delete-package-links:
650	@/bin/rm -f ${PACKAGES}/[a-z]*/${PKGNAME}${PKG_SUFX};
651.endif
652
653.if !target(delete-package)
654delete-package:
655	@${MAKE} ${.MAKEFLAGS} delete-package-links
656	@/bin/rm -f ${PKGFILE}
657.endif
658
659################################################################
660# This is the "generic" port target, actually a macro used from the
661# six main targets.  See below for more.
662################################################################
663
664_PORT_USE: .USE
665.if make(real-install)
666.if !defined(NO_MTREE)
667	@if [ `id -u` = 0 ]; then \
668		${MTREE_CMD} ${MTREE_ARGS} ${PREFIX}/; \
669	else \
670		${ECHO_MSG} "Warning: not superuser, can't run mtree."; \
671		${ECHO_MSG} "Become root and try again to ensure correct permissions."; \
672	fi
673.endif
674.endif
675	@${MAKE} ${.MAKEFLAGS} ${.TARGET:S/^real-/pre-/}
676	@if [ -f ${SCRIPTDIR}/${.TARGET:S/^real-/pre-/} ]; then \
677		/usr/bin/env CURDIR=${.CURDIR} DISTDIR=${DISTDIR} WRKDIR=${WRKDIR} \
678		  WRKSRC=${WRKSRC} PATCHDIR=${PATCHDIR} SCRIPTDIR=${SCRIPTDIR} \
679		  FILESDIR=${FILESDIR} PORTSDIR=${PORTSDIR} PREFIX=${PREFIX} \
680		  DEPENDS="${DEPENDS}" X11BASE=${X11BASE} \
681			/bin/sh ${SCRIPTDIR}/${.TARGET:S/^real-/pre-/}; \
682	fi
683	@${MAKE} ${.MAKEFLAGS} ${.TARGET:S/^real-/do-/}
684	@${MAKE} ${.MAKEFLAGS} ${.TARGET:S/^real-/post-/}
685	@if [ -f ${SCRIPTDIR}/${.TARGET:S/^real-/post-/} ]; then \
686		/usr/bin/env CURDIR=${.CURDIR} DISTDIR=${DISTDIR} WRKDIR=${WRKDIR} \
687		  WRKSRC=${WRKSRC} PATCHDIR=${PATCHDIR} SCRIPTDIR=${SCRIPTDIR} \
688		  FILESDIR=${FILESDIR} PORTSDIR=${PORTSDIR} PREFIX=${PREFIX} \
689		  DEPENDS="${DEPENDS}" X11BASE=${X11BASE} \
690			/bin/sh ${SCRIPTDIR}/${.TARGET:S/^real-/post-/}; \
691	fi
692.if make(real-install)
693	@${MAKE} ${.MAKEFLAGS} fake-pkg
694.endif
695.if !make(real-fetch) \
696	&& (!make(real-patch) || !defined(PATCH_CHECK_ONLY)) \
697	&& (!make(real-package) || !defined(PACKAGE_NOINSTALL))
698	@${TOUCH} ${TOUCH_FLAGS} ${WRKDIR}/.${.TARGET:S/^real-//}_done
699.endif
700
701################################################################
702# Skeleton targets start here
703# 
704# You shouldn't have to change these.  Either add the pre-* or
705# post-* targets/scripts or redefine the do-* targets.  These
706# targets don't do anything other than checking for cookies and
707# call the necessary targets/scripts.
708################################################################
709
710.if !target(fetch)
711fetch: depends
712	@${MAKE} ${.MAKEFLAGS} real-fetch
713.endif
714
715.if !target(extract)
716extract: checksum ${EXTRACT_COOKIE}
717.endif
718
719.if !target(patch)
720patch: extract ${PATCH_COOKIE}
721.endif
722
723.if !target(configure)
724configure: patch ${CONFIGURE_COOKIE}
725.endif
726
727.if !target(build)
728build: configure ${BUILD_COOKIE}
729.endif
730
731.if !target(install)
732install: build ${INSTALL_COOKIE}
733.endif
734
735.if !target(package)
736package: install ${PACKAGE_COOKIE}
737.endif
738
739${EXTRACT_COOKIE}:
740	@${MAKE} ${.MAKEFLAGS} real-extract
741${PATCH_COOKIE}:
742	@${MAKE} ${.MAKEFLAGS} real-patch
743${CONFIGURE_COOKIE}:
744	@${MAKE} ${.MAKEFLAGS} real-configure
745${BUILD_COOKIE}:
746	@${MAKE} ${.MAKEFLAGS} real-build
747${INSTALL_COOKIE}:
748	@${MAKE} ${.MAKEFLAGS} real-install
749${PACKAGE_COOKIE}:
750	@${MAKE} ${.MAKEFLAGS} real-package
751
752# And call the macros
753
754real-fetch: _PORT_USE
755real-extract: _PORT_USE
756	@${ECHO_MSG} "===>  Extracting for ${PKGNAME}"
757real-patch: _PORT_USE
758	@${ECHO_MSG} "===>  Patching for ${PKGNAME}"
759real-configure: _PORT_USE
760	@${ECHO_MSG} "===>  Configuring for ${PKGNAME}"
761real-build: _PORT_USE
762	@${ECHO_MSG} "===>  Building for ${PKGNAME}"
763real-install: _PORT_USE
764	@${ECHO_MSG} "===>  Installing for ${PKGNAME}"
765real-package: _PORT_USE
766
767# Empty pre-* and post-* targets, note we can't use .if !target()
768# in the _PORT_USE macro
769
770.for name in fetch extract patch configure build install package
771
772.if !target(pre-${name})
773pre-${name}:
774	@${DO_NADA}
775.endif
776
777.if !target(post-${name})
778post-${name}:
779	@${DO_NADA}
780.endif
781
782.endfor
783
784# Checkpatch
785#
786# Special target to verify patches
787
788.if !target(checkpatch)
789checkpatch:
790	@${MAKE} PATCH_CHECK_ONLY=yes ${.MAKEFLAGS} patch
791.endif
792
793# Reinstall
794#
795# Special target to re-run install
796
797.if !target(reinstall)
798reinstall: pre-reinstall install
799
800pre-reinstall:
801	@/bin/rm -f ${INSTALL_COOKIE}
802	@/bin/rm -f ${PACKAGE_COOKIE}
803.endif
804
805################################################################
806# Some more targets supplied for users' convenience
807################################################################
808
809# Cleaning up
810
811.if !target(pre-clean)
812pre-clean:
813	@${DO_NADA}
814.endif
815
816.if !target(clean)
817clean: pre-clean
818	@${ECHO_MSG} "===>  Cleaning for ${PKGNAME}"
819	@/bin/rm -f ${EXTRACT_COOKIE} ${CONFIGURE_COOKIE} ${INSTALL_COOKIE} \
820		${BUILD_COOKIE} ${PATCH_COOKIE}
821.if defined(NO_WRKDIR)
822	@/bin/rm -f ${WRKDIR}/.*_done
823.else
824	@/bin/rm -rf ${WRKDIR}
825.endif
826.endif
827
828# Prints out a list of files to fetch (useful to do a batch fetch)
829
830.if !target(fetch-list)
831fetch-list:
832	@if [ ! -d ${DISTDIR} ]; then /bin/mkdir -p ${DISTDIR}; fi
833	@(cd ${DISTDIR}; \
834	 for file in ${DISTFILES}; do \
835		if [ ! -f $$file -a ! -f `/usr/bin/basename $$file` ]; then \
836			for site in ${MASTER_SITES}; do \
837				/bin/echo -n ${NCFTP} ${NCFTPFLAGS} $${site}$${file} '||' ; \
838					break; \
839			done; \
840			/bin/echo "echo $${file} not fetched" ; \
841		fi \
842	done)
843.if defined(PATCHFILES)
844	@(cd ${DISTDIR}; \
845	 for file in ${PATCHFILES}; do \
846		if [ ! -f $$file -a ! -f `/usr/bin/basename $$file` ]; then \
847			for site in ${PATCH_SITES}; do \
848				/bin/echo -n ${NCFTP} ${NCFTPFLAGS} $${site}$${file} ${PATCH_PRFX}$${file} '||' ; \
849					break; \
850			done; \
851			/bin/echo "echo $${file} not fetched" ; \
852		fi \
853	 done)
854.endif
855.endif
856
857# Checksumming utilities
858
859.if !target(makesum)
860makesum: fetch
861	@if [ ! -d ${FILESDIR} ]; then /bin/mkdir -p ${FILESDIR}; fi
862	@if [ -f ${MD5_FILE} ]; then /bin/rm -f ${MD5_FILE}; fi
863	@(cd ${DISTDIR}; \
864	 for file in ${DISTFILES} ${PATCHFILES:S|^|${PATCH_PRFX}|}; do \
865		${MD5} $$file >> ${MD5_FILE}; \
866	 done)
867.endif
868
869.if !target(checksum)
870checksum: fetch
871	@if [ ! -f ${MD5_FILE} ]; then \
872		${ECHO_MSG} ">> No MD5 checksum file."; \
873	else \
874		(cd ${DISTDIR}; OK=""; \
875		  for file in ${DISTFILES} ${PATCHFILES:S|^|${PATCH_PRFX}|}; do \
876			CKSUM=`${MD5} $$file | awk '{print $$4}'`; \
877			CKSUM2=`grep "($$file)" ${MD5_FILE} | awk '{print $$4}'`; \
878			if [ "$$CKSUM2" = "" ]; then \
879				${ECHO_MSG} ">> No checksum recorded for $$file"; \
880				OK="false"; \
881			elif [ "$$CKSUM" != "$$CKSUM2" ]; then \
882				${ECHO_MSG} ">> Checksum mismatch for $$file"; \
883				exit 1; \
884			fi; \
885		  done; \
886		  if [ "$$OK" = "" ]; then \
887			${ECHO_MSG} "Checksums OK."; \
888		  else \
889			${ECHO_MSG} "Checksums OK for files that have them."; \
890		  fi) ; \
891	fi
892.endif
893
894################################################################
895# The special package-building targets
896# You probably won't need to touch these
897################################################################
898
899# Nobody should want to override this unless PKGNAME is simply bogus.
900
901.if !target(package-name)
902package-name:
903.if !defined(NO_PACKAGE)
904	@/bin/echo ${PKGNAME}
905.endif
906.endif
907
908# Show (recursively) all the packages this package depends on.
909
910.if !target(package-depends)
911package-depends:
912	@for i in ${EXEC_DEPENDS} ${LIB_DEPENDS} ${DEPENDS}; do \
913		dir=`/bin/echo $$i | /usr/bin/sed -e 's/.*://'`; \
914		(cd $$dir ; ${MAKE} package-name package-depends); \
915	done
916.endif
917
918# Build a package but don't check the package cookie
919
920.if !target(repackage)
921repackage: pre-repackage package
922
923pre-repackage:
924	@/bin/rm -f ${PACKAGE_COOKIE}
925.endif
926
927# Build a package but don't check the cookie for installation, also don't
928# install package cookie
929
930.if !target(package-noinstall)
931package-noinstall:
932	@${MAKE} ${.MAKEFLAGS} PACKAGE_NOINSTALL=yes real-package
933.endif
934
935################################################################
936# Dependency checking
937################################################################
938
939.if !target(depends)
940depends: exec_depends lib_depends misc_depends
941
942exec_depends:
943.if defined(EXEC_DEPENDS)
944.if defined(NO_DEPENDS)
945# Just print out messages
946	@for i in ${EXEC_DEPENDS}; do \
947		prog=`/bin/echo $$i | /usr/bin/sed -e 's/:.*//'`; \
948		dir=`/bin/echo $$i | /usr/bin/sed -e 's/.*://'`; \
949		${ECHO_MSG} "===>  ${PKGNAME} depends on executable:  $$prog ($$dir)"; \
950	done
951.else
952	@for i in ${EXEC_DEPENDS}; do \
953		prog=`/bin/echo $$i | /usr/bin/sed -e 's/:.*//'`; \
954		dir=`/bin/echo $$i | /usr/bin/sed -e 's/.*://'`; \
955		if which -s "$$prog"; then \
956			${ECHO_MSG} "===>  ${PKGNAME} depends on executable: $$prog - found"; \
957		else \
958			${ECHO_MSG} "===>  ${PKGNAME} depends on executable: $$prog - not found"; \
959			${ECHO_MSG} "===>  Verifying build for $$prog in $$dir"; \
960			if [ ! -d "$$dir" ]; then \
961				${ECHO_MSG} ">> No directory for $$prog.  Skipping.."; \
962			else \
963				(cd $$dir; ${MAKE} ${.MAKEFLAGS} is_depended) ; \
964				${ECHO_MSG} "===>  Returning to build of ${PKGNAME}"; \
965			fi; \
966		fi; \
967	done
968.endif
969.else
970	@${DO_NADA}
971.endif
972
973lib_depends:
974.if defined(LIB_DEPENDS)
975.if defined(NO_DEPENDS)
976# Just print out messages
977	@for i in ${LIB_DEPENDS}; do \
978		lib=`/bin/echo $$i | /usr/bin/sed -e 's/:.*//'`; \
979		dir=`/bin/echo $$i | /usr/bin/sed -e 's/.*://'`; \
980		${ECHO_MSG} "===>  ${PKGNAME} depends on shared library:  $$lib ($$dir)"; \
981	done
982.else
983	@for i in ${LIB_DEPENDS}; do \
984		lib=`/bin/echo $$i | /usr/bin/sed -e 's/:.*//'`; \
985		dir=`/bin/echo $$i | /usr/bin/sed -e 's/.*://'`; \
986		if ldconfig -r | grep -q -e "-l$$lib"; then \
987			${ECHO_MSG} "===>  ${PKGNAME} depends on shared library: $$lib - found"; \
988		else \
989			${ECHO_MSG} "===>  ${PKGNAME} depends on shared library: $$lib - not found"; \
990			${ECHO_MSG} "===>  Verifying build for $$lib in $$dir"; \
991			if [ ! -d "$$dir" ]; then \
992				${ECHO_MSG} ">> No directory for $$lib.  Skipping.."; \
993			else \
994				(cd $$dir; ${MAKE} ${.MAKEFLAGS} is_depended) ; \
995				${ECHO_MSG} "===>  Returning to build of ${PKGNAME}"; \
996			fi; \
997		fi; \
998	done
999.endif
1000.else
1001	@${DO_NADA}
1002.endif
1003
1004misc_depends:
1005.if defined(DEPENDS)
1006	@${ECHO_MSG} "===>  ${PKGNAME} depends on:  ${DEPENDS}"
1007.if !defined(NO_DEPENDS)
1008	@for i in ${DEPENDS}; do \
1009		${ECHO_MSG} "===>  Verifying build for $$i"; \
1010		if [ ! -d $$i ]; then \
1011			${ECHO_MSG} ">> No directory for $$i.  Skipping.."; \
1012		else \
1013			(cd $$i; ${MAKE} ${.MAKEFLAGS} is_depended) ; \
1014		fi \
1015	done
1016	@${ECHO_MSG} "===>  Returning to build of ${PKGNAME}"
1017.endif
1018.else
1019	@${DO_NADA}
1020.endif
1021
1022.endif
1023
1024################################################################
1025# Everything after here are internal targets and really
1026# shouldn't be touched by anybody but the release engineers.
1027################################################################
1028
1029# This target generates an index entry suitable for aggregation into
1030# a large index.  Format is:
1031#
1032# distribution-name|port-path|installation-prefix|comment| \
1033#  description-file|maintainer|categories|keywords
1034#
1035.if !target(describe)
1036describe:
1037	@/bin/echo -n "${PKGNAME}|${.CURDIR}/${PKGNAME}|"
1038	@/bin/echo -n "${PREFIX}|"
1039	@if [ -f ${PKGDIR}/COMMENT ]; then \
1040		/bin/echo -n "`/bin/cat ${PKGDIR}/COMMENT`"; \
1041	else \
1042		/bin/echo -n "** No Description"; \
1043	fi
1044	@if [ -f ${PKGDIR}/DESCR ]; then \
1045		/bin/echo -n "|${PKGDIR}/DESCR"; \
1046	else \
1047		/bin/echo -n "|/dev/null"; \
1048	fi
1049	@/bin/echo -n "|${MAINTAINER}|${CATEGORIES}|${KEYWORDS}"
1050	@/bin/echo ""
1051.endif
1052
1053# Fake installation of package so that user can pkg_delete it later.
1054# Also, make sure that an installed port is recognized correctly in
1055# accordance to the @pkgdep directive in the packing lists
1056
1057.if !target(fake-pkg)
1058fake-pkg:
1059	@if [ ! -f ${PKGDIR}/PLIST -o ! -f ${PKGDIR}/COMMENT -o ! -f ${PKGDIR}/DESCR ]; then /bin/echo "** Missing package files for ${PKGNAME} - installation not recorded."; exit 1; fi
1060	@if [ ! -d ${PKG_DBDIR} ]; then /bin/rm -f ${PKG_DBDIR}; /bin/mkdir -p ${PKG_DBDIR}; fi
1061.if defined(FORCE_PKG_REGISTER)
1062	@/bin/rm -rf ${PKG_DBDIR}/${PKGNAME}
1063.endif
1064	@if [ ! -d ${PKG_DBDIR}/${PKGNAME} ]; then \
1065		${ECHO_MSG} "===>  Registering installation for ${PKGNAME}"; \
1066		/bin/mkdir -p ${PKG_DBDIR}/${PKGNAME}; \
1067		${PKG_CMD} ${PKG_ARGS} -O ${PKGFILE} > ${PKG_DBDIR}/${PKGNAME}/+CONTENTS; \
1068		/bin/cp ${PKGDIR}/DESCR ${PKG_DBDIR}/${PKGNAME}/+DESC; \
1069		/bin/cp ${PKGDIR}/COMMENT ${PKG_DBDIR}/${PKGNAME}/+COMMENT; \
1070		if [ -f ${PKGDIR}/INSTALL ]; then \
1071			/bin/cp ${PKGDIR}/INSTALL ${PKG_DBDIR}/${PKGNAME}/+INSTALL; \
1072		fi; \
1073		if [ -f ${PKGDIR}/DEINSTALL ]; then \
1074			/bin/cp ${PKGDIR}/DEINSTALL ${PKG_DBDIR}/${PKGNAME}/+DEINSTALL; \
1075		fi; \
1076		if [ -f ${PKGDIR}/REQ ]; then \
1077			/bin/cp ${PKGDIR}/REQ ${PKG_DBDIR}/${PKGNAME}/+REQ; \
1078		fi; \
1079	else \
1080		${ECHO_MSG} "===> ${PKGNAME} is already installed - perhaps an older version?"; \
1081		${ECHO_MSG} "     If so, you may wish to \`\`pkg_delete ${PKGNAME}'' and install"; \
1082		${ECHO_MSG} "     this port again to upgrade it properly."; \
1083	fi
1084.endif
1085
1086# Depend is generally meaningless for arbitrary ports, but if someone wants
1087# one they can override this.  This is just to catch people who've gotten into
1088# the habit of typing `make depend all install' as a matter of course.
1089#
1090.if !target(depend)
1091depend:
1092.endif
1093
1094# Same goes for tags
1095.if !target(tags)
1096tags:
1097.endif
1098