List Info

Thread: findstring & ifeq




findstring & ifeq
user name
2006-05-10 20:56:34
Hi List,

I have a bunch of sources I'm trying to compile... All .f
files, but 
about 50% use one command and 50% use another...

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) 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




_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make
findstring & ifeq
user name
2006-05-10 21:07:14
On Wed, 10 May 2006, Ken Mankoff wrote:
> 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?

My apologies for not searching the list archives more
thoroughly. 
The solution is like so:

%.o: %.f
 	$(if $(findstring $,$(OBJ)),	\
 		$(FC) $(FFLAGS) $<,	\
 		$(FCMP) $(FFLAGSMP) $<)


ifeq doesn't expand $, so $(if) must be used...

   -k.



_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make
findstring & ifeq
user name
2006-05-11 12:19:38
%% Ken Mankoff <mankoffgmail.com> writes:

  km> On Wed, 10 May 2006, Ken Mankoff wrote:
  >> 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?

  km> My apologies for not searching the list archives
more thoroughly. 
  km> The solution is like so:

  km> %.o: %.f
  km>  	$(if $(findstring $,$(OBJ)),	\
  km>  		$(FC) $(FFLAGS) $<,	\
  km>  		$(FCMP) $(FFLAGSMP) $<)

Just a note: I would definitely avoid findstring here.  It
will find any
_substring_.  It's obviously unlikely that a <...>.o
string will appear
inside another word in OBJ; nevertheless ...

You should use the filter and filter-out functions (in this
case you
want filter) to match entire words.

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


_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make
findstring & ifeq
user name
2006-05-11 14:29:06
Ken Mankoff wrote:
> # So... why doesn't this work?
> %.o: %.f
> ifeq ($(findstring $,$(OBJ)),)
>         echo not found
> else
>         echo found
> endif

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.

But you could use $(if) instead:

     %.o: %.f
         echo $(if $(findstring $,$(OBJ)),found,not found)

John.
-- 
John Graham-Cumming
jgcjgc.org

Home: http://www.jgc.org/
Blog: http://www.jgc.org/blog/

POPFile: http://getpopfile.org/
GNU Make Standard Library: http://gmsl.sf.net/
GNU Make Debugger: http://gmd.sf.net/
Fast, Parallel Builds: http://www.electric-cl
oud.com/

Sign up for my Spam and Anti-spam Newsletter
at http://www.jgc.org/

Help out in the fight against spam
http://www.spamorham.org/


_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make
[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )