# $URL: http://subversion:8080/svn/gsc/trunk/drivers/LINUX/12AISS8AO4/samples/sbtest/makefile $
# $Rev: 51900 $
# $Date: 2022-10-20 10:02:06 -0500 (Thu, 20 Oct 2022) $

# 12AISS8AO4: Sample Application: make file

default:	all

CC			= gcc
CC_FLAGS	= -c -Wall -I../../include -L/usr/lib
DEP_FILE	= makefile.dep
LIB_FILES	= ../../lib/12aiss8ao4_main.a ../../lib/lib12aiss8ao4_api.so
TARGET		= sbtest

.NOTPARALLEL: %.o

ECHO	:= ${shell ls /bin/echo 2>/dev/null | wc -l}
ifeq ("${ECHO}","1")
ECHO	:= /bin/echo
else
ECHO	:= echo
endif

ifeq ("${GSC_APP_COMP_FLAGS}","")
GSC_APP_COMP_FLAGS_MSG=
else
GSC_APP_COMP_FLAGS_MSG="  (added '${GSC_APP_COMP_FLAGS}')"
endif

ifeq ("${GSC_APP_LINK_FLAGS}","")
GSC_APP_LINK_FLAGS_MSG=
else
GSC_APP_LINK_FLAGS_MSG="  (added '${GSC_APP_LINK_FLAGS}')"
endif

OBJ_FILES	:=					\
			ai_buf_clear.o		\
			ai_buf_level.o		\
			ai_buf_overflow.o	\
			ai_buf_thr_lvl.o	\
			ai_buf_thr_sts.o	\
			ai_burst_enable.o	\
			ai_burst_size.o		\
			ai_burst_status.o	\
			ai_chan_sel.o		\
			ai_enable.o			\
			ai_mode.o			\
			ai_range_a.o		\
			ai_range_b.o		\
			ai_sw_clock.o		\
			ai_sw_trigger.o		\
			ao_clock_mode.o		\
			ao_range.o			\
			ao_timing.o			\
			ao_sw_clock.o		\
			auto_cal_sts.o		\
			auto_calibrate.o	\
			data_format.o		\
			dio_dir_out.o		\
			dio_read.o			\
			dio_write.o			\
			gen_a_enable.o		\
			gen_a_ndiv.o		\
			gen_b_enable.o		\
			gen_b_ndiv.o		\
			oper_mode.o			\
			initialize.o		\
			irq_enable.o		\
			main.o				\
			perform.o			\
			query.o				\
			reg_mod.o			\
			reg_read.o			\
			reg_write.o			\
			service.o			\
			rx_io_abort.o		\
			rx_io_mode.o		\
			rx_io_overflow.o	\
			rx_io_timeout.o		\
			wait_cancel.o		\
			wait_event.o		\
			wait_status.o


# Sort object file list to compile most recentlty changed sources first.
OBJ_FILES:= $(shell ls -t $(patsubst %.o,%.c,${OBJ_FILES}))
OBJ_FILES:= $(patsubst %.c,%.o,${OBJ_FILES})

.c.o:
	@echo == Compiling: $<  ${GSC_APP_COMP_FLAGS_MSG}
	@-chmod +rw ${DEP_FILE}
	@# Get the dependency list for this module.
	@-${CC} -MM ${CC_FLAGS} $< > .tmp1
	@# Remove the trailing white space and backslash.
	@-sed -e "s/[ ]*[\\\\]//g" < .tmp1 > .tmp2
	@# Put everything on seperate lines.
	@-tr [:space:] \\n < .tmp2 > .tmp3
	@# Remove all of the system include files.
	@-grep -v "^[ ]*/" < .tmp3 > .tmp4
	@# Remove all empty lines.
	@-grep [[:alnum:]] < .tmp4 > .tmp5
	@# Put everything on the same line.
	@-tr '\n' '\040' < .tmp5 > .tmp6
	@-${ECHO} -e '\012' >> .tmp6
	@# Add all of the other dependencies to the end of this file.
	@-echo >> ${DEP_FILE}
	@-grep -v "^[ ]*$@" < ${DEP_FILE} >> .tmp6
	@# Remove blank lines from the list.
	@-grep "[[:alnum:]]" < .tmp6 > .tmp7
	@# Sort the list and put it in the dependency file.
	@-sort < .tmp7 > ${DEP_FILE}
	@# Cleanup.
	@rm -f ${DEP_FILE}.tmp* .tmp*
	@# Compile the module.
	@${CC} ${CC_FLAGS} $< -o $@ ${GSC_APP_COMP_FLAGS}



all: ${TARGET}
	@echo ==== All Done

release: ${TARGET}
	@rm -f *.a *.o
	@echo ==== Release Done

clean:
	@echo ==== Cleaning ${TARGET} ...
	@rm -f *.a *.o ${TARGET}
	@-chmod +rw ${DEP_FILE}
	@echo > ${DEP_FILE}

${TARGET}: makefile ${OBJ_FILES} ${LIB_FILES}
	@echo ==== Linking: $@  ${GSC_APP_LINK_FLAGS_MSG}
	@${CC} ${OBJ_FILES} ${LIB_FILES} -o $@ -lm -lpthread -lrt ${GSC_APP_LINK_FLAGS}

${DEP_FILE}:
	@echo ==== Creating: $@
	@echo > ${DEP_FILE}

include ${DEP_FILE}
