summaryrefslogtreecommitdiff
path: root/schulung_tools/linking/hello/Makefile
diff options
context:
space:
mode:
authorManuel Traut <manut@linutronix.de>2019-01-09 16:42:49 +0100
committerJohn Ogness <john.ogness@linutronix.de>2019-01-28 17:25:56 +0106
commitb990733af9d6a07c2130daeb5fd39c75f6804441 (patch)
tree6c5f6486948ab3c1a9ec1a0db6d045d6bb1543c4 /schulung_tools/linking/hello/Makefile
parent6f5bc54bec1449b1713504950cce078b0dac47c1 (diff)
add examples for dynamic linking / loading
one example by doing it manually with an ugly Makefile, another one by using autotools. Signed-off-by: Manuel Traut <manut@linutronix.de>
Diffstat (limited to 'schulung_tools/linking/hello/Makefile')
-rw-r--r--schulung_tools/linking/hello/Makefile33
1 files changed, 33 insertions, 0 deletions
diff --git a/schulung_tools/linking/hello/Makefile b/schulung_tools/linking/hello/Makefile
new file mode 100644
index 0000000..a5b4c26
--- /dev/null
+++ b/schulung_tools/linking/hello/Makefile
@@ -0,0 +1,33 @@
+hello: hello.c libfunc.so
+ $(CROSS_COMPILE)gcc -g -ohello hello.c -L. -lfunc
+
+hello2: hello.c libfunc.a
+ rm -f libfunc.so
+ $(CROSS_COMPILE)gcc -g -ohello2 hello.c -L. -lfunc
+
+libfunc.so: libfunc.so.0.0.1
+ ln -s libfunc.so.0.0.1 libfunc.so
+
+libfunc.so.0.0.1: func1.o func2.o
+ $(CROSS_COMPILE)gcc -shared -olibfunc.so.0.0.1 -Wl,-soname,libfunc.so.0 func1.o func2.o
+
+libfunc.a: func1.o func2.o
+ $(CROSS_COMPILE)ar cr libfunc.a func1.o func2.o
+ $(CROSS_COMPILE)ranlib libfunc.a
+
+func1.o: func1.c
+ $(CROSS_COMPILE)gcc -fPIC -g -c func1.c
+
+func2.o: func2.c
+ $(CROSS_COMPILE)gcc -fPIC -g -c func2.c
+
+install_lib: libfunc.so.0.0.1
+ echo "/opt/acme/lib" > /etc/ld.so.conf.d/acme.conf
+ mkdir -p /opt/acme/lib
+ cp libfunc.so.0.0.1 /opt/acme/lib
+ ldconfig
+
+clean:
+ rm -f hello hello2 *.o lib*
+
+.PHONY: clean