# $URL: http://subversion:8080/svn/gsc/trunk/drivers/LINUX/16AO16/16AO16_Linux_2.x.x.x_DN/utils/makefile $
# $Rev: 56206 $
# $Date: 2025-02-05 08:48:14 -0600 (Wed, 05 Feb 2025) $

# 16AO16: Utilities: make file

default: all

CC			= gcc
CC_FLAGS	= -c -Wall -I../include
DEP_FILE	= makefile.dep
TARGET		= ../lib/16ao16_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	\
			write.o	\
			\
			config_ao.o	\
			count.o		\
			fsamp_ao.o	\
			id.o		\
			reg.o		\
			\
			autocal.o				\
			autocal_status.o		\
			buffer_clear.o			\
			buffer_mode.o			\
			buffer_over_data.o		\
			buffer_over_frame.o		\
			buffer_size.o			\
			buffer_status.o			\
			burst_enable.o			\
			burst_ready.o			\
			burst_trig_src.o		\
			burst_trigger.o			\
			cbl_iso_clock_io.o		\
			cbl_iso_dac_clk_out.o	\
			cbl_iso_trig_out.o		\
			cbl_pol_clock_io.o		\
			cbl_pol_dac_clk_out.o	\
			cbl_pol_trig_in.o		\
			cbl_pol_trig_out.o		\
			channel_sel.o			\
			clock_enable.o			\
			clock_ready.o			\
			clock_ref_src.o			\
			clock_src.o				\
			clock_sw.o				\
			data_format.o			\
			ground_sense.o			\
			initialize.o			\
			irq_sel.o				\
			load_ready.o			\
			load_request.o			\
			nclk.o					\
			nrate.o					\
			output_filter.o			\
			output_mode.o			\
			query.o					\
			range.o					\
			reg_mod.o				\
			reg_read.o				\
			reg_write.o				\
			tx_io_abort.o			\
			tx_io_mode.o			\
			tx_io_over_data.o		\
			tx_io_over_frame.o		\
			tx_io_timeout.o			\
			wait_cancel.o			\
			wait_event.o			\
			wait_status.o			\
			watchdog_enable.o		\
			watchdog_output.o		\
			xcvr_type.o

# Retained for backwards compatibility only:
OBJ_FILES	:= ${OBJ_FILES}			\
			auto_cal_sts.o			\
			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}
