lionel319
lionel319

Reputation: 1256

how to do a string compare with a makefile's target name

Say i have this:-

files := a.txt b.txt c.txt
$(files):
    ifeq ($@, a.txt)
        #do this
    else
        #do that
    endif

this doesn't seem to work. is there any workaround for this?

Upvotes: 0

Views: 604

Answers (1)

Jonathan Leffler
Jonathan Leffler

Reputation: 753455

The orthodox way to handle it is:

files_a = a.txt
files_bc = b.txt c.txt

files = $(files_a) $(files_bc)

all: $(files)

$(files_a):
    do this

$(files_bc):
    do that

If different files need different rules, you group them separately. The other advantage of this is that it doesn't depend on GNU make extensions. If there are common operations shared between the two sets of commands (the 'do this' and 'do that'), you can encode the common operations as macros.

Upvotes: 1

Related Questions