# $URL: http://subversion:8080/svn/gsc/trunk/drivers/LINUX/16AI32SSC/samples/sbtest/makefile $
# $Rev: 54744 $
# $Date: 2024-07-01 09:31:31 -0500 (Mon, 01 Jul 2024) $

# 16AI32SSC: Sample Application: make file

default:	all

CC			= gcc
CC_FLAGS	= -c -Wall -I../../include -L/usr/lib
DEP_FILE	= makefile.dep
LIB_FILES	= ../../lib/16ai32ssc_main.a ../../lib/lib16ai32ssc_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	:=						\
			main.o					\
			perform.o				\
			service.o				\
									\
			adc_clk_src.o			\
			adc_enable.o			\
			ain_buf_clear.o			\
			ain_buf_level.o			\
			ain_buf_overflow.o		\
			ain_buf_thr_lvl.o		\
			ain_buf_thr_sts.o		\
			ain_buf_underflow.o		\
			ain_mode.o				\
			ain_range.o				\
			autocal.o				\
			burst_busy.o			\
			burst_sync.o			\
			chan_active.o			\
			chan_first.o			\
			chan_last.o				\
			chan_single.o			\
			data_format.o			\
			data_packing.o			\
			initialize.o			\
			input_sync.o			\
			io_inv.o				\
			irq0_sel.o				\
			irq1_sel.o				\
			query.o					\
			rag_enable.o			\
			rag_nrate.o				\
			rbg_clk_src.o			\
			rbg_enable.o			\
			rbg_nrate.o				\
			rbg_sync_output.o		\
			reg_mod.o				\
			reg_read.o				\
			reg_write.o				\
			rx_io_abort.o			\
			rx_io_mode.o			\
			rx_io_overflow.o		\
			rx_io_timeout.o			\
			rx_io_underflow.o		\
									\
			scan_marker.o			\
			scan_marker_val.o		\
									\
			aux_.o					\
			aux_clk_mode.o			\
			aux_in_pol.o			\
			aux_noise.o				\
			aux_out_pol.o			\
			aux_sync_mode.o			\
									\
			tt.o					\
			tt_adc_clk_src.o		\
			tt_adc_enable.o			\
			tt_chan_mask.o			\
			tt_enable.o				\
			tt_log_mode.o			\
			tt_nrate.o				\
			tt_ref_clk_src.o		\
			tt_ref_val_mode.o		\
			tt_ref_xx.o				\
			tt_reset.o				\
			tt_reset_ext.o			\
			tt_tagging.o			\
			tt_thr_xx.o				\
			tt_trig_mode.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}: ${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}
