CC=gcc CFLAGS+=-Wall -I. LDFLAGS+=-L. .PHONY: all clean all: example example_static example_dynamic clean: rm -f example *.o lib*.a example: example.o hello.o $(CC) $(LDFLAGS) $^ -o $@ example.o: example.c hello.h $(CC) $(CFLAGS) -c $< -o $@ hello.o: hello.c hello.h debug.h $(CC) $(CFLAGS) -c $< -o $@ libhello.a: hello.o ar rcs $@ $^ example_static: example.o libhello.a $(CC) $(LDFLAGS) example.o -Wl,-Bstatic -lhello -Wl,-Bdynamic -o $@ hello_fpic.o: hello.c hello.h debug.h $(CC) $(CFLAGS) -c -fPIC $< -o $@ libhello.so: hello_fpic.o $(CC) $(LDFLAGS) -shared $^ -o $@ example_dynamic: example.o libhello.so $(CC) $(LDFLAGS) example.o -lhello -L. -o $@