[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Paths above current/working directory don't work with suffix rules
From: |
Adam Tuja |
Subject: |
Paths above current/working directory don't work with suffix rules |
Date: |
Mon, 24 Jan 2022 19:09:44 +0100 |
Hello,
I had this problem trying to compile a source with relative paths above current/working directory level. I took me hours of frustration to make work and, it eventually didn't.
Then, by a chance I realised that when I use a path within current working directory it more or less works.
It doesn't matter how with many levels above current directory the path has (../ ../../ ...), it's still the same.
--
PROG = ab
LD = $(CC)
OBJS = a.o b.o c-1up.o
a.o: a.c
b.o: b.c
c-1up.o: ../c-1up.c
.c.o:
$(CC) $(CFLAGS) -c -o $@ $<
.cpp.o:
$(CXX) $(CXXFLAGS) -c -o $@ $<
$(PROG): $(OBJS)
$(LD) -o $@ $(OBJS) $(LIBS)
all: $(PROG)
--
```
$ make -f makefile-ab3x-suffix-rules.mk all
cc -c -o a.o a.c
cc -c -o b.o b.c
cc -o ab a.o b.o c-1up.o
cc: error: c-1up.o: No such file or directory
make: *** [ab] Error 1
```
And then I found that it only fails when I use suffix rules. When every file has its own rule it works.
--
PROG = ab
LD = $(CC)
OBJS = a.o b.o c-1up.o
a.o: a.c
$(CC) $(CFLAGS) -c -o $@ $<
b.o: b.c
$(CC) $(CFLAGS) -c -o $@ $<
c-1up.o: ../c-1up.c
$(CC) $(CFLAGS) -c -o $@ $<
$(PROG): $(OBJS)
$(LD) -o $@ $(OBJS) $(LIBS)
all: $(PROG)
--
```
$ make -f makefile-ab3y-dependencies-for-every1.mk all
cc -c -o a.o a.c
cc -c -o b.o b.c
cc -c -o c-1up.o ../c-1up.c
cc -o ab a.o b.o c-1up.o
```
I don't know if it's a feature or a bug, or a bug in my makefile but it seems to work somewhat strange.
Above Test files are attached.
PS.
Not to mention that if I don't specify target (all) then it only processes one file
```
$ make -f makefile-ab3x-suffix-rules.mk
cc -c -o a.o a.c
$ make -f makefile-ab3y-dependencies-for-every1.mk
cc -c -o a.o a.c
```
That's minor I guess.
Kind regards
Adam
65544
Description: GNU Zip compressed data
- Paths above current/working directory don't work with suffix rules,
Adam Tuja <=