From e37f95ba81000477be8c1775ed1b3357b15fe4de Mon Sep 17 00:00:00 2001 From: Aleksey Lobanov Date: Mon, 12 Oct 2020 23:38:41 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=94=D0=974?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 04_Multifile/Makefile | 53 +++++++++++++++++++++++++++++++++++++++++++ 04_Multifile/README | 2 ++ 04_Multifile/const.c | 1 + 04_Multifile/fun.c | 11 +++++++++ 04_Multifile/outlib.h | 4 ++++ 5 files changed, 71 insertions(+) create mode 100644 04_Multifile/Makefile create mode 100644 04_Multifile/README create mode 100644 04_Multifile/const.c create mode 100644 04_Multifile/fun.c create mode 100644 04_Multifile/outlib.h diff --git a/04_Multifile/Makefile b/04_Multifile/Makefile new file mode 100644 index 0000000..0af158c --- /dev/null +++ b/04_Multifile/Makefile @@ -0,0 +1,53 @@ +GENERATES = prog prog-a prog-so README libout.a libout.so +TRASH = *.o *~ o.* + +%.o: %.c + cc $< -c -o $@ + +fun.o: outlib.h + +all: README prog prog-a + +prog: const.o fun.o prog.o + cc $^ -o $@ + +prog-a: libout.a prog.o + cc -L. prog.o -lout -o prog-a + +libout.a: const.o fun.o + ar -rcs libout.a const.o fun.o + + +prog-so: libout.so prog.o + cc -L. prog.o -lout -o prog-so + +libout.so: const.c fun.c outlib.h + cc fun.c -c -fPIC -o fun-pic.o + cc const.c -c -fPIC -o const-pic.o + cc -shared fun-pic.o const-pic.o -o libout.so + + +test: prog prog-a prog-so + ./prog hello 2>&1 > prog.test.o + ./prog-a hello 2>&1 > prog-a.test.o + LD_LIBRARY_PATH=`pwd` ./prog-so hello 2>&1 > prog-so.test.o + cmp prog.test.o prog-a.test.o + cmp prog-a.test.o prog-so.test.o + + ./prog hell o world 2>&1 > prog.test.o + ./prog-a hell o world 2>&1 > prog-a.test.o + LD_LIBRARY_PATH=`pwd` ./prog-so hell o world 2>&1 > prog-so.test.o + cmp prog.test.o prog-a.test.o + cmp prog-a.test.o prog-so.test.o + + + +README: prog + ./$< 2> $@ + +clean: + rm -f $(TRASH) + +distclean: clean + rm -rf $(GENERATES) + diff --git a/04_Multifile/README b/04_Multifile/README new file mode 100644 index 0000000..c0bcd94 --- /dev/null +++ b/04_Multifile/README @@ -0,0 +1,2 @@ +./prog v0.00: Print all arguments + Usage: ./prog arg1 [arg2 […]] diff --git a/04_Multifile/const.c b/04_Multifile/const.c new file mode 100644 index 0000000..65c3545 --- /dev/null +++ b/04_Multifile/const.c @@ -0,0 +1 @@ +int Count=0; diff --git a/04_Multifile/fun.c b/04_Multifile/fun.c new file mode 100644 index 0000000..0b3ecf8 --- /dev/null +++ b/04_Multifile/fun.c @@ -0,0 +1,11 @@ +#include +#include "outlib.h" + +void output(char *str) { + printf("%d: %s\012", Count++, str); +} + +void usage(char *prog) { + fprintf(stderr, "%s v%.2f: Print all arguments\012\t"\ + "Usage: %s arg1 [arg2 […]]\012", prog, VERSION, prog); +} diff --git a/04_Multifile/outlib.h b/04_Multifile/outlib.h new file mode 100644 index 0000000..15b4731 --- /dev/null +++ b/04_Multifile/outlib.h @@ -0,0 +1,4 @@ +void output(char *); +void usage(char *); +extern int Count; +#define VERSION 0.0