summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--makefile-so/Makefile33
-rw-r--r--makefile-so/clib.c18
-rw-r--r--makefile-so/clib.h9
-rw-r--r--makefile-so/main.c9
-rwxr-xr-xmakefile-so/test5
5 files changed, 74 insertions, 0 deletions
diff --git a/makefile-so/Makefile b/makefile-so/Makefile
new file mode 100644
index 0000000..9a2de9d
--- /dev/null
+++ b/makefile-so/Makefile
@@ -0,0 +1,33 @@
+CC = gcc
+CCFLAGS=-pedantic -Wall
+LD_OPTS=
+
+# $< - the current dependcy file
+# $@ - the current target file
+# $* - the base name of the current target
+# $? - all dependencies that are newer than the target
+# -fPIV : emit position-independent code
+# -nostartfiles : do not use the standard system startup files when linking
+
+%.o: %.c
+ $(CC) $(CCFLAGS) -c -I. -o $@ $<
+
+default: all
+
+clib.o: clib.c
+ $(CC) $(CCFLAGS) -c -fPIC $<
+
+libclib.so: clib.o
+ $(CC) $(CCFLAGS) -shared -nostartfiles -Wl,-soname,libclib.so -o libclib.so.1.0 $<
+
+ldlinks:
+ @ldconfig -n .
+
+main: libclib.so ldlinks main.o
+ $(CC) $(LD_OPTS) main.o -L. -lclib -o main
+
+all: main
+
+clean:
+ rm -f main *.o *.so* *~
+
diff --git a/makefile-so/clib.c b/makefile-so/clib.c
new file mode 100644
index 0000000..e624baa
--- /dev/null
+++ b/makefile-so/clib.c
@@ -0,0 +1,18 @@
+
+#include "clib.h"
+
+void _init()
+{
+ printf(" _init()\n");
+}
+
+void _fini()
+{
+ printf(" _fini()\n");
+}
+
+void say_hello(FILE *stream)
+{
+ fprintf(stream,"hello world\n");
+}
+
diff --git a/makefile-so/clib.h b/makefile-so/clib.h
new file mode 100644
index 0000000..290c27a
--- /dev/null
+++ b/makefile-so/clib.h
@@ -0,0 +1,9 @@
+
+#ifndef __C_LIB_H__
+#define __C_LIB_H__
+
+#include <stdio.h>
+
+void say_hello(FILE *stream);
+
+#endif /* __C_LIB_H__ */
diff --git a/makefile-so/main.c b/makefile-so/main.c
new file mode 100644
index 0000000..1a30f1f
--- /dev/null
+++ b/makefile-so/main.c
@@ -0,0 +1,9 @@
+#include<stdio.h>
+#include<clib.h>
+
+int main(int argc, char* argv[], char* envp[])
+{
+ say_hello(stdout);
+ return 0;
+}
+
diff --git a/makefile-so/test b/makefile-so/test
new file mode 100755
index 0000000..410ce11
--- /dev/null
+++ b/makefile-so/test
@@ -0,0 +1,5 @@
+#!/bin/bash
+DIR=$(dirname $0)
+cd $DIR && make clean && make || exit 1
+LD_LIBRARY_PATH=. ./main
+