A style proposal for referring to upper-level directories in Makefiles

Mikhail T. mi+thun at aldan.algebra.com
Thu Jul 28 19:17:23 UTC 2011


The most common method to refer to the upper directory in Makefile is as 
${.CURDIR}/..

I'd like to propose we begin using ${.CURDIR:H} instead. For one this speeds up 
the filesystem-traversal for the invoked tool. And, perhaps more importantly, it 
makes the various build-logs look nicer (and be smaller). The lines in Makefiles 
will also be shorter (two characters per level instead of three). For example:

    --- secure/Makefile.inc 3 Aug 2009 08:13:06 -0000       1.25.10.1
    +++ secure/Makefile.inc 28 Jul 2011 18:45:52 -0000
    @@ -3,8 +3,8 @@
      .include <bsd.own.mk>

    -.if exists(${.CURDIR}/../../lib/libcrypt/obj)
    -CRYPTOBJDIR=   ${.CURDIR}/../../lib/libcrypt/obj
    +.if exists(${.CURDIR:H:H}/lib/libcrypt/obj)
    +CRYPTOBJDIR=   ${.CURDIR:H:H}/lib/libcrypt/obj
      .else
    -CRYPTOBJDIR=   ${.CURDIR}/../../lib/libcrypt
    +CRYPTOBJDIR=   ${.CURDIR:H:H}/lib/libcrypt
      .endif

    @@ -14,4 +14,4 @@

      .if ${MK_OPENSSH} != "no"
    -SSHDIR=                ${.CURDIR}/../../../crypto/openssh
    +SSHDIR=                ${.CURDIR:H:H:H}/crypto/openssh
      .endif

The new method is functionally equivalent to the old and I see no drawbacks to 
it, do you?

    -mi



More information about the freebsd-hackers mailing list