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