Subject: How to properly use shell commands that are defined in make(1)
To: None <>
From: Roland Illig <>
List: tech-pkg
Date: 11/24/2005 14:04:04
Quite a few shell programs in pkgsrc use commands similar to how they 
are used in the pkgsrc Makefiles. As it were much better if the tools 
were used not only similar but _equal_ to inside Makefiles, I've written 
a quiet little, but useful make(1) target:

.for _c_ in ${CMDS}
         @${ECHO} ${_c_:Q}"() { "${${_c_}:Q}" \"\$$@\"; }"

It looks cryptic, and indeed it is. But its usage is very simple:

$ make sh-define-cmds CMDS=MAKE
MAKE() { /usr/bin/make "$@"; }

This output can then be evaluated by a shell script using the "." command.

This also works in really weird environments, like the following:

$ make sh-define-cmds \
     PKG_DBDIR="fo            bar"
PKG_DELETE() { /usr/bin/env FOO=bar /home/roland/pkg/sbin/pkg_delete -K 
fo\ \ \ \ \ \ \ \ \ \ \ \ bar "$@"; }

(Well, if you try it out right now pkgsrc will print many warnings, but 
that's because there are some bugs left in

I'd like to commit that code. After that, we should change the complete 
pkgsrc infrastructure to use this code. Or something equivalent.