Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 8 Nov 1998 03:21:20 -0800 (PST)
From:      asami@cs.berkeley.edu (Satoshi Asami)
To:        ports@FreeBSD.ORG
Subject:   bsd.port.{pre,post}.mk
Message-ID:  <199811081121.DAA04535@silvia.hip.berkeley.edu>

next in thread | raw e-mail | index | archive | help
Folks,

I'm working on splitting up bsd.port.mk to two parts, one to be
included before the port Makefile (to define stuff like PREFIX and
PORTOBJFORMAT) and one to be included after it.  I think adding two
new files, bsd.port.{pre,post}.mk, which define a dummy variable and
include bsd.port.mk is the easiest way for people, since it will allow 
them to track only one file (bsd.port.mk) most of the time.  It is
also easier for me to maintain the file too.

One thing to note that it bsd.port.pre.mk actually has to be included
after some variable definitions (most notably, USE_X_PREFIX and
friends) for it to be useful, otherwise things like PREFIX will come
out wrong.  So we can't just add the file right after the leading
comments.  (Too bad, that would have been nice.)

So, your Makefile will look like this:

===
# New ports collection makefile for:	oneko
 :
MAN6=		oneko.6

.include <bsd.port.pre.mk>

.if ("${PORTOBJFORMAT}" == "elf")
OBJS=		elf.o
.else
OBJS=		aout.o
.endif

.if exists(${PREFIX}/lib/X11/config/FreeBSD.cf.orig)
laugh:
	@echo "Tee hee, you forgot to delete an .orig file!"
.endif

pre-configure:
	@echo "MANSUFFIX=6" >>${WRKSRC}/Imakefile

.include <bsd.port.post.mk>
===

The general rule is, if you need the pre.mk and post.mk separation,
put pre.mk after variable definitions (except for those that need
variables defined in pre.mk).  Then comes the rules, then post.mk.  If
you only need one, then bsd.port.mk can be used just like before,
included at the end.

Here's bsd.port.pre.mk:

===
BEFOREPORTMK=	yes
.include <bsd.port.mk>
.undef BEFOREPORTMK
===

and here's bsd.port.post.mk:

===
AFTERPORTMK=	yes
.include <bsd.port.mk>
.undef AFTERPORTMK
===

Here's a patch to bsd.port.mk itself and Makefile.  I had to move some
stuff around, but basically all it does is to surround the first part
with ".if !defined(AFTERPORTMK)" and the rest with ".if !defined(BEFOREPORTMK)".

===
Index: Makefile
===================================================================
RCS file: /usr/cvs/src/share/mk/Makefile,v
retrieving revision 1.13.2.3
diff -u -r1.13.2.3 Makefile
--- Makefile	1998/05/30 22:40:58	1.13.2.3
+++ Makefile	1998/11/08 10:54:35
@@ -4,7 +4,8 @@
 FILES=	bsd.README
 FILES+=	bsd.dep.mk bsd.doc.mk bsd.info.mk bsd.kern.mk bsd.kmod.mk
 FILES+=	bsd.lib.mk bsd.libnames.mk bsd.man.mk bsd.obj.mk bsd.own.mk
-FILES+=	bsd.port.mk bsd.port.subdir.mk bsd.prog.mk bsd.sgml.mk bsd.subdir.mk
+FILES+=	bsd.port.mk bsd.port.post.mk  bsd.port.pre.mk bsd.port.subdir.mk
+FILES+=	bsd.prog.mk bsd.sgml.mk bsd.subdir.mk
 FILES+=	sys.mk
 NOOBJ=	noobj
 
Index: bsd.port.mk
===================================================================
RCS file: /usr/cvs/src/share/mk/bsd.port.mk,v
retrieving revision 1.227.2.59
diff -u -r1.227.2.59 bsd.port.mk
--- bsd.port.mk	1998/11/08 10:30:53	1.227.2.59
+++ bsd.port.mk	1998/11/08 11:14:03
@@ -36,6 +36,7 @@
 #				  makefile is being used on.  Automatically set to
 #				  "FreeBSD," "NetBSD," or "OpenBSD" as appropriate.
 # OSREL			- The release version (numeric) of the operating system.
+# OSVER			- __FreeBSD_version.
 # PORTOBJFORMAT	- The object format ("aout" or "elf").
 #
 # These variables are used to identify your port.
