Subject: making cpuflags ${PREFIX}-aware
To: None <tech-pkg@netbsd.org>
From: Karl Hammerschmidt <stuffynose@earthlink.net>
List: tech-pkg
Date: 03/14/2004 14:37:00
I noticed that cpuflags doesn't work if ${LOCALBASE} is set to something
other than /usr/pkg.

It installs fine, but it still looks for it's files in /usr/pkg, and 
the man page
gives the wrong locations.

I was able to overcome both issues (on my system) with these changes:

I changed the references to /usr/pkg in cpuflags.mk and cpuflags.1 to
@PREFIX@, and I added a sed routine to the Makefile that finds all of 
the
references to @PREFIX@ and replaces them with ${PREFIX}.

I'd really like it if somebody would look at the diffs and tell me what 
they
think.

(or if someone wants them in some other format, I'd be happy to oblige)

Here they are the diffs. I hope they're useful.

#### The diff for Makefile ####

--- Makefile.orig	Sun Mar 14 11:24:39 2004
+++ Makefile	Sun Mar 14 11:24:24 2004
@@ -15,12 +15,24 @@
  USE_LANGUAGES=	# empty
  NO_CHECKSUM=	yes
  NO_CONFIGURE=	yes
-NO_BUILD=	yes
+
+do-extract:
+	@${MKDIR} ${WRKSRC}/src
+.for FILE in cpuflags.1 cpuflags.mk
+	${CP} ${FILESDIR}/${FILE} ${WRKSRC}/src/${FILE}
+.endfor
+
+do-build:
+.for FILE in cpuflags.1 cpuflags.mk
+	${SED} -e 's|@PREFIX@|${PREFIX}|g'	\
+		< ${WRKSRC}/src/${FILE}		\
+		> ${WRKSRC}/${FILE}
+.endfor

  do-install:
  	${INSTALL_SCRIPT} ${FILESDIR}/cpuflags.${OPSYS} ${PREFIX}/bin/cpuflags
-	${INSTALL_DATA} ${FILESDIR}/cpuflags.mk ${PREFIX}/share/mk/cpuflags.mk
+	${INSTALL_DATA} ${WRKSRC}/cpuflags.mk ${PREFIX}/share/mk/cpuflags.mk
  	${INSTALL_DATA} ${FILESDIR}/optimize_gcc.mk 
${PREFIX}/share/mk/optimize_gcc.mk
-	${INSTALL_MAN} ${FILESDIR}/cpuflags.1 ${PREFIX}/man/man1/cpuflags.1
+	${INSTALL_MAN} ${WRKSRC}/cpuflags.1 ${PREFIX}/man/man1/cpuflags.1

  .include "../../mk/bsd.pkg.mk"

#### And cpuflags.mk ####

--- cpuflags.mk.orig	Sun Mar 14 11:26:41 2004
+++ cpuflags.mk	Sun Mar 14 11:26:19 2004
@@ -14,9 +14,9 @@

  .ifndef CPU_FLAGS
  . if defined(BSD_PKG_MK) || ${USETOOLS:Uyes} == "no"
-CPU_FLAGS!=/usr/pkg/bin/cpuflags ${CC}
+CPU_FLAGS!=@PREFIX@/bin/cpuflags ${CC}
  . else
-CPU_FLAGS!=/usr/pkg/bin/cpuflags
+CPU_FLAGS!=@PREFIX@/bin/cpuflags
  . endif
  .endif

#### And the one for cpuflags.1 ####

--- cpuflags.1.orig	Sun Mar 14 11:27:22 2004
+++ cpuflags.1	Sun Mar 14 11:27:04 2004
@@ -23,7 +23,7 @@
  found in the path.
  .Sh ENVIRONMENT
  The makefile fragment
-.Pa /usr/pkg/share/mk/cpuflags.mk
+.Pa @PREFIX@/share/mk/cpuflags.mk
  will set the following
  .Xr make 1
  variables, plus add CPU_FLAGS and CPU_DIR to .MAKEFLAGS for sub-makes.
@@ -39,12 +39,12 @@
  Has CPU_FLAGS appended
  .El
  .Sh FILES
-.Bl -tag -width /usr/pkg/share/mk/optimize_gcc.mk -compact
-.It /usr/pkg/share/mk/cpuflags.mk
+.Bl -tag -width @PREFIX@/share/mk/optimize_gcc.mk -compact
+.It @PREFIX@/share/mk/cpuflags.mk
  Set appropriate compiler flags based on the output from
  .Nm .
  Suitable for inclusion in /etc/mk.conf
-.It /usr/pkg/share/mk/optimize_gcc.mk
+.It @PREFIX@/share/mk/optimize_gcc.mk
  Attempt to set additional -mXXX gcc flags based on gcc version and 
packages
  being compiled. Note: This is experimental and not supported.
  .El
@@ -56,7 +56,7 @@
  kernel or userland by adding the following to
  .Pa /etc/mk.conf :
  .Bd -literal -offset indent
- .sinclude "/usr/pkg/share/mk/cpuflags.mk"
+ .sinclude "@PREFIX@/share/mk/cpuflags.mk"
  .Ed
  .Pp
  Those desiring further optimisation can install the lang/gcc3 package, 
and
@@ -64,17 +64,17 @@
  .Pa /etc/mk.conf
  instead:
  .Bd -literal -offset indent
- .sinclude "/usr/pkg/share/examples/gcc/mk.conf"
- .sinclude "/usr/pkg/share/mk/cpuflags.mk"
+ .sinclude "@PREFIX@/share/examples/gcc/mk.conf"
+ .sinclude "@PREFIX@/share/mk/cpuflags.mk"
  .Ed
  .Pp
  To experiment with optimisations that can break generated code there is
  optimize_gcc.mk. This is unsupported, but for full effect add the 
following to
  .Pa /etc/mk.conf :
  .Bd -literal -offset indent
- .sinclude "/usr/pkg/share/examples/gcc/mk.conf"
- .sinclude "/usr/pkg/share/mk/cpuflags.mk"
- .sinclude "/usr/pkg/share/mk/optimize_gcc.mk"
+ .sinclude "@PREFIX@/share/examples/gcc/mk.conf"
+ .sinclude "@PREFIX@/share/mk/cpuflags.mk"
+ .sinclude "@PREFIX@/share/mk/optimize_gcc.mk"
  .Ed
  .Pp
  On all except low memory machines compliation can be speeded up by 
adding the