bug-make
[Top][All Lists]
Advanced

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

Re: [RFC] .NOT_DEFAULT: target


From: Paul D. Smith
Subject: Re: [RFC] .NOT_DEFAULT: target
Date: Mon, 17 May 2004 17:29:22 -0400

%% Boris Kolpackov <address@hidden> writes:

  bk> I came to the point where I cannot work around "default target
  bk> hijacking" problem. So I am planning to do something about it in
  bk> my -bk patch-set. I also hope this feature will end up in the main
  bk> stream thus this RFC.

  bk> When makefile inclusion is used there is a recurring problem of
  bk> default target hijacking by auxiliary targets. For example I 
  bk> have the following pattern:

  bk> 1. User `makefile' includes `bootstrap.make' to bootstrap build
  bk>    system.

  bk> 2. `bootstrap.make' includes configuration makefiles that are 
  bk>     generated automatically. Rules for those configuration files
  bk>     hijack default target.

  bk> # file: bootstrap.make
  bk> out_root := initialize-output-root
  bk> $(out_root)/configuration:
  bk>   configure $@
  bk> include $(out_root)/configuration

  bk> # file: makefile
  bk> include bootstrap.make
  bk> $(out_root)/driver: driver.c

The way I typically solve this is that I always define the target I want
to be the default first, with no prerequisites etc.  Simply putting
something like:

    all:

by itself at the top of the first makefile is enough to force make to
consider that target to be the default.  So, in your example you could
change your makefile to:

    # file: makefile
    all:
    include boostrap.make
    all: $(out_root)/driver
    $(out_root)/driver: driver.c

Alternatively, if you have a makefile which is always included at the
top (say your bootstrap.make file) you can put the "all" target in that
file as the first thing:

    # file: bootstrap.make
    .PHONY: all
    all:
    out_root := initialize-output-root
    $(out_root)/configuration:
        configure $@
    include $(out_root)/configuration

    # file: makefile
    include boostrap.make
    all: $(out_root)/driver
    $(out_root)/driver: driver.c

With these methods what you do is declare the "real" default target (or
list of targets) to be a prerequisite of the generic default target,
"all".

  bk> This problem can be solved by specifying that particular target
  bk> cannot be default:

  bk> # file: bootstrap.make

  bk> out_root := initialize-output-root

  bk> .NOT_DEFAULT: $(out_root)/configuration

  bk> $(out_root)/configuration:
  bk>   configure $@

  bk> include $(out_root)/configuration

  bk> comments?

Mm.  I don't know about this.  It seems like it's the wrong way
around... if what you want to have is the default target, why have
people declare everything that _cannot_ be the default?  Why not just
declare what _IS_ the default?

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.paulandlesley.org
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist




reply via email to

[Prev in Thread] Current Thread [Next in Thread]