# $URL: http://subversion:8080/svn/gsc/trunk/drivers/LINUX/24DSI/24DSI_Linux_3.x_and_4.x_GSC_DN/utils/makefile $
# $Rev: 55095 $
# $Date: 2024-08-21 15:50:19 -0500 (Wed, 21 Aug 2024) $

# 24DSI: Utilities: make file

default: all

CC			= gcc
CC_FLAGS	= -c -Wall -I../include
DEP_FILE	= makefile.dep
TARGET		= ../lib/24dsi_utils.a

.NOTPARALLEL: %.o

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

ifeq ("${GSC_LIB_COMP_FLAGS}","")
GSC_LIB_COMP_FLAGS_MSG=
else
GSC_LIB_COMP_FLAGS_MSG="  (added '${GSC_LIB_COMP_FLAGS}')"
endif

ifeq ("${GSC_LIB_LINK_FLAGS}","")
GSC_LIB_LINK_FLAGS_MSG=
else
GSC_LIB_LINK_FLAGS_MSG="  (added '${GSC_LIB_LINK_FLAGS}')"
endif

OBJ_FILES	:=		\
			close.o	\
			init.o	\
			ioctl.o	\
			open.o	\
			read.o	\
			\
			ch_grp_x_src.o		\
			config_ai.o			\
			count.o				\
			fref.o				\
			fsamp_ai.o			\
			id.o				\
			rate_div_x_ndiv.o	\
			rate_gen_x_nrate.o	\
			rate_gen_x_nref.o	\
			rate_gen_x_nvco.o	\
			reg.o				\
			\
			adc_rate_out.o			\
			ain_buf_clear.o			\
			ain_buf_input.o			\
			ain_buf_overflow.o		\
			ain_buf_thresh.o		\
			ain_buf_underflow.o		\
			ain_coupling.o			\
			ain_filter.o			\
			ain_filter_00_03.o		\
			ain_filter_04_07.o		\
			ain_filter_08_11.o		\
			ain_filter_12_15.o		\
			ain_filter_16_19.o		\
			ain_filter_20_23.o		\
			ain_filter_24_27.o		\
			ain_filter_28_31.o		\
			ain_filter_sel.o		\
			ain_mode.o				\
			ain_range.o				\
			ain_range_00_03.o		\
			ain_range_04_07.o		\
			ain_range_08_11.o		\
			ain_range_12_15.o		\
			ain_range_16_19.o		\
			ain_range_20_23.o		\
			ain_range_24_27.o		\
			ain_range_28_31.o		\
			ain_range_sel.o			\
			autocal.o				\
			ch_grp_0_src.o			\
			ch_grp_1_src.o			\
			ch_grp_2_src.o			\
			ch_grp_3_src.o			\
			channel_order.o			\
			channels_ready.o		\
			coupling_mode_ac.o		\
			coupling_mode_dc.o		\
			data_format.o			\
			data_width.o			\
			ext_clk_src.o			\
			ext_trig.o				\
			gps_enable.o			\
			gps_locked.o			\
			gps_polarity.o			\
			gps_rate_locked.o		\
			gps_target_rate.o		\
			gps_tolerance.o			\
			init_mode.o				\
			initialize.o			\
			irq_sel.o				\
			pll_ref_freq_hz.o		\
			query.o					\
			rate_div_0_ndiv.o		\
			rate_div_1_ndiv.o		\
			rate_gen_a_nrate.o		\
			rate_gen_a_nref.o		\
			rate_gen_a_nvco.o		\
			rate_gen_b_nrate.o		\
			rate_gen_b_nref.o		\
			rate_gen_b_nvco.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		\
			sw_sync.o				\
			sw_sync_mode.o			\
			ta_inv_ext_trigger.o	\
			thres_flag_cbl.o		\
			wait_cancel.o			\
			wait_event.o			\
			wait_status.o			\
			xcvr_type.o

# Retained for backwards compatibility only:
OBJ_FILES	:= ${OBJ_FILES}			\
			auto_calibrate.o		\

include ./gsc_util_makefile.inc
include ./gsc_util_makefile_pci.inc
include ./os_util_makefile.inc

# 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_LIB_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_LIB_COMP_FLAGS}

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

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

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

${TARGET}: ${OBJ_FILES} ${GSC_TARGET} ${PLX_TARGET} ${OS_TARGET}
	@echo ==== Linking: $@  ${GSC_LIB_LINK_FLAGS_MSG}
	@ld -r -o $@ ${OBJ_FILES} ${GSC_LIB_LINK_FLAGS}

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

include ${DEP_FILE}
