Re: [PATCH] honor CFLAGS & friends from environment

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 14/02/2019 23:34, Luc Van Oostenryck wrote:
> From: Uwe Kleine-König <uwe@xxxxxxxxxxxxxxxxx>
> 
> Debian build scripts pass CFLAGS in the environment.
> However, this is ignored by Sparse's Makefile since 'CFLAGS'
> is unconditionaly initialized.
> 
> Fix this by initializing CFLAGS to their default value using '?='.
> Do the same for PKG_CONFIG, CHECKER, CHECKER_FLAGS and
> DESTDIR, BINDIR, MANDIR & MAN1DIR.
> 
> Note: It's useless to try to do the same for CC, LD & AR since
>       they're builtin variables so '?= ...' is a no-op for them
>       (unless make is called with -R).

BTW, I have seen (a long time ago) an ugly hack to try and
get around this 'special behaviour' of the variables from
make's built-in database. It is very ugly, ...

Suppose you wanted to set 'CC ?= gcc' in the Makefile, but
because CC is 'special', you don't get the 'use the value
from the environment if set, else default to this value'.
An ugly workaround would look something like this:

  $ git diff
  diff --git a/Makefile b/Makefile
  index 025bce2..a98a9fc 100644
  --- a/Makefile
  +++ b/Makefile
  @@ -4,8 +4,9 @@ VERSION=0.6.0
   # The following variables can be overwritten from the command line
   OS = linux
   
  -
  +ifeq ($(origin CC),default)
   CC = gcc
  +endif
   CFLAGS = -O2 -g
   CFLAGS += -Wall -Wwrite-strings
   LD = $(CC)
  @@ -20,6 +21,9 @@ BINDIR=$(PREFIX)/bin
   MANDIR=$(PREFIX)/share/man
   MAN1DIR=$(MANDIR)/man1
   
  +fred:
  +       @echo "CC is $(CC), origin: " $(origin CC)
  +
   # Allow users to override build settings without dirtying their trees
   # For debugging, put this in local.mk:
   #
  $ 

  $ make fred
  Makefile:128: Your system does not have libxml, disabling c2xml
  Makefile:150: Your system does not have gtk3/gtk2, disabling test-inspect
  Makefile:183: Your system does not have llvm, disabling sparse-llvm
  CC is gcc, origin:  file
  $ 

  $ make CC=cmd fred
  make: cmd: Command not found
  Makefile:128: Your system does not have libxml, disabling c2xml
  Makefile:150: Your system does not have gtk3/gtk2, disabling test-inspect
  Makefile:183: Your system does not have llvm, disabling sparse-llvm
  CC is cmd, origin:  command line
  $ 

  $ CC=env make fred
  env: unrecognised option '--print-file-name='
  Try 'env --help' for more information.
  Makefile:128: Your system does not have libxml, disabling c2xml
  Makefile:150: Your system does not have gtk3/gtk2, disabling test-inspect
  Makefile:183: Your system does not have llvm, disabling sparse-llvm
  CC is env, origin:  environment
  $ 
  
[Note: the 'make: cmd: Command not found' and similar message
about the 'env' invocation comes from the '$(shell $(CC) ...)'
further down the makefile (see line 100, setting GCC_BASE).]

Hmm, it may be possible to create a define ... :-P

ATB,
Ramsay Jones



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux