Re: [PATCH] Makefile: avoid undefined variables

2024-10-25 Thread Martin D Kealey
On Fri, 25 Oct 2024 at 05:07, Grisha Levit  wrote:

> These are reported by make --warn-undefined-variables.
>
> Most were being set previously (sometimes 20 years ago) and got left
> behind in recepies after their definitions have been removed. Others
> only get set in some configurations so it makes sense to prevent them
> from inheriting stray values from the environment otherwise. A few are
> just typos.
>

I've been looking at the Makefiles as well, and I find I have a lot of
questions, like:

   1. What is the point of ‘$(BUILD_DIR)’?
   When is it not simply ‘$$PWD’ or ‘.’ (prefaced by one or more ‘../’ when
   in a subdirectory)?
   2. Do any of the following *ever* change?
   dot = .
   DEFDIR = builtins
   LIBBUILD = lib
   GLOB_LIBDIR = lib/glob
   INTL_LIBDIR = lib/intl
   ALLOC_LIBDIR = lib/malloc
   RL_LIBDIR = lib/readline
   HIST_LIBDIR = lib/readline *(again)*
   SH_LIBDIR = lib/sh
   TERM_LIBDIR = lib/termcap
   TILDE_LIBDIR = lib/tilde
   3. Are any of these *ever* used?
   ALLOC_ABSSRC = ${topdir}/$(ALLOC_LIBDIR)
   BASE_CFLAGS_FOR_BUILD = @BASE_CFLAGS_FOR_BUILD@
   BUILD_INCLUDED_LIBINTL = @BUILD_INCLUDED_LIBINTL@
   BUILTIN_ABSSRC = ${topdir}/builtins
   DEBUGGER_DIR = debugger
   DOCSRC = $(srcdir)/doc
   EXTRASOURCES = *(a long list)*
   GCC_LINT_CFLAGS = $(BASE_CCFLAGS) $(CPPFLAGS) $(GCC_LINT_FLAGS)
   GLOB_ABSSRC = ${topdir}/$(GLOB_LIBDIR)
   GLOB_OBJ = *(a long list)*
   HISTORY_OBJ = *(a long list)*
   HIST_ABSSRC = ${topdir}/$(HIST_LIBDIR)
   HIST_INCLUDEDIR = @HIST_INCLUDEDIR@
   INTLLIBS = @INTLLIBS@
   INTLOBJS = @INTLOBJS@
   INTL_ABSSRC = ${topdir}/$(INTL_LIB)
   LIBINTL = @LIBINTL@
   LTLIBINTL = @LTLIBINTL@
   MALLOC = @MALLOC@
   OTHERS = *(a list)*
   PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
   PACKAGE_NAME = @PACKAGE_NAME@
   PACKAGE_STRING = @PACKAGE_STRING@
   PACKAGE_TARNAME = @PACKAGE_TARNAME@
   PO_SRC = $(srcdir)/po/
   PSIZE_SOURCE= *(a long list)*
   READLINE_OBJ= *(a long list)*
   RELOCATABLE_DEFS = -DENABLE_RELOCATABLE=1 -DIN_LIBRARY \
   RL_ABSSRC = ${topdir}/$(RL_LIBDIR)
   RL_INCLUDEDIR = @RL_INCLUDEDIR@
   RL_LIBDOC = $(RL_LIBSRC)/doc
   SH_ABSSRC = ${topdir}/${SH_LIBSRC}
   SIGNAMES_SUPPORT = $(SUPPORT_SRC)mksignames.c
   SRC = *(a short list)*
   SRC1 =  man2html.c
   STATIC_SOURCE   = *(a long list)*
   STUB_SOURCE = stub.c
   SUBDIR_INCLUDES = -I. @RL_INCLUDE@ -I$(topdir) -I$(topdir)/$(LIBSUBDIR)
   TERMCAP_LDFLAGS = -L$(TERM_LIBDIR)
   TERMCAP_OBJ = $(TERM_LIBDIR)/termcap.o \
   TERM_ABSSRC = ${topdir}/$(TERM_LIBDIR)
   TEX = tex
   TEXINDEX= texindex
   TILDE_ABSSRC = ${topdir}/$(TILDE_LIBDIR)
   TILDE_OBJ   = $(TILDE_LIBDIR)/tilde.o
   USE_INCLUDED_LIBINTL = @USE_INCLUDED_LIBINTL@
   datarootdir = @datarootdir@
   host_cpu = @host_cpu@
   host_vendor = @host_vendor@
   l = @INTL_LIBTOOL_SUFFIX_PREFIX@
   transform = @program_transform_name@


