CFLAGS=-O2 -g
PICFLAGS=-fPIC

PROGS= main

all: $(PROGS)
	for f in $(PROGS); do echo "Running: $$f"; ./$$f; \
	  if [ $$? != 0 ]; then echo Failed; fi; done

main: main.o libfoo.a
	$(CC) -static -o $@ $^

libfoo.a: foo.o bar.o
	ar rcs $@ $^

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

bar.o: bar.c
	$(CC) $(PICFLAGS) $(CFLAGS) -c $<

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

tar:
	tar cfz /tmp/bug.tar.gz Makefile *.c