@@ -393,6 +394,9 @@
 #				  a different checksum and you intend to verify if
 #				  the port still works with it.
 
+# Start of pre-makefile section.
+.if !defined(AFTERPORTMK)
+
 # Get the architecture
 ARCH!=	uname -m
 
@@ -401,14 +405,12 @@
 
 # Get the operating system revision
 OSREL!=	uname -r | sed -e 's/[-(].*//'
-PLIST_SUB+=	OSREL=${OSREL}
+
+# Get __FreeBSD_version
+OSVER!=	sysctl -n kern.osreldate
 
 # Get the object format.
 PORTOBJFORMAT!=	test -x /usr/bin/objformat && /usr/bin/objformat || echo aout
-CONFIGURE_ENV+=	PORTOBJFORMAT=${PORTOBJFORMAT}
-SCRIPTS_ENV+=	PORTOBJFORMAT=${PORTOBJFORMAT}
-MAKE_ENV+=		PORTOBJFORMAT=${PORTOBJFORMAT}
-PLIST_SUB+=		PORTOBJFORMAT=${PORTOBJFORMAT}
 
 # If they exist, include Makefile.inc, then architecture/operating
 # system specific Makefiles, then local Makefile.local.
@@ -494,6 +496,25 @@
 PKGDIR?=		${.CURDIR}/pkg
 .endif
 
+.if defined(USE_X_PREFIX)
+PREFIX?=		${X11BASE}
+.else
+PREFIX?=		${LOCALBASE}
+.endif
+
+.endif
+# End of pre-makefile section.
+
+# Start of post-makefile section.
+.if !defined(BEFOREPORTMK)
+
+PLIST_SUB+=	OSREL=${OSREL}
+
+CONFIGURE_ENV+=	PORTOBJFORMAT=${PORTOBJFORMAT}
+SCRIPTS_ENV+=	PORTOBJFORMAT=${PORTOBJFORMAT}
+MAKE_ENV+=		PORTOBJFORMAT=${PORTOBJFORMAT}
+PLIST_SUB+=		PORTOBJFORMAT=${PORTOBJFORMAT}
+
 .if defined(MANCOMPRESSED)
 .if ${MANCOMPRESSED} != yes && ${MANCOMPRESSED} != no && \
 	${MANCOMPRESSED} != maybe
@@ -515,11 +536,6 @@
 .if defined(USE_X_PREFIX)
 USE_XLIB=		yes
 .endif
-.if defined(USE_X_PREFIX)
-PREFIX?=		${X11BASE}
-.else
-PREFIX?=		${LOCALBASE}
-.endif
 
 .if defined(USE_GMAKE)
 BUILD_DEPENDS+=		gmake:${PORTSDIR}/devel/gmake
@@ -2189,3 +2210,6 @@
 .if !target(tags)
 tags:
 .endif
+
+.endif
+# End of post-makefile section.
===

I left most of the pathname definitions in pre.mk, as I thought
exists() check is what they are needed for, although I'm not sure if
PKGDIR and stuff are that useful that early.  As for non-pathname
stuff, only these five are defined in pre.mk:

===
ARCH!=	uname -m
OPSYS!=	uname -s
OSREL!=	uname -r | sed -e 's/[-(].*//'
OSVER!=	sysctl -n kern.osreldate
PORTOBJFORMAT!=	test -x /usr/bin/objformat && /usr/bin/objformat || echo aout
===

OSVER is new, and can be used for numeric comparisons.

I'm not so sure about putting pre.mk right in the middle.  Since it
only needs USE_IMAKE and USE_X_PREFIX, maybe we can ask people to put
it right at the top after those.  Something like:

===
# New ports collection makefile for:	oneko
# Version required:	1.2
# Date created:		5 December 1994
# Whom:			asami
#
# $Id: Makefile,v 1.11 1998/10/04 18:11:54 jseger Exp $
#
USE_IMAKE=	yes
.include <bsd.port.pre.mk>
 :
(everything else)
 :
.include <bsd.port.post.mk>
===

This looks pretty ugly though.  Also it means USE_IMAKE/USE_X_PREFIX
could appear in two different places, depending on whether the port
needs pre/post.mk or just bsd.port.mk.  I think putting it in the
middle is fine, as there really aren't that many ports that need the
split.

Any ideas?

Satoshi

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199811081121.DAA04535>