-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
70 lines (35 loc) · 1.85 KB
/
Makefile
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
# Even if you don't know a bit about Makefiles, this is too easy to understand
# Basics:
# A: B C ---> A (TARGET) depends on B and C (PREREQUISITES)
# [TAB]some commands ---> this should be executed to update A (from B and C)
# PHONY Targets are not meant to be files. They aren't checked or updated.
# PHONY Targets are rules to be executed every time they are called
.PHONY: all clean
# Now, all is the DEFAULT. If you call 'make', it calls for 'make all':
all:example-main libexample-1.so libplugin-cpp.so
# If you call 'make clean', you mean this:
clean:
rm -f *.o *.~ libexample-1.so example-main libplugin-cpp.so
# This is a generic rule to every *.o file depending on some *.cpp file
# of the same name. $^ means all of the PREREQUISITES
.cpp.o:
g++ -c -fPIC $^
# This are using the generic rule above, see? plugin.o from plugin.cpp
plugin.o:plugin.cpp
example-main.o:example-main.cpp
plugin-example.o:plugin-example.cpp
# Now the binaries. $@ is the TARGET. $< means the first PREREQUISITE.
example-main: example-main.o libplugin-cpp.so
g++ -o $@ $< -L. -lplugin-cpp
# This is the Plugin and PluginFactory class library. This will let you
# get your own plugins loaded at runtime. If you don't want to install it
# (like for testing purposes), you can define LD_LIBRARY_PATH to ./
libplugin-cpp.so: plugin.o
g++ -shared -fPIC $^ -o $@ -ldl
# And finally this. Here there is a trick about using g++ to access the linker.
# If you put -lplugin-cpp BEFORE the $<, the linker might not see the symbols
# and just ignore libplugin-cpp.so entirely. To check for a wrong linkage,
# you may use 'ldd -d libexample-1.so'. If there are unresolved symbols, then
# the linkage has just failed. As a good rule, -l fits nicely AT THE END.
libexample-1.so: plugin-example.o libplugin-cpp.so
g++ -o $@ -fPIC $< -shared -L. -rdynamic -lplugin-cpp