CC        := gcc
WFLAGS    := -Wstrict-prototypes -Wmissing-prototypes \
             -Wmissing-declarations -Wimplicit -Wreturn-type -Wunused \
             -Wcomment -Wformat

DRV_PATH  := ../sis3100
DRV_LIB   := ${DRV_PATH}/lib_sis3100mvme.a

#CPPFLAGS  := -I$(DRV_PATH) -L$(DRV_PATH)
CFLAGS    := -g -ansi $(WFLAGS) -L$(DRV_PATH) -I$(DRV_PATH)

srcdir    := src
EXECS     := $(patsubst src/%.c,bin/%,$(wildcard $(srcdir)/*.c))

VPATH = $(srcdir)

ifndef MIDASSYS
MIDASSYS := /opt/MIDAS.PSI/Versions/Current
endif
CFLAGS += -I$(MIDASSYS)/include

.PHONY: all clean

all: ${EXECS}

bin/%: %.c ${DRV_LIB}
	$(CC) $(CFLAGS) -o $@ $^

clean:
	rm -f *.o core* *~
	rm -f $(EXECS)

${DRV_LIB}:	
	@if test ! -f ${DRV_LIB}; then \
		echo "Building ${DRV_LIB} ..."; \
		cd ${DRV_PATH} && ${MAKE}; \
	fi
