# 
# Makefile for neesdaq
# Paul Hubbard hubbard@mcs.anl.gov
# 4/2003


# Figure out which operating system to build for
OPSYS = $(shell uname -s)

CC = cc
CFLAGS = -g -Wall -I../flog -I../nsds-driver -I../dataq-194

LDFLAGS = -g -L. -L../flog -L../nsds-driver -L../dataq-194
LOADLIBS = -ladxl_util -lnsds_util -lflog -ldi194 -lpthread -lm

#Target: common library
LIB_APP = libadxl_util.a
LIB_OBJ = adxl_util.o
LIB_SRC = adxl_util.c
LIB_HDR = adxl_util.h

# Target: DAQ program
DAQ_APP = nees-adxl
DAQ_SRC = nees-adxl.c
DAQ_OBJ = nees-adxl.o

# Target: Test program
TST_APP = adxl-simple
TST_SRC = adxl-simple.c
TST_OBJ = adxl-simple.o

# Emacs source code browser/db
etags = TAGS

# CVS changelog
CLOG = ChangeLog

# Hold-all 
APPS = $(DAQ_APP) $(TST_APP)
SOURCE = $(DAQ_SRC) $(TST_SRC) $(LIB_SRC)
OBJECTS =  $(DAQ_OBJ) $(TST_OBJ) $(LIB_OBJ)
INCLUDES = $(LIB_HDR)

# Default make target
bins: $(LIB_APP) $(DAQ_APP) $(TST_APP) $(etags)

# add doxygen and changelog, mostly for developers
all: $(LIB_APP) $(DAQ_APP) $(TST_APP) $(etags) doxygen $(CLOG)

#######################
# OS-specific stuff
# Mac OSX
ifeq ($(OPSYS), Darwin)
 CFLAGS += -I/sw/include/gnugetopt
 LOADLIBS = -ladxl_util -lnsds_util -lflog -ldi194 -lgnugetopt -lpthread -lm
 LDFLAGS += -L/sw/lib
endif

# Explicit dependency
$(OBJECTS): $(SOURCE) $(INCLUDES) $(LIB_HDR)

# General compliation rule
.c.o:	$(SOURCE) $(INCLUDES)
	$(CC) -c $(CFLAGS) $< 

# Library
$(LIB_APP): $(LIB_OBJ)
	ar r $(LIB_APP) $(LIB_OBJ)
	ranlib $(LIB_APP)

# daq app
$(DAQ_APP): $(LIB_APP) $(DAQ_OBJ)
	$(CC) $(LDFLAGS) $(DAQ_OBJ) $(LOADLIBS) -o $(DAQ_APP)

# test app
$(TST_APP): $(LIB_APP) $(TST_OBJ)
	$(CC) $(LDFLAGS) $(TST_OBJ) $(LOADLIBS) -o $(TST_APP)
 
clean:
	-rm -f $(APPS) $(OBJECTS) $(LIB_APP) $(etags)

# Etags build rule
$(etags):	$(SOURCE) $(INCLUDES)
	-etags $(INCLUDES) $(SOURCE) 

# Doxygen docs - see also Doxyfile
doxygen: $(SOURCE) $(INCLUDES)
	-doxygen

# Changelog - must have cvs2cl.pl in path
$(CLOG): $(SOURCE) $(INCLUDES)
	-cvs2cl.pl
