# $URL: http://subversion:8080/svn/gsc/trunk/drivers/LINUX/SIO4%20and%20SIO8/SIO4_Linux_1.x.x_GSC_DN/samples/sbtest/makefile $
# $Rev: 53081 $
# $Date: 2023-06-13 10:10:10 -0500 (Tue, 13 Jun 2023) $

# SIO4: Sample Application: make file

default:	all

CC			= gcc
CC_FLAGS	= -c -Wall -I../../include
DEP_FILE	= makefile.dep
LIB_FILES	= ../../lib/sio4_main.a
TARGET		= sbtest

.NOTPARALLEL: %.o

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

OBJ_FILES	:=								\
			main.o							\
			perform.o						\
			service.o						\
											\
			board_jumpers.o					\
			cable_config.o					\
			clear_dpll_status.o				\
			cts_cable_config.o				\
			dcd_cable_config.o				\
			enable_brg0.o					\
			enable_brg1.o					\
			feature_test.o					\
			get_driver_info.o				\
			init_board.o					\
			init_channel.o					\
			int_notify.o					\
			mod_register.o					\
			mp_config.o						\
			mp_info.o						\
			mp_init.o						\
			mp_reset.o						\
			mp_test.o						\
			no_function.o					\
			osc_info.o						\
			osc_init.o						\
			osc_measure.o					\
			osc_program.o					\
			osc_reference.o					\
			osc_reset.o						\
			osc_test.o						\
			read_int_status.o				\
			read_register.o					\
			read_register_raw.o				\
			reset_channel.o					\
			reset_device.o					\
			reset_fifo.o					\
			reset_usc.o						\
			reset_zilog_chip.o				\
			rx_cable_config.o				\
			rx_fifo_ae_config.o				\
			rx_fifo_af_config.o				\
			rx_fifo_count.o					\
			rx_fifo_full_cfg_chan.o			\
			rx_fifo_full_cfg_glb.o			\
			rx_fifo_size.o					\
			rx_io_abort.o					\
			rx_io_mode_config.o				\
			rxc_usc_config.o				\
			select_dpll_resync.o			\
			send_channel_command.o			\
			set_brg0_mode.o					\
			set_brg0_source.o				\
			set_brg1_mode.o					\
			set_brg1_source.o				\
			set_ctr0_source.o				\
			set_ctr1_source.o				\
			set_dpll_divisor.o				\
			set_dpll_mode.o					\
			set_dpll_source.o				\
			set_rcv_async_prot.o			\
			set_rcv_hdlc_prot.o				\
			set_rcv_isochr_prot.o			\
			set_read_timeout.o				\
			set_rx_clock_source.o			\
			set_sync_byte.o					\
			set_tx_clock_source.o			\
			set_usc_dma_options.o			\
			set_write_timeout.o				\
			set_xmt_async_prot.o			\
			set_xmt_hdlc_prot.o				\
			set_xmt_hdlc_sdlc_loop_prot.o	\
			set_xmt_isochr_prot.o			\
			tx_cable_clock_config.o			\
			tx_cable_config.o				\
			tx_cable_data_config.o			\
			tx_fifo_ae_config.o				\
			tx_fifo_af_config.o				\
			tx_fifo_count.o					\
			tx_fifo_size.o					\
			tx_io_abort.o					\
			tx_io_mode_config.o				\
			txc_usc_config.o				\
			write_register.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: $<
	@-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 $@

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: $@
	@${CC} ${OBJ_FILES} ${LIB_FILES} -o $@ -lm -lpthread -lrt

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

include ${DEP_FILE}
