From 2224f05d43a0d782b626d09f397767597b3d7f4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Mon, 16 Apr 2012 09:40:09 +0200 Subject: add makefile-so --- makefile-so/Makefile | 33 +++++++++++++++++++++++++++++++++ makefile-so/clib.c | 18 ++++++++++++++++++ makefile-so/clib.h | 9 +++++++++ makefile-so/main.c | 9 +++++++++ makefile-so/test | 5 +++++ 5 files changed, 74 insertions(+) create mode 100644 makefile-so/Makefile create mode 100644 makefile-so/clib.c create mode 100644 makefile-so/clib.h create mode 100644 makefile-so/main.c create mode 100755 makefile-so/test 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 + +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 +#include + +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 + -- cgit v1.1-2-g2b99