MAKEFLAGS += --no-builtin-rules
CC=gcc
CFLAGS=-std=c11 -pedantic -Wall -Werror -D_XOPEN_SOURCE=700 -c -g -pthread -O0
LD=gcc
LDFLAGS=-pthread
.PHONY: all clean run
all: atomic cas main-static main-dynamic
clean:
rm -f atomic atomic.o
rm -f cas cas.o
rm -f main-static libfoo-static.a
rm -f main-dynamic libfoo-dynamic.so
rm -f main.o foo.o foo-pic.o
%: %.o
$(LD) $(LDFLAGS) -o $@ $^
%.o: %.c
$(CC) $(CFLAGS) -o $@ $<
atomic: atomic.o
atomic.o: atomic.c
cas: cas.o
cas.o: cas.c
%-pic.o: %.c
$(CC) $(CFLAGS) -fPIC -o $@ $<
foo-pic.o: foo.c foo.h
foo.o: foo.c foo.h
main.o: main.c foo.h
libfoo-dynamic.so: foo-pic.o
gcc -shared -fPIC -o $@ $^
libfoo-static.a: foo.o
ar -rcs $@ $^
main-static: libfoo-static.a main.o
$(LD) $(LDFLAGS) -o $@ main.o -L. -lfoo-static
main-dynamic: libfoo-dynamic.so main.o
$(LD) $(LDFLAGS) -o $@ main.o -L. -lfoo-dynamic
run:
LD_LIBRARY_PATH=. ./main-dynamic