## Targets:
# 1. default:  lib_sis3100.a
# 2. mvmelib:  lib_sis3100mvme.a
# 3. shared:   lib_sis3100.so
# 4. libs-all:  1~4, lib_sis3100mvme.so

CC  = gcc
CXX = g++
CP := cp -p

WFLAGS   := -Wstrict-prototypes -Wmissing-prototypes \
            -Wmissing-declarations -Wimplicit -Wreturn-type -Wunused \
            -Wcomment -Wformat
CFLAGS   := -g -ansi $(WFLAGS)

OBJS     =  sis3100_vme_calls.o sharc_utils.o
SLIBNAME := _sis3100
SLIBA    := lib$(SLIBNAME).a
DRV_LIBS = $(SLIBA)

## Shared library
SLIBSO   := lib$(SLIBNAME).so
ifdef NEED_SHLIB
CFLAGS   += -fPIC -shared
CXXFLAGS   += -fPIC -shared
DRV_LIBS += $(SLIBSO)
endif

## Lib for Python interface
PYDRVDIR := ../PySIS3100
PYDRVLIB := ${PYDRVDIR}/$(DRV_LIBSO)

## Interface using MIDAS/PSI mvmestd.h
MLIBNAME := _sis3100mvme
MLIBA    := lib$(MLIBNAME).a
MLIBSO   := lib$(MLIBNAME).so
DRV_LIBS += $(MLIBA)

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

ifdef NEED_SHLIB
DRV_LIBS += $(MLIBSO)
endif

##################################################
all: $(DRV_LIBS)

.PHONY: clean clean-all

shared:  clean
	$(MAKE) NEED_SHLIB=1

mvmelib: clean
	$(MAKE) NEED_MLIB=1

libs-all: clean-all
	$(MAKE) NEED_MLIB=1
	$(MAKE) clean
	$(MAKE) NEED_SHLIB=1 NEED_MLIB=1

clean:
	rm -f *.o *~ \#* *Cint*

clean-all: clean
	rm -f lib_*.a lib_*.so

##################################################
$(SLIBA):  $(OBJS)
$(SLIBSO): $(OBJS)

$(MLIBA):  $(OBJS) sis3100_mvme.o
$(MLIBSO): $(OBJS) sis3100_mvme.o

%.o: %.c sis3100_vme_calls.h

%.a:
	ar cr $@ $^

%.so:
	$(CC) -shared -o $@ $^

