help-make
[Top][All Lists]
Advanced

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

Re: Dynamic top-level targets


From: Garrett Cooper
Subject: Re: Dynamic top-level targets
Date: Thu, 12 Jun 2008 11:44:49 -0700

On Wed, Jun 11, 2008 at 12:03 AM, Timothy Reilly <address@hidden> wrote:
> Hello-
>
> I've got a program that I'd like to compile with varying sets of options.
> All of these options are completely independent, and the actual dependencies
> of the targets are the same- they differ only in options passed to the
> commands.  My idea was to have each set of flags be a pattern match rule and
> an explicit rule.  The pattern match rule would match the option-set to the
> suffix, strip the suffix, and depend on the prefix, which would repeat the
> process until only a single option-set remained, which would match the
> explicit rule.  Here's the relevant portion of the makefile :
>
> debug: CXXFLAGS := $(CXXFLAGS) -Wall -g
> debug: all
>
> benchmark: CXXFLAGS := $(CXXFLAGS) -DBENCHMARK
> benchmark: all
>
> openmp: CXXFLAGS := $(CXXFLAGS) $(OMP)
> openmp: all
>
> release: CXXFLAGS := $(CXXFLAGS) -DNDEBUG -O2
> release: all
>
> vector: CXXFLAGS := $(CXXFLAGS) -DUSE_SIMD $(VECTOR_FLAGS)
> vector: all
>
>
> %_debug: CXXFLAGS := $(CXXFLAGS) -Wall -g
> %_debug: %
>
> %_benchmark: CXXFLAGS := $(CXXFLAGS) -DBENCHMARK
> %_benchmark: %
>
> %_openmp: CXXFLAGS := $(CXXFLAGS) $(OMP)
> %_openmp: %
>
> %_release: CXXFLAGS := $(CXXFLAGS) -DNDEBUG -O2
> %_release: %
>
> %_vector: CXXFLAGS := $(CXXFLAGS) -DUSE_SIMD $(VECTOR_FLAGS)
> %_vector: %
>
>
> The idea was to be able to do something as such:
>
> make vector_debug_openmp_benchmark
>
> and have CXXFLAGS expand to all of the relevant flags.
>
> The pattern match rules do not do what I'd like them to do, and I do not
> understand why.  Is what I'm trying to do feasible/possible?
>
>
> Thanks in advance for your time,
> Timothy Reilly

I believe your issue is with target vs variable expansion.

One thing you can do is do CXXFLAGS += -Wall -g, etc per target type,
as opposed to CXXFLAGS := $(CXXFLAGS) -Wall -g, etc.

I'm not sure that the pattern rules will match as you have specified
above though; you'd probably have to have the ability to do "front" as
well as "rear" pattern matching. I don't believe that function is
available in make at all.

Why do that though if you can specify compile options via conditionals
in make, like ifeq, if, etc, and manipulate the target name via $(if
...)? Seems like a simpler solution to the issue...

-Garrett




reply via email to

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