diff --git a/Makefile b/Makefile index b8b3173..407baf3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,9 @@ -example: main.o foo.o - $(CC) main.o foo.o -o $@ + +SOURCES = $(wildcard *.c) +OBJECTS = $(SOURCES:.c=.o) + +example: $(OBJECTS) + $(CC) $(OBJECTS) -o $@ %.o: %.c $(CC) -c $< -o $@ @@ -7,4 +11,4 @@ example: main.o foo.o .PHONY: clean clean: - rm -f example *.o + rm -f example $(OBJECTS) diff --git a/bar.c b/bar.c new file mode 100644 index 0000000..2c0bab8 --- /dev/null +++ b/bar.c @@ -0,0 +1,7 @@ +#include "bar.h" + +#include + +void bar(void) { + puts("Hello World from bar()."); +} diff --git a/bar.h b/bar.h new file mode 100644 index 0000000..01abcb6 --- /dev/null +++ b/bar.h @@ -0,0 +1,6 @@ +#ifndef BAR_H +#define BAR_H + +void bar(void); + +#endif diff --git a/main.c b/main.c index 7de1619..3ddacc7 100644 --- a/main.c +++ b/main.c @@ -2,9 +2,11 @@ #include #include "foo.h" +#include "bar.h" int main(void) { puts("Hello World"); foo(); + bar(); return EXIT_SUCCESS; }