Subject: Compiling the system with different options.
To: None <tech-userlevel@netbsd.org>
From: Christos Zoulas <christos@zoulas.com>
List: tech-userlevel
Date: 11/15/2004 17:49:12
Hello,

There was a recent PR mentioning that right now there are too many options
hard-coded in the Makefiles and we cannot easily turn them on and off.
The example in the PR was -DINET6, but there are many more.

We also commonly specify libraries in the Makefiles as:

.if ${USE_SKEY} != "no"
CPPFLAGS+= -DSKEY
DPADD += ${LIBSKEY}
LDADD += -lskey
.endif

I suggest that we change all this to be:

CPPFLAGS += ${CPPFLAGS_SKEY}
DPADD += ${DPADD_SKEY}
LDADD += ${LDADD_SKEY}

This way we achieve the following:

	- the Makefiles become simplified; no more conditionals
	- the variable handling is symmetric; all variables are treated
	  the same way.
	- we don't expose implementation specific information such as -lskey.

All the magic is handled in bsd.own.mk. We can start with -DINET6 -DSKEY
etc, which are low hanging fruit and I have a patch for them already,
and then become more ambitious to fix the rest.

What do you think? Here's the minor patch to bsd.own.mk and the login Makefile

Index: bsd.own.mk
===================================================================
RCS file: /cvsroot/src/share/mk/bsd.own.mk,v
retrieving revision 1.424
diff -u -u -r1.424 bsd.own.mk
--- bsd.own.mk	7 Aug 2004 21:42:52 -0000	1.424
+++ bsd.own.mk	15 Nov 2004 22:12:39 -0000
@@ -548,7 +548,7 @@
 	DOC \
 	GCC GCCCMDS GDB \
 	HESIOD HTML \
-	IEEEFP INET6 INFO \
+	IEEEFP INET6 IPSEC INFO \
 	KERBEROS KERBEROS4 \
 	LINKLIB LINT \
 	MAN \
@@ -653,14 +653,33 @@
 # USE_* options which default to "yes" unless their corresponding MK*
 # variable is set to "no".
 #
-.for var in HESIOD INET6 KERBEROS KERBEROS4 SKEY YP
+.for var in CRYPTO HESIOD INET6 IPSEC KERBEROS KERBEROS4 SKEY YP
 .if (${MK${var}} == "no")
 USE_${var}:= no
 .else
 USE_${var}?= yes
+CPPFLAGS_${var}=-D${var}
+DPADD_${var}=${LIB${var}}
+LDADD_${var}=-l${var:tl}
 .endif
 .endfor
 
+.if (${MKHESIOD} != "no")
+DPADD_HESIOD=${LIBHDB}
+LDADD_HESIOD=-lhdb
+.endif
+
+.if (${MKHESIOD} != "no" || ${MKKERBEROS4} != "no")
+DPADD_KERBEROS=${LIBKRB}
+LDADD_KERBEROS=-lkrb
+.endif
+
+DPADD_INET6=
+LDADD_INET6=
+
+DPADD_YP=
+LDADD_YP=
+
 #
 # USE_* options which default to "yes".
 #


Index: Makefile
===================================================================
RCS file: /cvsroot/src/usr.bin/login/Makefile,v
retrieving revision 1.42
diff -u -u -r1.42 Makefile
--- Makefile	5 Jan 2004 03:53:10 -0000	1.42
+++ Makefile	15 Nov 2004 22:32:58 -0000
@@ -11,11 +11,9 @@
 BINMODE=4555
 CPPFLAGS+=-DLOGIN_CAP -DSUPPORT_UTMP -DSUPPORT_UTMPX
 
-.if (${USE_SKEY} != "no")
-CPPFLAGS+=-DSKEY
-DPADD+= ${LIBSKEY}
-LDADD+=	-lskey
-.endif
+CPPFLAGS+=${CPPFLAGS_SKEY}
+DPADD+= ${DPADD_SKEY}
+LDADD+=	${LDADD_SKEY}
 
 CLEANFILES+=	copyrightstr.c
 
@@ -41,8 +39,8 @@
 LDADD+= -lkrb -ldes
 .endif
 
-DPADD+=	${LIBCRYPTO} ${LIBROKEN} ${LIBCOM_ERR}
-LDADD+=	-lcrypto -lroken -lcom_err
+DPADD+=	${DPADD_CRYPTO} ${LIBROKEN} ${LIBCOM_ERR}
+LDADD+=	${LDADD_CRYPTO} -lroken -lcom_err
 .endif
 
 .include <bsd.prog.mk>