SCPILIB = scpilib.a
SCPILIB_CSRC = \
	scpilib.c \
	vxi11_clnt.c \
	vxi11_svc.c \
	vxi11_xdr.c
SCPILIB_OBJS = $(patsubst %.c, %.o, $(SCPILIB_CSRC))
SCPILIB_HDRS = \
	vxi11.h \
	scpilib.h

SCPITEST_CSRC = \
	test.c
SCPITEST_OBJS = $(patsubst %.c,%.o, $(SCPITEST_CSRC))
SCPITEST_HDRS = \
	scpilib.h \

# define variables for building RPCL (.x) files
RPCGEN=rpcgen -N -M
UNAME_S := $(shell uname -s)

CFLAGS += -Wno-unused
CFLAGS  += -fPIC

all:	$(SCPILIB) scpitest

scpitest: $(SCPITEST_OBJS) $(SCPITEST_HDRS) $(SCPILIB) Makefile
	$(CC) $(CFLAGS) $(LDFLAGS) $(SCPITEST_OBJS) -o $@ $(SCPILIB) $(LDLIBS) -lm

$(SCPITEST_OBJS): %.o: %.c $(SCPITEST_HDRS) $(SCPILIB) Makefile
	$(CC) $(CFLAGS) -c $< -o $*.o

$(SCPILIB_OBJS): %.o: %.c $(SCPILIB_HDRS) $(SCPILIB_CSRC) Makefile
	$(CC) $(CFLAGS) -c $< -o $*.o

$(SCPILIB): $(SCPILIB_OBJS) Makefile
	$(AR) $(ARFLAGS) $@ $^

# RPC files
# these need to be generated one at a time to control the server
# creation properly
ifeq ($(UNAME_S),Linux)
vxi11_clnt.c vxi11.h vxi11_xdr.c: vxi11.x Makefile
	$(RM) -f $@
	$(RPCGEN) $(RPCFLAGS)  vxi11.x
endif

vxworks: vxi11_clnt.c vxi11_svc.c vxi11.h vxi11_xdr.c
	for f in $(SCPILIB_CSRC) ; do \
		sed -i 's/memory\.h/string\.h/' $$f ; \
	done

romfs:
#	$(ROMFSINST) -e CONFIG_USER_EX1048A_SERVER    /bin/scpitest

ifeq ($(UNAME_S),Linux)
clean:
	rm -f *.o *.gdb scpitest
	rm -f vxi11_clnt.c vxi11_clnt.c vxi11.h vxi11_xdr.c vxi11_svc.c
	rm -f scpilib.a
endif

ifeq ($(UNAME_S), Darwin)
clean:
	rm -f *.o *.gdb scpitest
	rm -f scpilib.a
endif
