Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


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

Makefile Help needed



I'm not sure that tis helps, maybe I'm dense as I'm not 100% sure what you
want to do, but it sounds like you need an inference rule:

PROJPATH=../test1

%.o:$(PROJPATH)/%.c
        cc -o  $@ $<


test.o : $(PROJPATH)/test.c


> My makefile is *mostly* working.
>
> My problem is this:  I want to build a .o in a different directory from
> the
> current one, and it's being rather stubborn unless I spell out the rule.
>
> Imagine if you will, a makefile that can build target1, target2, and
> target3, and I'm adding troubletarget.o to it.  Assume troubletarget.c is
> in
> the currect directory with everything else
>
> If I do:
> all: target1 target2 target3 troubletarget.o
> it builds fine.
>
> If I do:
> all: target1 target2 target3 ./troubletarget.o
> it builds fine.
>
> If I do:
> all: target1 target2 target3 ../otherdir/troubletarget.o
> I get "make: *** No rule to make target ../otherdir/troubletarget.o"
> which I can understand, because it doesn't know where the C file is.
>
> HOWEVER, if I do:
> all: target1 target2 target3 ../otherdir/troubletarget.o
> it simply does not try to build it at all.
>
> If I add a rule like:
> ../otherdir/troubletarget.o: troubletarget.c
> it still doesn;t attempt to build it.
>
> If I change that to
> ../otherdir/troubletarget.o: troubletarget.c
> 	$(CC) $(CFLAGS) -c $< -o $@
> it works, but I don't see why I have to do that, since it already knows
> how
> to turn a .c into a .o, because earlier in the file I have
> .c.o:
> 	$(CC) $(CFLAGS) -c $< -o $@
> which should build it fine,
>
> Note that I can't use the newer style
> %.o : %.c ; command...
> because the stem is different on the .o and the .c since they're in
> different directories.
>
>
> Does this make sense?  What am I doing wrong?  Thanks in advance.





BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org