Subject: lib and prog specific flags.
To: None <tech-userlevel@netbsd.org>
From: Eric Haszlakiewicz <erh@nimenees.com>
List: tech-userlevel
Date: 09/07/2003 16:34:24
--8t9RHnE3ZwKMSgU+
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline


	I recently ran into the need to set custom CPPFLAGS and LDADD for
only one particular program.  (sendmail, to compile sasl support).  It
seemed less than ideal to have to go and edit the makefile so I added
support to the mk files to allow you to do this in mk.conf.  The patch
is attached.  Does this look reasonable?  Are there any other variables
that should be handled like this?

eric

--8t9RHnE3ZwKMSgU+
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="mk.diff"

? diff
Index: bsd.README
===================================================================
RCS file: /cvsroot/src/share/mk/bsd.README,v
retrieving revision 1.135
diff -u -r1.135 bsd.README
--- bsd.README	2003/09/03 05:38:09	1.135
+++ bsd.README	2003/09/07 21:15:46
@@ -255,6 +255,19 @@
 		various system utilities/libraries that support it.
 		If MKYP is "no", USE_YP will also be forced to "no".
 
+COPTS.lib<lib>
+LDADD.lib<lib>
+CPPFLAGS.lib<lib>
+CXXFLAGS.lib<lib>
+COPTS.<prog>
+LDADD.<prog>
+CPPFLAGS.<prog>
+CXXFLAGS.<prog>		These provide a way to specify additions to the
+		associated variables in a way that applies only to a particular
+		library or program.  <lib> corresponds to the LIB variable set
+		in the library's makefile.  <prog> corresponds to either PROG
+		or PROG_CXX (if set).  For example, if COPTS.libcrypto is set to "g",
+		"-g" will be added to COPTS only when compiling the crypto library.
 
 =-=-=-=-=   sys.mk   =-=-=-=-=
 
Index: bsd.lib.mk
===================================================================
RCS file: /cvsroot/src/share/mk/bsd.lib.mk,v
retrieving revision 1.231
diff -u -r1.231 bsd.lib.mk
--- bsd.lib.mk	2003/08/24 09:35:49	1.231
+++ bsd.lib.mk	2003/09/07 21:15:47
@@ -12,6 +12,20 @@
 realinstall:	checkver libinstall
 clean:		cleanlib
 
+##### LIB specific flags.
+.if defined(COPTS.lib${LIB})
+COPTS+=    ${COPTS.lib${LIB}}
+.endif
+.if defined(CPPFLAGS.lib${LIB})
+CPPFLAGS+=  ${CPPFLAGS.lib${LIB}}
+.endif
+.if defined(CXXFLAGS.lib${LIB})
+CXXFLAGS+=  ${CXXFLAGS.lib${LIB}}
+.endif
+.if defined(LDADD.lib${LIB})
+LDADD+=     ${LDADD.lib${LIB}}
+.endif
+
 ##### Build and install rules
 CPPFLAGS+=	${DESTDIR:D-nostdinc ${CPPFLAG_ISYSTEM} ${DESTDIR}/usr/include}
 CXXFLAGS+=	${DESTDIR:D-nostdinc++ ${CPPFLAG_ISYSTEMXX} ${DESTDIR}/usr/include/g++}
Index: bsd.prog.mk
===================================================================
RCS file: /cvsroot/src/share/mk/bsd.prog.mk,v
retrieving revision 1.183
diff -u -r1.183 bsd.prog.mk
--- bsd.prog.mk	2003/08/22 19:17:00	1.183
+++ bsd.prog.mk	2003/09/07 21:15:47
@@ -7,11 +7,29 @@
 .include <bsd.shlib.mk>
 .include <bsd.gcc.mk>
 
+.if defined(PROG_CXX)
+PROG=	${PROG_CXX}
+.endif
+
 ##### Basic targets
 .PHONY:		cleanextra cleanobjs cleanprog proginstall scriptsinstall
 realinstall:	proginstall scriptsinstall
 clean:		cleanprog
 
+##### PROG specific flags.
+.if defined(COPTS.${PROG})
+COPTS+=    ${COPTS.${PROG}}
+.endif
+.if defined(CPPFLAGS.${PROG})
+CPPFLAGS+=  ${CPPFLAGS.${PROG}}
+.endif
+.if defined(CXXFLAGS.${PROG})
+CXXFLAGS+=  ${CXXFLAGS.${PROG}}
+.endif
+.if defined(LDADD.${PROG})
+LDADD+=     ${LDADD.${PROG}}
+.endif
+
 ##### Default values
 CPPFLAGS+=	${DESTDIR:D-nostdinc ${CPPFLAG_ISYSTEM} ${DESTDIR}/usr/include}
 CXXFLAGS+=	${DESTDIR:D-nostdinc++ ${CPPFLAG_ISYSTEMXX} ${DESTDIR}/usr/include/g++}
@@ -76,10 +94,6 @@
 	@mv -f x.c x.cc
 	@${CXX} ${CXXFLAGS} -c x.cc -o ${.TARGET}
 	@rm -f x.cc
-.endif
-
-.if defined(PROG_CXX)
-PROG=	${PROG_CXX}
 .endif
 
 .if defined(PROG)

--8t9RHnE3ZwKMSgU+--