I think I may have identified some issues as well.

Firstly, almost all targets are simply given as a path relative to the
current directory (which is fine) but where they're noted as dependencies,
they're often prefaced by some ‘$(FOOLIB)/’.

I'm guessing that the idea was that you could link with a different version
of the library outside the build tree (and outside the source tree), but is
that actually used anywhere?
If it *is* used, I'd ideally like to see all the variables that reference
build directories have trailing slashes, unless they're completely empty
(meaning the current directory). This would probably need some adjustment
to the ‘configure’ script, or to autoconf.

Otherwise I'd rather just hard-code them as relative paths; I have a patch
to that effect if you're interested.

I'm seeing weird errors where generated dependencies wind up including both
'./foo.h' and 'foo.h' separately. Having the wrong one is a problem when
foo.h is actually a generated file, in which case the addition or removal
of './' can thwart the rule intended to build it, or even cause ‘make’ to
abort due to the absence of a stated prerequisite that has no rule.
(Depending on the version of Make, it may or may not normalize file paths.)

Secondly, where targets are built by running a command in another
directory, that secondary build process can inherit paths that no longer
point to the correct place.

If we could be sure that the variables are always relative, then it would
be simple enough to preface them with ‘../’, like this:

   - cd $(@D) && $(MAKE) BUILD_DIR=../$(BUILD_DIR) $(MAKEFLAGS) $(@F)


However if they could be absolute paths, that would clearly be thwarted.

The tricky part is that this may or may not affect variables that point to
the source, depending on how ‘configure’ was invoked:

   - when run in the source tree as ‘./configure’ it sets ‘BUILD_DIR=.’
   (which I would like to see changed to ‘./’ or empty);
   - when run as ‘../bash-source/configure’ it sets
   ‘BUILD_DIR=../bash-source’
   - when run as ‘/home/me/src/bash/configure’ it sets
   ‘BUILD_DIR=/home/me/src/bash’

Re: [PATCH] BASH_STRUCT_DIRENT*: simplify

2024-10-25 Thread Chet Ramey

On 10/23/24 1:34 PM, Grisha Levit wrote:

The BASH_STRUCT_DIRENT* macros duplicate the caching, message printing,
and defining functionality already present in the AC_CHECK_MEMBERS macro
that gets called.


Thanks for the report and patch.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/


OpenPGP_signature.asc
Description: OpenPGP digital signature


Re: [PATCH] BASH_FUNC_STRTOIMAX: fix and simplify

2024-10-25 Thread Chet Ramey

On 10/23/24 12:39 PM, Grisha Levit wrote:

Without an existing cache, if we run ./configure -C, we get the odd-
looking:

 checking for usable strtoimax... checking for strtoimax... yes
 checking whether strtoimax is declared... yes
 yes


Thanks for the report. I'll take a look here. This file is a simplified
version of the one from gnulib, which has a lot of machinery to detect
and cope with systems that have a strtoimax function but not a declaration,
and vice versa (e.g., HPUX 11).

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/


OpenPGP_signature.asc
Description: OpenPGP digital signature


Re: [PATCH] Makefile: avoid undefined variables

2024-10-25 Thread Dmitry Goncharov
>- cd $(@D) && $(MAKE) BUILD_DIR=$(UP)$(BUILD_DIR)
>top_srcdir=$(UPSRC)$(top_srcdir) $(MAKEFLAGS) $(@F)

It is really not a good idea to pass makeflags on the command line as
a positional parameter.
A variable (any variable, including makeflags) set on the command
line, overrides the value in make's memory.
In the case of makeflags, make itself sets makeflags according to the
command line switches specified by the user.
And then, a command line definition of makeflags wipes out those
switches from make's memory and the switches do not get to submake.
Unless you are using some ancient version of make, there is no need to
pass makeflags on the command line.
See https://savannah.gnu.org/bugs/?62469

regards, Dmitry



Re: posix vs default mode nonsense

2024-10-25 Thread Zachary Santer
On Tue, Oct 22, 2024 at 11:30 AM Chet Ramey  wrote:
>
> but that won't help with the portability problems.

You can't even use arrays or [[ ... ]] and be portable, right? It
might be easier to install bash on whatever it is at that point.