I am not fully following what's going on.

The way this grew is because Jim and I once had a solution in Make-lang.in
that put a "-I ../libgcobol" into CPPFLAGS.

Then it turned out I couldn't use CPPFLAGS, because it wasn't available on
all architectures.

But I nonetheless needed to use valconv.cc and charmaps.cc in both
libgcobol and gcc/cobol.  So I copied them to the build directory.  Then
it turned out that compilations have to be possible on read-only file
systems.  And the various cdf.y parse.y and scan.l builds cause .cc files
to be created in the build directory.  

But I don't know where the build directory is, so I couldn't statically
establish the relative path to libgcobol in those source code modules.  

So, I didn't know how to set -I, and I didn't know where the build
directory is, so I came up with the SED solution.  It was hateful, and Jim
and I had words about it, but I did it to be able to keep going.  (You may
have noted that I have a "keep going" ethic.)

If there is a solution whereby the gcc/cobol build process can have a "-I
$(srcdir)/../libgcobol" established, then by all means, we should do so.
I just wasn't able figure out how to do it.


> -----Original Message-----
> From: Jakub Jelinek <ja...@redhat.com>
> Sent: Friday, March 28, 2025 10:40
> To: Robert Dubner <rdub...@symas.com>; James K. Lowden
> <jklow...@cobolworx.com>; Richard Biener <rguent...@suse.de>
> Cc: gcc-patches@gcc.gnu.org
> Subject: [PATCH] cobol: Fix up cobol/{charmaps,valconv}.cc rules
> 
> Hi!
> 
> sed -i is not portable, it is supported by GNU sed and perhaps some
BSDs,
> but not elsewhere.
> Furthermore, I think it is far better to always use
> #include "../../libgcobol/something.h"
> paths rather than something depending on the build directory.
> And because we require GNU make, we don't have to have two different
> rules for those, can use just one for both.
> The l variable in there is just to make it fit into 80 columns.
> 
> Ok for trunk?
> 
> 2025-03-28  Jakub Jelinek  <ja...@redhat.com>
> 
>       * Make-lang.in (cobol/charmaps.cc, cobol/valconv.cc): Used sed -e
>       instead of cp and multiple sed -i commands.  Always prefix
libgcobol
>       header names in #include directives with ../../libgcobol/ rather
> than
>       something depending on $(LIB_SOURCE).
> 
> --- gcc/cobol/Make-lang.in.jj 2025-03-28 15:08:29.431543005 +0100
> +++ gcc/cobol/Make-lang.in    2025-03-28 15:31:14.886182633 +0100
> @@ -87,29 +87,10 @@ cobol1_OBJS =    \
>  # Various #includes in the files copied from gcc/libgcobol need to be
> modified
>  # so that the .h files can be found.
> 
> -cobol/charmaps.cc: $(LIB_SOURCE)/charmaps.cc
> -     cp $^ $@
> -     sed -i "s|\"ec[.]h\"|\"$(LIB_SOURCE)/ec.h\"|g" $@
> -     sed -i "s|\"common-defs[.]h\"|\"$(LIB_SOURCE)/common-defs.h\"|g"
$@
> -     sed -i "s|\"io[.]h\"|\"$(LIB_SOURCE)/io.h\"|g" $@
> -     sed -i "s|\"gcobolio[.]h\"|\"$(LIB_SOURCE)/gcobolio.h\"|g" $@
> -     sed -i "s|\"libgcobol[.]h\"|\"$(LIB_SOURCE)/libgcobol.h\"|g" $@
> -     sed -i "s|\"gfileio[.]h\"|\"$(LIB_SOURCE)/gfileio.h\"|g" $@
> -     sed -i "s|\"charmaps[.]h\"|\"$(LIB_SOURCE)/charmaps.h\"|g" $@
> -     sed -i "s|\"valconv[.]h\"|\"$(LIB_SOURCE)/valconv.h\"|g" $@
> -     sed -i "s|\"exceptl[.]h\"|\"$(LIB_SOURCE)/exceptl.h\"|g" $@
> -
> -cobol/valconv.cc: $(LIB_SOURCE)/valconv.cc
> -     cp $^ $@
> -     sed -i "s|\"ec[.]h\"|\"$(LIB_SOURCE)/ec.h\"|g" $@
> -     sed -i "s|\"common-defs[.]h\"|\"$(LIB_SOURCE)/common-defs.h\"|g"
$@
> -     sed -i "s|\"io[.]h\"|\"$(LIB_SOURCE)/io.h\"|g" $@
> -     sed -i "s|\"gcobolio[.]h\"|\"$(LIB_SOURCE)/gcobolio.h\"|g" $@
> -     sed -i "s|\"libgcobol[.]h\"|\"$(LIB_SOURCE)/libgcobol.h\"|g" $@
> -     sed -i "s|\"gfileio[.]h\"|\"$(LIB_SOURCE)/gfileio.h\"|g" $@
> -     sed -i "s|\"charmaps[.]h\"|\"$(LIB_SOURCE)/charmaps.h\"|g" $@
> -     sed -i "s|\"valconv[.]h\"|\"$(LIB_SOURCE)/valconv.h\"|g" $@
> -     sed -i "s|\"exceptl[.]h\"|\"$(LIB_SOURCE)/exceptl.h\"|g" $@
> +cobol/charmaps.cc cobol/valconv.cc: cobol/%.cc: $(LIB_SOURCE)/%.cc
> +     -l='ec\|common-defs\|io\|gcobolio\|libgcobol\|gfileio\|charmaps';
\
> +     l=$$l'\|valconv\|exceptl'; \
> +     sed -e '/^#include/s,"\('$$l'\)\.h","../../libgcobol/\1.h",' $^ >
$@
> 
>  LIB_SOURCE_H=$(wildcard $(LIB_SOURCE)/*.h)
> 
> 
>       Jakub

Reply via email to