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
| |-- libfoo.so ->
/home/ljh/Documents/hello_makefile_OutOfSRC/src//objdir_tmp/foo/libfoo.so.6.2.3
| |-- libfoo.so.6 ->
/home/ljh/Documents/hello_makefile_OutOfSRC/src//objdir_tmp/foo/libfoo.so.6.2.3
| `-- libfoo.so.6.2.3
`-- main
|-- main
|-- main.d
`-- main.o
5 directories, 15 files
$
# Makefile for top dir
export OBJDIR = $(dir $(realpath $(lastword $(MAKEFILE_LIST))))/objdir_tmp
# $(call version_number,1.2.3)
# major.minor.patch
# libtool manual 4.2: -version-number
define version_number
$(MAKE) -C $@ [email protected].$(word 1,$(subst ., ,$(1)))
cp $(OBJDIR)/$@/$@ $(OBJDIR)/$@/[email protected].$(1)
cd $(OBJDIR)/$@; ln -f -s $(OBJDIR)/$@/[email protected].$(1)
$(OBJDIR)/$@/[email protected].$(word 1,$(subst ., ,$(1))); cd ..
cd $(OBJDIR)/$@; ln -f -s $(OBJDIR)/$@/[email protected].$(1)
$(OBJDIR)/$@/[email protected]; cd ..
endef
SUBDIRS = main foo
all : $(SUBDIRS)
install : $(SUBDIRS)
main : foo
main : ; $(MAKE) -C $@
foo : ; $(call version_number,6.2.3)
# make DESTDIR=~/foo install
install :
install -d "$(DESTDIR)/usr/local/bin"
install -d "$(DESTDIR)/usr/local/lib"
install -m 0755 $(OBJDIR)/main/main "$(DESTDIR)/usr/local/bin"
install -m 0755 $(OBJDIR)/foo/*.so* "$(DESTDIR)/usr/local/lib"
clean : ; -rm -fr $(OBJDIR)
.PHONY : $(SUBDIRS) all install clean