CFLAGS=-g -O

PROGS=test1 test1a test2 test2a

all: $(PROGS)

test1: main1.o ref1.o ref2.o libfoo.so
	$(CC) -o $@ $^ -Wl,-rpath,.
	./$@

test1a: main1.o libref1.so libref2.so libfoo.so
	$(CC) -o $@ $^ -Wl,-rpath,.
	./$@

libfoo.so: foo.o
	$(CC) -shared -o $@ $^ -Wl,--version-script,libfoo.map 

libref1.so: ref1.o
	$(CC) -shared -o $@ $^ -Wl,--version-script,libref1.map 

libref2.so: ref2.o
	$(CC) -shared -o $@ $^ -Wl,--version-script,libref2.map 

test2: main2.o libref1.so libref2.so libfoo.so
	-$(CC) -o $@ $^ -Wl,-rpath,.

test2a: main2.o ref1.o ref2.o libfoo.so
	-$(CC) -o $@ $^ -Wl,-rpath,.

foo.o: foo.c
	$(CC) -c $(CFLAGS) -fPIC $<

ref1.o: ref1.c
	$(CC) -c $(CFLAGS) -fPIC $<

ref2.o: ref2.c
	$(CC) -c $(CFLAGS) -fPIC $<

clean:
	rm -f $(PROGS) a.out *.so *.o *.os

tar:
	tar cfz bug.tar.gz Makefile *.c *.map
