Re: sub makefile does not use correct value of CFLAGS from top make file,

2021-09-03 Thread Jeffrey Walton
On Fri, Sep 3, 2021 at 5:58 PM Jeffrey.Fellin--- via Bug reports and
discussion for GNU make  wrote:
>
> I have a project that compiles .S and .c files, and the value of CFLAGS in 
> the sub makefile is not the same for the compile lines
> ...
> The compile of bug.S succeeds, but doesn’t have the correct value of CFLAGS, 
> as in the annotated output below. The compile of hello.c has the correct 
> value of CFLAGS, but the compile fails due to the unsupported options to the 
> cc. The extra options are for use by the project specific compiler.

I believe you should use ASFLAGS for assembly source, not CFLAGS.

Also see "Variables Used by Implicit Rules"
(https://ftp.gnu.org/old-gnu/Manuals/make-3.79.1/html_node/make_97.html)
in the manual.

Jeff



Re: sub makefile does not use correct value of CFLAGS from top make file,

2021-09-03 Thread Martin Dorey
# Also note the top make file removes the default rule for %.o:%.[Sc], but

# the default rules are still being used.

I fear you think that .EXPORT_ALL_VARIABLES should have exported your custom 
rule to the sub-make.  It won't.  I didn't notice any difference in say 4.1 but 
I dug out a similarly prehistoric version of make, 3.81, and its default rule 
for compiling .S files doesn't mention CFLAGS:

COMPILE.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_MACH) -c
...
%.o: %.S
#  commands to execute (built-in):
$(COMPILE.S) -o $@ $<

In make_top, there's an extra S on the name of the third variable used here:

echo "Assembling: $< : lib CFLAGS=$(CFLAGGS)" \

I doubt that line continuation backslash is going to have the desired effect, 
if it were ever used, given the @ at the start of the next line and the lack of 
a semicolon after the echo.


From: Bug-make  on behalf of 
Jeffrey.Fellin--- via Bug reports and discussion for GNU make 
Sent: Friday, September 3, 2021 13:34
To: bug-make@gnu.org 
Subject: sub makefile does not use correct value of CFLAGS from top make file,

* EXTERNAL EMAIL *

I have a project that compiles .S and .c files, and the value of CFLAGS in the 
sub makefile is not the same for the compile lines



The version of make is

GNU Make 3.82

Built for x86_64-redhat-linux-gnu

Copyright (C) 2010  Free Software Foundation, Inc.



I’m attaching a tarball containing the following files, for ease in reproducing 
the problem

cflags_bug/make_top

cflags_bug/base/sub_make

cflags_bug/base/src/bug.S

cflags_bug/base/src/hello.c



The compile of bug.S succeeds, but doesn’t have the correct value of CFLAGS, as 
in the annotated output below. The compile of hello.c has the correct value of 
CFLAGS, but the compile fails due to the unsupported options to the cc. The 
extra options are for use by the project specific compiler.



The top make undefines the default rules for %.o:%.c and %.o:%.S, has my 
understanding from these documents:

Managing Projects with BNU Make, Third Edition,

GNU Make pdf, Section 10.5.5 Match-Anything Pattern Rules



The annotated execution of make -f make_top, supplied in the cflags_bug.tar

$ make -ikf make_top;exit

(cd base && make -f sub_make all)

make[1]: Entering directory `/home/jfellin/cflags_bug/base'

# This displays the value of CFLAGS that should be use in the

# compilation of the .S and .c files

# the compile errors are not important, but the different

# value of CFLAGS, which are expected to be the same.



# Also note the top make file removes the default rule for %.o:%.[Sc], but

# the default rules are still being used.



# Expected value in compile *.S and *.c

check CFLAGS=-DTOP_MAKE -Wall -I base/inc -mlittle-endian 
--target=aarch64-arm-none-eabi -mcpu=cortex-a53+nocrypto+nofp+nosimd 
-mno-unaligned-access -mfpu=None-O  -MD -I 
/home/jfellin/cflags_bug/base/../base/inc  -D BASE_MAKE





# Note this value of CFLAGS is not the one printed above

cc-c -o /home/jfellin/cflags_bug/base/../base/src/bug.o 
/home/jfellin/cflags_bug/base/../base/src/bug.S





# Note this value of CFLAGS is the one printed by the check_cflag rule

# in the file, sub_make,

cc -DTOP_MAKE -Wall -I base/inc -mlittle-endian --target=aarch64-arm-none-eabi 
-mcpu=cortex-a53+nocrypto+nofp+nosimd -mno-unaligned-access -mfpu=None-O  
-MD -I /home/jfellin/cflags_bug/base/../base/inc  -D BASE_MAKE  -mlittle-endian 
--target=aarch64-arm-none-eabi -mcpu=cortex-a53+nocrypto+nofp+nosimd 
-mno-unaligned-access -mfpu=None -c -o 
/home/jfellin/cflags_bug/base/../base/src/hello.o 
/home/jfellin/cflags_bug/base/../base/src/hello.c

cc: warning: \u2018-mcpu=\u2019 is deprecated; use \u2018-mtune=\u2019 or 
\u2018-march=\u2019 instead

cc: warning: \u2018-mcpu=\u2019 is deprecated; use \u2018-mtune=\u2019 or 
\u2018-march=\u2019 instead

cc: error: unrecognized command line option \u2018-mlittle-endian\u2019

cc: error: unrecognized command line option \u2018-mno-unaligned-access\u2019

cc: error: unrecognized command line option \u2018-mfpu=None\u2019

cc: error: unrecognized command line option \u2018-mlittle-endian\u2019

cc: error: unrecognized command line option \u2018-mno-unaligned-access\u2019

cc: error: unrecognized command line option \u2018-mfpu=None\u2019

make[1]: [/home/jfellin/cflags_bug/base/../base/src/hello.o] Error 1 (ignored)

make[1]: Leaving directory `/home/jfellin/cflags_bug/base'



