Hi community,
I managed to do out-of-source build.
I use `CPPFLAGS += -MMD -MP` to generate `.d` files.
The `.d` files and the source files are not in the same directory now.
`make` addes path the the target `.o` part,
but not the prerequisites parts `.c`, `.h`.
So, the rules in `.d` files wil
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
On Sat, 2023-03-04 at 21:49 +0800, ljh wrote:
> I managed to do out-of-source build.
>
> I use `CPPFLAGS += -MMD -MP` to generate `.d` files.
> The `.d` files and the source files are not in the same directory
> now. `make` addes path the the target `.o` part,
> but not the prerequisites parts
Hi Paul,
I finally work it out.
Thank you very much for the great help.
$ tree --charset C
.
|-- foo
| |-- foo.c
| |-- foo.h
| `-- Makefile
|-- main
| |-- main.c
| `-- Makefile
|-- Makefile
`-- objdir_tmp
|-- foo
| |-- foo
| |-- foo.d
| |-- foo.o
| |-- li
Can you please give me suggestions to improve it.
1. In thie out of source version, I can not omit recipes in both building and
linking rules. This make it a bit complicated.
2. if I put # comment at the end of the line of export OBJDIR, it causes
mysterious error message in rules involve the v
Updated. Accept a path parameter on command line from the user.
# Makefile for top dir
# $(call version_number,1.2.3)
# major.minor.patch
# libtool manual 4.2: -version-number
define version_number
$(MAKE) -C $@ soname=lib$@.so.$(word 1,$(subst ., ,$(1)))
@ cp $(OBJDIR)/$@/$@ $(OB
Updated. Suggestions are most welcome.
Thanks
---
# Makefile for top dir
# $(call makever,1.2.3)
# major.minor.patch
define makever
$(MAKE) -C $@ soname=lib$@.so.$(word 1,$(subst ., ,$(1)))
@ cp $(OBJDIR)/$@/$@ $(OBJDIR)/$@/lib$@.so.$(1)
@ cd $(OBJDIR)/$@; ln -f -s $(OBJDIR)/$@/lib$@.s