lua-users home
lua-l archive

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


On Thu, Mar 15, 2018 at 02:01:07AM -0700, William Ahern wrote:
<snip>
> 
> The biggest headache with the existing Lua build, though, is that there's no
> way to override the default, per-platform flag sets without forgoing the
> pre-defined flags altogether. There's no way for me to say, "build for
> macosx, _except_ use this flag instead of the default macosx flag". The
> least intrusive way to fix this this is, from the platform target rules, to
> specify the default flags as environment variables and then use the standard
> (POSIX-defined) -e option. Make is defined by POSIX to propogate command
> line options and macro definitions to recursive make invocations by passing
> them through the MAKEFLAGS environment variable (whether or not the rule
> uses the $(MAKE) macro; make always exports SHELL and MAKEFLAGS by default).

I left out the pertinent aspect of -e: it changes the order of precedence so
that environment variables override variables defined in the makefile, but
still have lower precedence that those defined on the command-line or
inherited via MAKEFLAGS. The default precedence order is (quoting POSIX)

  Macro definitions shall be taken from the following sources, in the
  following logical order, before the makefile(s) are read.

  1. Macros specified on the make utility command line, in the order
  specified on the command line. It is unspecified whether the internal
  macros defined in Internal Macros are accepted from this source.

  2. Macros defined by the MAKEFLAGS environment variable, in the order
  specified in the environment variable. It is unspecified whether the
  internal macros defined in Internal Macros are accepted from this source.

  3. The contents of the environment, excluding the MAKEFLAGS and SHELL
  variables and including the variables with null values.

  4. Macros defined in the inference rules built into make.

  Macro definitions from these sources shall not override macro definitions
  from a lower-numbered source. Macro definitions from a single source (for
  example, the make utility command line, the MAKEFLAGS environment
  variable, or the other environment variables) shall override previous
  macro definitions from the same source.

 Macros defined in the makefile(s) shall override macro definitions that
 occur before them in the makefile(s) and macro definitions from source 4.
 If the -e option is not specified, macros defined in the makefile(s) shall
 override macro definitions from source 3. Macros defined in the makefile(s)
 shall not override macro definitions from source 1 or source 2.

Even Microsoft NMake seems to follow the same rules,

 The following list shows the order of precedence, from highest to lowest:

 1. A macro defined on the command line

 2. A macro defined in a makefile or include file

 3. An inherited environment-variable macro

 4. A macro defined in the Tools.ini file

 5. A predefined macro, such as CC and AS

 Use /E to cause macros inherited from environment variables to override
 makefile macros with the same name.

(https://docs.microsoft.com/en-us/cpp/build/precedence-in-macro-definitions)

> For example, I can override the definition of CC when using the macosx
> target by applying this diff,
> 
> -   $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_MACOSX" SYSLIBS="-lreadline" CC=cc
> +   CC=cc $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_MACOSX" SYSLIBS="-lreadline"
<snip>