Jeff




Re: sub makefile does not use correct value of CFLAGS from top make file,

2021-09-03 Thread Philip Guenther
Unlike variable assignments, rules--including overrides of built-in pattern
rules--are not inherited by recursively invoked instances of make.  They
have to be in a makefile read by the instance of make that needs them.

(GNU makes built-in rules and variables have TARGET_ARCH for basically all
types of compilation.  IMHO, if you have options that don't apply to, for
example, .S files, then why not put them in CFLAGS *directly* and not in
TARGET_ARCH?  Or just use your own variable name (e.g., "targ_arch")
instead of trying to give your own use/meaning to a variable which is
already in use.  Fighting the builtin rules is a bad use of your time.)


Philip Guenther

On Fri, Sep 3, 2021 at 12:58 PM Jeffrey.Fellin--- via Bug reports and
discussion for GNU make  wrote:

> I have a project that compiles .S and .c files, and the value of CFLAGS in
> the sub makefile is not the same for the compile lines
>
>
>
> The version of make is
>
> GNU Make 3.82
>
> Built for x86_64-redhat-linux-gnu
>
> Copyright (C) 2010  Free Software Foundation, Inc.
>
>
>
> I’m attaching a tarball containing the following files, for ease in
> reproducing the problem
>
> cflags_bug/make_top
>
> cflags_bug/base/sub_make
>
> cflags_bug/base/src/bug.S
>
> cflags_bug/base/src/hello.c
>
>
>
> The compile of bug.S succeeds, but doesn’t have the correct value of
> CFLAGS, as in the annotated output below. The compile of hello.c has the
> correct value of CFLAGS, but the compile fails due to the unsupported
> options to the cc. The extra options are for use by the project specific
> compiler.
>
>
>
> The top make undefines the default rules for %.o:%.c and %.o:%.S, has my
> understanding from these documents:
>
> Managing Projects with BNU Make, Third Edition,
>
> GNU Make pdf, Section 10.5.5 Match-Anything Pattern Rules
>
>
>
> The annotated execution of make -f make_top, supplied in the cflags_bug.tar
>
> $ make -ikf make_top;exit
>
> (cd base && make -f sub_make all)
>
> make[1]: Entering directory `/home/jfellin/cflags_bug/base'
>
> # This displays the value of CFLAGS that should be use in the
>
> # compilation of the .S and .c files
>
> # the compile errors are not important, but the different
>
> # value of CFLAGS, which are expected to be the same.
>
>
>
> # Also note the top make file removes the default rule for %.o:%.[Sc], but
>
> # the default rules are still being used.
>
>
>
> # Expected value in compile *.S and *.c
>
> check CFLAGS=-DTOP_MAKE -Wall -I base/inc -mlittle-endian
> --target=aarch64-arm-none-eabi -mcpu=cortex-a53+nocrypto+nofp+nosimd
> -mno-unaligned-access -mfpu=None-O  -MD -I
> /home/jfellin/cflags_bug/base/../base/inc  -D BASE_MAKE
>
>
>
>
>
> # Note this value of CFLAGS is not the one printed above
>
> cc-c -o /home/jfellin/cflags_bug/base/../base/src/bug.o
> /home/jfellin/cflags_bug/base/../base/src/bug.S
>
>
>
>
>
> # Note this value of CFLAGS is the one printed by the check_cflag rule
>
> # in the file, sub_make,
>
> cc -DTOP_MAKE -Wall -I base/inc -mlittle-endian
> --target=aarch64-arm-none-eabi -mcpu=cortex-a53+nocrypto+nofp+nosimd
> -mno-unaligned-access -mfpu=None-O  -MD -I
> /home/jfellin/cflags_bug/base/../base/inc  -D BASE_MAKE  -mlittle-endian
> --target=aarch64-arm-none-eabi -mcpu=cortex-a53+nocrypto+nofp+nosimd
> -mno-unaligned-access -mfpu=None -c -o
> /home/jfellin/cflags_bug/base/../base/src/hello.o
> /home/jfellin/cflags_bug/base/../base/src/hello.c
>
> cc: warning: \u2018-mcpu=\u2019 is deprecated; use \u2018-mtune=\u2019 or
> \u2018-march=\u2019 instead
>
> cc: warning: \u2018-mcpu=\u2019 is deprecated; use \u2018-mtune=\u2019 or
> \u2018-march=\u2019 instead
>
> cc: error: unrecognized command line option \u2018-mlittle-endian\u2019
>
> cc: error: unrecognized command line option
> \u2018-mno-unaligned-access\u2019
>
> cc: error: unrecognized command line option \u2018-mfpu=None\u2019
>
> cc: error: unrecognized command line option \u2018-mlittle-endian\u2019
>
> cc: error: unrecognized command line option
> \u2018-mno-unaligned-access\u2019
>
> cc: error: unrecognized command line option \u2018-mfpu=None\u2019
>
> make[1]: [/home/jfellin/cflags_bug/base/../base/src/hello.o] Error 1
> (ignored)
>
> make[1]: Leaving directory `/home/jfellin/cflags_bug/base'
>
>
>
> Jeff
>
>
>