Unix Programming - Make (ifeq and findstring)

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > May 2006 > Make (ifeq and findstring)





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Make (ifeq and findstring)
mankoff

2006-05-10, 7:15 pm

Hi Group,

I have a bunch of sources I'm trying to compile... All .f files, but
about 50% use one command and 50% use the other (MP compilation).

I'm trying to do conditional compilation using findstring and ifeq in
the makefile, but having errors. Can anyone advise how to best do this?
The problem I am having is with a simple 'ifeq' command the logic works
(like the example in the manual here:
http://www.gnu.org/software/make/ma...ditional-Syntax)
but if I nest a $(findstring) in the $(ifeq) then no matter what the
rule is true...

# this works:
ifeq ("foo","foo")
@echo here
endif

# this works too (nothing printed)
ifeq ("foo","bar")
@echo here
endif

# this works too... If I touch a file in the OBJ list it echos the
filename
# if I touch a file NOT in the OBJ list, it echos a blank line
%.o: %.f
@echo $(findstring $@,$(OBJ))

# So... why doesn't this work?
%.o: %.f
ifeq ($(findstring $@,$(OBJ)),)
@echo not found
else
@echo found
endif

The Makefile I'm testing is below.

Thanks,

-k.

FC=xlf
FCMP=xlf_r
FFLAGS=-O2 -qmaxmem=-1 -qalias=nostd -qsave -qfloat=strictnmaf -c
FFLAGSMP=-qsmp=omp $(FFLAGS)

# these are single processor source files
SRC = f0.f, f1.f, f2.f, etc...
# these are SMP (distributed)
SRCMP = f0mp.f, f1mp.f, f2mp.f, etc...
# except in reality the filenames are long and complex and I cannot
# just search for the word "mp" in the filename...

OBJ=$(SRC:.f=.o)
OBJMP=$(SRCMP:.f=.o)

SRCS = $(SRC) $(SRCMP) # all sources
OBJS = $(OBJ) $(OBJMP) # all objects

all: foo

foo: $(OBJS)
# ./compile.sh

%.o: %.f
ifeq ($(findstring $@,$(OBJ)),$@)
# search in OBJ (not OBJS or OBJMP) for this file.
@echo single processor
$(FC) $(FFLAGS) $<
else
@echo dual processor
$(FCMP) $(FFLAGSMP) $<
endif

Maxim Yegorushkin

2006-05-11, 1:20 am


mankoff wrote:
> Hi Group,
>
> I have a bunch of sources I'm trying to compile... All .f files, but
> about 50% use one command and 50% use the other (MP compilation).
>
> I'm trying to do conditional compilation using findstring and ifeq in
> the makefile, but having errors. Can anyone advise how to best do this?


[]

For your task you don't need ifeq's. Just put the object files into
different folders or name them differently. See bellow.

> FC=xlf
> FCMP=xlf_r
> FFLAGS=-O2 -qmaxmem=-1 -qalias=nostd -qsave -qfloat=strictnmaf -c
> FFLAGSMP=-qsmp=omp $(FFLAGS)
>
> # these are single processor source files
> SRC = f0.f, f1.f, f2.f, etc...
> # these are SMP (distributed)
> SRCMP = f0mp.f, f1mp.f, f2mp.f, etc...
> # except in reality the filenames are long and complex and I cannot
> # just search for the word "mp" in the filename...
>

OBJ=$(SRC:.f=.o)
OBJMP=$(SRCMP:.f=.mp.o)

all: foo foo.mp

foo: $(OBJS)
foo.mp: $(OBJSMP)

%.o: %.f
@echo single processor
$(FC) $(FFLAGS) $<

%.mp.o: %.f
@echo dual processor
$(FCMP) $(FFLAGSMP) $<

mankoff

2006-05-29, 5:32 pm

Thanks for the reply. I cannot change/rename/move the files as I am not
the only programmer and this is a legacy codebase.

"Because the ifeq is processed when the Makefile is being parsed and
not when rules are run. In that case $@ is empty and hence this won't
work. You can't use ifeq to change the body of a rule at run time."

The final solution used $(filter).

-k.

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com