[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re:How to adding pathes to dependencies in rules of `.d` files
From: |
ljh |
Subject: |
Re:How to adding pathes to dependencies in rules of `.d` files |
Date: |
Sat, 4 Mar 2023 23:24:39 +0800 |
My Makefile used to build source files in the subdir is like this:
```
# build shared library with -fPIC, -shared
CFLAGS = -fPIC # -g -O3 -fPIC # CXXFLAGS for .cpp
LDFLAGS = -shared # -L../bar -Wl,-rpath,/foo/bar # -shared
LDLIBS = # -lbar
CPPFLAGS = -MMD -MP # -I../bar
DIR = $(BUILD_DIR)/foo
#LDFLAGS += -Wl,-rpath,'$$ORIGIN/../foo'
$(DIR)/foo : $(addprefix $(DIR)/,$(patsubst %.c,%.o,$(wildcard *.c))) # .cpp
# $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@ # CXX for .cpp
$(DIR)/%.o : %.c # .cpp
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< # .cpp
-include $(shell find . -type f -name "*.d")
clean : ; -rm -fr $(DIR)
.PHONY : clean
```
The `.c`, `.h` files in the `.d` files are left without paths.
```
$ cat build/foo/foo.d
/home/ljh/Documents/make_outofsrc/src/build/foo/foo.o: foo.c foo.h
foo.h:
$
```