-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile_7_soname_rpath
138 lines (115 loc) · 3.22 KB
/
Makefile_7_soname_rpath
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# Makefile with soname and symbolic links
# Makefile with rpath for build and install
$ ls
bar foo main1 main2 Makefile
$
$ find . | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
.
|____foo
| |____Makefile
| |____foo.c
| |____foo.h
|____main1
| |____main1.c
| |____Makefile
|____Makefile
|____bar
| |____bar.c
| |____Makefile
| |____bar.h
|____main2
| |____main2.c
| |____Makefile
$
$ cat Makefile
SUBDIRS = bar foo main1 main2
all : $(SUBDIRS)
foo : bar
main1 : foo
main2 : foo
install : $(SUBDIRS)
define make_so_with_versions # version soversion
$(MAKE) -C $@ soversion=lib$@.so.$(2)
cp $@/$@ $@/lib$@.so.$(1)
cd $@; ln -f -s lib$@.so.$(1) lib$@.so.$(2); cd ..
cd $@; ln -f -s lib$@.so.$(1) lib$@.so; cd ..
endef
bar :
$(call make_so_with_versions,1.2.3,1.2) #,version,soversion
foo :
$(call make_so_with_versions,99.1890.70,99.1890) #,version,soversion
main1 :
$(MAKE) -C $@
main2 :
$(MAKE) -C $@
# make DESTDIR=~/myproject install
install :
install -d "$(DESTDIR)/usr/local/bin"
install -d "$(DESTDIR)/usr/local/lib"
install -m755 main1/main1 "$(DESTDIR)/usr/local/bin"
install -m755 main2/main2 "$(DESTDIR)/usr/local/bin"
install -m755 bar/*.so bar/*.so.* "$(DESTDIR)/usr/local/lib"
install -m755 foo/*.so foo/*.so.* "$(DESTDIR)/usr/local/lib"
clean :
for dir in $(SUBDIRS); do \
$(MAKE) -C $$dir $@; \
done
.PHONY : $(SUBDIRS) all clean install
$
$ cat main1/Makefile
# build shared library with -fPIC, -shared
CFLAGS = -g # -O3 -fPIC # CXXFLAGS for .cpp
CPPFLAGS = -MMD -MP -I../foo
LDFLAGS = -L../foo -Wl,-rpath,'$$ORIGIN/../foo' # -shared
LDLIBS = -lfoo
#CC = $(CXX) # link with CXX for .cpp
LDFLAGS += -Wl,-rpath,'$$ORIGIN/../lib'
# target name is basename of one of the source files
main1 : $(patsubst %.c,%.o,$(wildcard *.c)) # .cpp
-include *.d
clean : ; -rm -fr *.o *.d main1
.PHONY : clean
$
$ cat main2/Makefile
# build shared library with -fPIC, -shared
CFLAGS = -g # -O3 -fPIC # CXXFLAGS for .cpp
CPPFLAGS = -MMD -MP -I../foo
LDFLAGS = -L../foo -Wl,-rpath,'$$ORIGIN/../foo' # -shared
LDLIBS = -lfoo
#CC = $(CXX) # link with CXX for .cpp
LDFLAGS += -Wl,-rpath,'$$ORIGIN/../lib'
# target name is basename of one of the source files
main2 : $(patsubst %.c,%.o,$(wildcard *.c)) # .cpp
-include *.d
clean : ; -rm -fr *.o *.d main2
.PHONY : clean
$
$ cat foo/Makefile
# build shared library with -fPIC, -shared
CFLAGS = -g -fPIC # -O3 # CXXFLAGS for .cpp
CPPFLAGS = -MMD -MP -I../bar
LDFLAGS = -shared -L../bar -Wl,-rpath,'$$ORIGIN/../bar'
LDLIBS = -lbar
#CC = $(CXX) # link with CXX for .cpp
LDFLAGS += -Wl,-rpath,'$$ORIGIN/../lib'
LDFLAGS += -Wl,-soname,$(soversion)
# target name is basename of one of the source files
foo : $(patsubst %.c,%.o,$(wildcard *.c)) # .cpp
-include *.d
clean : ; -rm -fr *.o *.d foo *.so *.so.*
.PHONY : clean
$
$ cat bar/Makefile
# build shared library with -fPIC, -shared
CFLAGS = -g -fPIC # -O3 # CXXFLAGS for .cpp
CPPFLAGS = -MMD -MP # -I../foo
LDFLAGS = -shared # -L../foo -Wl,-rpath,'$$ORIGIN/../foo' #
LDLIBS = # -lfoo
#CC = $(CXX) # link with CXX for .cpp
LDFLAGS += -Wl,-soname,$(soversion)
# target name is basename of one of the source files
bar : $(patsubst %.c,%.o,$(wildcard *.c)) # .cpp
-include *.d
clean : ; -rm -fr *.o *.d bar *.so *.so.*
.PHONY : clean
$