Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

makefile and notdir

208 views
Skip to first unread message

Brownie

unread,
Jul 24, 2009, 9:42:16 AM7/24/09
to
Hello,

I try to do a makefile for a program with several sources. It's
working if all sources are in the same folder with the makefile
SRC -> file with all f90 and the makefile
OBJ -> objects directory
MOD -> modules directory

the list of objects is generated as follow
OBJDIR = ../obj
SRCS= \
./TYP_DateJJSecPico_mod.f90 \
main.f90

OBJS= $(SRCS:%.f90=$(OBJDIR)/%.o)

Now, I would like to access sources from different directories as
follows
SRC2 -> directory with the new source file toto.f90
SRC -> same as before
OBJ -> same as before
MOD -> same as before

object list is generated as follows
OBJDIR = ../obj
SRCS= \
./TYP_DateJJSecPico_mod.f90 \
../SRC2/toto.f90 \ <=========modif
main.f90

OBJS= $(SRCS:%.f90=$(OBJDIR)/%.o)
This formulation returns OBJS as follows :
../obj/./TYP_DateJJSecPico_mod.f90
../obj/../SRC2/toto.o

WRONG !! but playing whith $(addprefix $(OBJDIR)/,$(notdir $(OBJS)))
I obtain
../obj/TYP_DateJJSecPico_mod.f90
../obj/toto.o

GOOD but SRCS has been modified and cut the directory path from each
file so my inferences $(OBJDIR)/%.o: %.f90 do not work.

Help please,

Brownie

Henrik Carlqvist

unread,
Jul 31, 2009, 4:08:46 PM7/31/09
to
Brownie <brown...@gmail.com> wrote:
> Now, I would like to access sources from different directories
...

> so my inferences $(OBJDIR)/%.o: %.f90 do not work.

One solution if you have your sources in different directories is to also
have different rules. Something like:

$(OBJDIR)/%.o: %.f90
command to compile

$(OBJDIR)/%.o: ../SRC2/%.f90
command to compile (possible the same command as for the other rule)

Another solution would be to use VPATH or vpath, example:

vpath %.f90 .:../SRC2

For more info on vpath and VPATH see
http://www.gnu.org/software/make/manual/make.html#General-Search

regards Henrik
--
The address in the header is only to prevent spam. My real address is:
hc3(at)poolhem.se Examples of addresses which go to spammers:
root@localhost postmaster@localhost

0 new messages