Subject: Some more Q. re. mk/ and a proposal
To: None <>
From: Georg Schwarz <>
List: tech-pkg
Date: 03/02/2005 17:40:31

I am trying to understand mk/, so here are a few more questions:

Is there any version of Linux that does not come with GNU make installed?
(i.e. should _TOOLS_OPSYS_HAS_GNU.make contain Linux-*-*?)

Now to the real questions...

.for _tool_ in ${USE_GNU_TOOLS}
# What GNU tools did the package or user ask for, and does the base
# system already have it?
_TOOLS_NEED_GNU.${_tool_}=      YES
.  for _pattern_ in ${_TOOLS_OPSYS_HAS_GNU.${_tool_}}
_TOOLS_HAS_GNU.${_tool_}=       YES
.    if !empty(MACHINE_PLATFORM:M${_pattern_})
_TOOLS_NEED_GNU.${_tool_}=      NO
.    endif
.  endfor

Note that in the inner loop _tool_ is fixed. What sense does it make to
_TOOLS_HAS_GNU.${_tool_}=       YES
in the inner loop? 
What purpose does _TOOLS_HAS_GNU.${_tool_} serve at all?
To me this information is already contained in
_TOOLS_HAS_GNU.${_tool_} does not seem to be used except for yacc.
Looking at the above code it seems that _TOOLS_OPSYS_HAS_GNU.${_tool_}
equals YES exactly if ${_tool_} is contained in USE_GNU_TOOLS.
Next, what sense does the test of _TOOLS_OPSYS_INCOMPAT.${_tool_} make?
(which is done for ${_tool_} in ${USE_GNU_TOOLS} only)  

_TOOLS_NEED_GNU.${_tool_} has already been set to YES, unless
In the latter case, it should never be in _TOOLS_OPSYS_INCOMPAT.${_tool_}
though, shouldn't it?

So to me that section is completely useless.

Next, the line
# Are we using a GNUish system tool in place of the needed GNU tool?
is misleading. Note that we loop through _TOOLS here, not only
USE_GNU_TOOLS. So it should be called something like
# Are there any system tools that explicitly need to be symlinked?

What is also misleading is the use of "GNUish" in

# These platforms have GNUish versions of the tools available in the base
# system, which we already define as ${AWK}, ${SED}, etc. (refer to
# mk/platform/*.mk for the definitions), so no need to pull in the pkgsrc
# versions; we will use these instead.

above. As can be seen below in mk/, _TOOLS_REPLACE_OPSYS.{_tool_}
only is of relevance if _TOOLS_NEED_GNU.${_tool_} is not set.
This makes sense, but then the comment re. _TOOLS_REPLACE_OPSYS should read
something like this:

# These platforms have usable versions of the tools available in the base
# system, which we already define as ${AWK}, ${SED}, etc. (refer to
# mk/platform/*.mk for the definitions), but they might need to be
# explicitly symlinked to be found.

I think here it becomes apparent that _TOOLS_OPSYS_INCOMPAT is not needed
at all (and in fact not used currently, as explained above).

So my understanding is that things are like this:

_TOOLS contains a list of all tools we potentially deal with
USE_GNU_TOOLS contains a user/package defined list of tools that have to be
During execution of mk/ USE_GNU_TOOLS is potentially reduced if the
respective _IGNORE_GNU_TOOL.${_tool_} is set.

_TOOLS_OPSYS_HAS_GNU.${_tool_} indicates whether the system already comes
with a GNU version of _tool_. That one can either be in the system path or
referenced by the respective variable ($AWK, $SED, etc.)

Irrespectively of that, i.e. whether _tool_ is required in GNU form or not,
_TOOLS_REPLACE_OPSYS.${_tool_} indicates whether on the respective system
there is _tool_ defined as a variable and needs to be symlinked, since
otherwise it might not be found by the system (e.g. a different, undesired
instance with the standard name prior to it in the shell search path might
be used).

mk/ fills the following variables:

not needed nor used in my opinion, see above.

whether the GNU _tool_ from pkgsrc needs to be used


built from _TOOLS_REPLACE_OPSYS.${_tool_} with the same meening (just that
the tool/system "matrix" is inverted) 

whether to explicitly symlink something for ${_tool_}. (if so, "something"
is specified in the end by _TOOLS_PROGNAME.${_tool_}.)

What I honestly do not understand is the following (example for awk):

.if !empty(PKGPATH:Mlang/gawk)
MAKEFLAGS+=             _IGNORE_GNU_TOOL.awk=

If gawk is already installed, then do not override awk? Why? Does this
assume that packages installed are in the shell search path and moreover
are found with priority over the respective native system tools? This would
not necessarily be a valid assumption.

Moreover, it looks to me that mk/ assumes that $SED, $AWK, etc. are
plain paths to binaries, i.e. do not contain e.g. trailing options.
Correct? Would it be advisable to, just in case, strip off any trailing
options? Would the following do (assuming noone uses spaces in their file
_TOOLS_PROGNAME.awk=    ${AWK:S, .*$,,}

So far for my current understanding of mk/
Now the reason I looked into this is that I am considering whether it would
make sense to symlink other tools as well for systems (like mine :-)) where
the native equivalent in the shell path is not powerful enough, e.g. CP,

On such systems one could, e.g. in /etc/mk.conf, add (as an example for cp)

All it would take to change in mk/ is to add the additional tools
to the _TOOLS= list and add respective handlers like

.if ${_TOOLS_REPLACE.cp} == "YES"

for the extra supported tools.





Georg Schwarz     +49 178 8545053