Subject: Re: [RFC] framework for platform tools
To: Johnny Lam <jlam@NetBSD.org>
From: Roland Illig <roland.illig@gmx.de>
List: tech-pkg
Date: 04/10/2005 17:31:57
This is a multi-part message in MIME format.
--------------020901010103060504000201
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Johnny Lam wrote:
> These are all good reasons, especially the maintenance part. Plus, we
> simplify porting pkgsrc, which is quite good. I'm not sure that the
> TOOL_FLAGS variable can be consistently used because it won't be used
> correctly by configure scripts, etc. I think maybe it'd be better to
> define a TOOL_CMD and TOOL_FLAGS variable and then also a TOOL variable
> that looks like:
>
> TOOL?= ${TOOL_CMD} ${TOOL_FLAGS}
I've done that. I am using TOOL_REAL_CMD instead of TOOL_CMD to make it
more uniform. Otherwise there would be a conflict in what the GZIP_CMD
is to mean.
> One problem with your implementation is that ":tu" isn't a variable
> modifier that is supported by the bootstrap bmake. Until we've fixed
> that, and also create some way for pkgsrc to check that the ${MAKE}
> invoked is of the correct vintage, we can't use these extra modifiers.
I've also done this. I made a new file toupper.mk that contains a list
of words it can convert. Although your suggestion of _PLATFORM_TOOLNAME
may be more suitable for my platform.default.mk, I have chosen to take
the more general approach of providing a toupper "function" that can be
easily replaced once the pkgsrc bmake is fully functional.
Roland
--------------020901010103060504000201
Content-Type: text/plain;
name="platform.default.mk"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="platform.default.mk"
# $NetBSD$
#
# Default tool definitions for all operating systems.
#
# For each program `tool' in ${PLATFORM_TOOLS} and ${PLATFORM_CMD_TOOLS},
# a variable `TOOL_REAL_CMD' is defined to the first program that is
# found in ${PLATFORM_EXECDIRS}, and a variable `TOOL_FLAGS' is defined
# to the empty string, if it had not been defined before.
#
# For each program `tool' in PLATFORM_TOOLS, a variable `TOOL' is
# defined to either ${TOOL_REAL_CMD} ${TOOL_FLAGS} (if TOOL_FLAGS
# is defined) or to just ${TOOL_REAL_CMD}.
# For each program `tool' in PLATFORM_CMD_TOOLS, a variable `TOOL_CMD' is
# defined to either ${TOOL_REAL_CMD} ${TOOL_FLAGS} (if TOOL_FLAGS
# is defined) or to just ${TOOL_REAL_CMD}.
#
# You can set PLATFORM_TOOLS and PLATFORM_CMD_TOOLS to a list of additional
# tools you want to be checked.
#
# Examples:
# After inclusion of this file, the variable MKDIR_REAL_CMD points
# to a mkdir(1) tool, and the variable MKDIR is defined such that it
# can be used unquoted in Makefile shell code fragments.
# Similarly, GZIP_REAL_CMD is defined, and GZIP_CMD can be used
# unquoted in Makefile shell code fragments.
#
# Allow multiple inclusion -- other Makefile fragments might want to define
# additional tools and then include this file.
#.if !defined(_MK_PLATFORM_DEFAULT_MK)
#_MK_PLATFORM_DEFAULT_MK= # defined
.include "../mk/bsd.prefs.mk"
PLATFORM_EXECDIRS?= /bin /usr/bin /sbin /usr/sbin ${LOCALBASE:Q}/bin
PLATFORM_TOOLS+= awk
PLATFORM_TOOLS+= basename
PLATFORM_TOOLS+= cat chmod chown chgrp cmp cp cpp cut
PLATFORM_TOOLS+= date dirname
PLATFORM_TOOLS+= echo echo_n egrep env expr
PLATFORM_TOOLS+= false fgrep find
PLATFORM_TOOLS+= gmake grep groupadd gtar gzcat
PLATFORM_TOOLS+= head
PLATFORM_TOOLS+= id
PLATFORM_TOOLS+= ldconfig ln ls
PLATFORM_TOOLS+= m4 mkdir mtree mv
PLATFORM_TOOLS+= nice
PLATFORM_TOOLS+= patch pax perl5 ps
PLATFORM_TOOLS+= rm rmdir rsh
PLATFORM_TOOLS+= sed sh shlock sort su
PLATFORM_TOOLS+= tail tar tee test touch tr true tsort type
PLATFORM_TOOLS+= useradd
PLATFORM_TOOLS+= wc
PLATFORM_TOOLS+= xargs
PLATFORM_CMD_TOOLS+= file gunzip gzip hostname mail pwd
TOUPPER_NEEDED+= ${PLATFORM_TOOLS} ${PLATFORM_CMD_TOOLS}
.include "toupper.mk"
#
# Define TOOL_REAL_CMD for each tool from PLATFORM_TOOLS. If the tool
# cannot be found, fall back to the tool name without a path.
#
.for _t_ in ${PLATFORM_TOOLS} ${PLATFORM_CMD_TOOLS}
. for _d_ in ${PLATFORM_EXECDIRS}
. if !defined(TU.${_t_}_REAL_CMD) && exists(${_d_}/${_t_})
${TU.${_t_}}_REAL_CMD= ${_d_}/${_t_}
. endif
. endfor
. if !defined(${TU.${_t_}}_REAL_CMD)
${TU.${_t_}}_REAL_CMD= ${_t_}
. endif
.endfor
#
# Define the TOOL variable for the tools in PLATFORM_TOOLS.
#
.for _t_ in ${PLATFORM_TOOLS}
. if !defined(TU.${_t_})
. if defined(${TU.${_t_}}_FLAGS)
${TU.${_t_}}= ${${TU.${_t_}}_REAL_CMD:Q} ${${TU.${_t_}}_FLAGS}
. else
${TU.${_t_}}= ${${TU.${_t_}}_REAL_CMD:Q}
. endif
. endif
.endfor
#
# Define the TOOL_CMD variable for the tools in PLATFORM_CMD_TOOLS.
#
.for _t_ in ${PLATFORM_CMD_TOOLS}
. if !defined(TU.${_t_}_CMD)
. if defined(TU.${_t_}_FLAGS)
${TU.${_t_}}_CMD= ${${TU.${_t_}}_REAL_CMD:Q} ${${TU.${_t_}}_FLAGS}
. else
${TU.${_t_}}_CMD= ${${TU.${_t_}}_REAL_CMD:Q}
. endif
. endif
.endfor
#.endif # _MK_PLATFORM_DEFAULT_MK
--------------020901010103060504000201
Content-Type: text/plain;
name="toupper.mk"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="toupper.mk"
# $NetBSD$
#
# This file provides an efficient way to generate the uppercase
# equivalent of a string. To use it, add the values you want to convert
# to the TUPPER_NEEDED list of strings and include this file directly
# after the addition.
#
# After inclusion of this file, you can access the uppercase names using
# ${TU.${X}} for every X that has been added to TUPPER_NEEDED.
#
# This file is a workaround for the :tu modifier, which is not included
# in the pkgsrc bmake, but is a useful feature of the NetBSD bmake since
# 1.6. As soon as bmake includes the :tu modifier, this file will be
# removed from pkgsrc.
#
.if !defined(_MK_TOUPPER_MK_TABLE)
_MK_TOUPPER_MK_TABLE= # defined
TU.awk= AWK
TU.basename= BASENAME
TU.cat= CAT
TU.chgrp= CHGRP
TU.chmod= CHMOD
TU.chown= CHOWN
TU.cmp= CMP
TU.cp= CP
TU.cpp= CPP
TU.cut= CUT
TU.date= DATE
TU.dirname= DIRNAME
TU.echo= ECHO
TU.echo_n= ECHO_N
TU.egrep= EGREP
TU.env= ENV
TU.expr= EXPR
TU.false= FALSE
TU.fgrep= FGREP
TU.file= FILE
TU.find= FIND
TU.gmake= GMAKE
TU.grep= GREP
TU.groupadd= GROUPADD
TU.gtar= GTAR
TU.gunzip= GUNZIP
TU.gzcat= GZCAT
TU.gzip= GZIP
TU.head= HEAD
TU.hostname= HOSTNAME
TU.id= ID
TU.ldconfig= LDCONFIG
TU.ln= LN
TU.ls= LS
TU.m4= M4
TU.mail= MAIL
TU.mkdir= MKDIR
TU.mtree= MTREE
TU.mv= MV
TU.nice= NICE
TU.patch= PATCH
TU.pax= PAX
TU.perl5= PERL5
TU.ps= PS
TU.pwd= PWD
TU.rm= RM
TU.rmdir= RMDIR
TU.rsh= RSH
TU.sed= SED
TU.sh= SH
TU.shlock= SHLOCK
TU.sort= SORT
TU.su= SU
TU.tail= TAIL
TU.tar= TAR
TU.tee= TEE
TU.test= TEST
TU.touch= TOUCH
TU.tr= TR
TU.true= TRUE
TU.tsort= TSORT
TU.type= TYPE
TU.useradd= USERADD
TU.wc= WC
TU.xargs= XARGS
check-vulnerable: do-toupper-check
do-toupper-check:
${_PKG_SILENT}${_PKG_DEBUG} \
vars=${_TOUPPER_UNDEFINED:Q}; \
if test x"$$vars" != "x"; then \
echo "ERROR: toupper.mk: undefined variables:$$vars" 1>&2; \
exit 1; \
fi
.endif # _MK_TOUPPER_MK_TABLE
_TOUPPER_UNDEFINED= # empty
.for _v_ in ${TOUPPER_NEEDED}
. if !defined(TU.${_v_})
_TOUPPER_UNDEFINED+= ${_v_}
. endif
.endfor
--------------020901010103060504000201--