default: tests
help:
	@echo "USAGE: make pstest"

CC      =       gcc
SRC     =       src
BIN     =       bin

DESTBIN =       $(HOME)/src/bin/$(ARCH)

LPSLIB  :=      $(shell pslib-config --libs)
IPSLIB  :=      $(shell pslib-config --cflags)

INCS	= 	$(IPSLIB)
LIBS	= 	$(LPSLIB)
CFLAGS	=	$(INCS) -std=c99 -Wall -Werror -g
LFLAGS	=	$(LIBS) 

TESTS = \
$(BIN)/tst_psPolynomial.$(ARCH)

tests: $(TESTS)

# dependancy rules for binary code #########################
.PRECIOUS: %.$(ARCH).o
.PRECIOUS: $(BIN)/%.$(ARCH)

%.$(ARCH).o : %.c
	$(CC) $(CFLAGS) -c $< -o $@

$(BIN)/%.$(ARCH) : $(SRC)/%.$(ARCH).o
	@if [ ! -d $(BIN) ]; then mkdir -p $(BIN); fi
	$(CC) $^ -o $@ $(LFLAGS)
	@echo "done with $@"

$(DESTBIN)/%: $(BIN)/%.$(ARCH)
	@if [ ! -d $(DESTBIN) ]; then mkdir -p $(DESTBIN); fi
	rm -f $(DESTBIN)/$*
	cp $(BIN)/$*.$(ARCH) $(DESTBIN)/$*

$(INSTALL): % : $(BIN)/%.$(ARCH)

%.clean :
	rm -f $(BIN)/$*.$(ARCH)
	rm -f $(SRC)/*.$(ARCH).o

%.install:
	make $(DESTBIN)/$*

# utilities #################################################

install:
	for i in $(INSTALL); do make $$i.install; done

clean:	
	rm -f $(BIN)/*.$(ARCH)
	rm -f `find . -name "*.o"`
	rm -f `find . -name "*~"`
	rm -f `find . -name "#*"`
