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

# SIO4: Document Source Library: make file

default: all

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

.NOTPARALLEL: %.o

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

OBJ_FILES	:=							\
			async_setup.o				\
			async_setup_rx.o			\
			async_setup_tx.o			\
			board_init.o				\
			board_jumpers.o				\
			brg0_enable.o				\
			brg0_set_clock_source.o		\
			brg0_set_mode.o				\
			brg1_enable.o				\
			brg1_set_clock_source.o		\
			brg1_set_mode.o				\
			cable_config.o				\
			channel_command_send.o		\
			channel_init.o				\
			channel_reset.o				\
			close.o						\
			ctr0_set_clock_source.o		\
			ctr1_set_clock_source.o		\
			cts_cable_config.o			\
			dcd_cable_config.o			\
			dma_set_options.o			\
			dpll_clear_status.o			\
			dpll_set_clock_source.o		\
			dpll_set_divisor.o			\
			dpll_set_mode.o				\
			dpll_set_resync.o			\
			driver_info.o				\
			feature_test.o				\
			fifo_reset.o				\
			hdlc_sdlc_loop_setup_rx.o	\
			hdlc_setup_rx.o				\
			hdlc_setup_tx.o				\
			int_notify.o				\
			int_read_status.o			\
			ioctl.o						\
			isochr_setup_rx.o			\
			isochr_setup_tx.o			\
			mp_config.o					\
			mp_info.o					\
			mp_init.o					\
			mp_reset.o					\
			mp_test.o					\
			no_function.o				\
			open.o						\
			osc_info.o					\
			osc_init.o					\
			osc_measure.o				\
			osc_program.o				\
			osc_reference.o				\
			osc_reset.o					\
			osc_test.o					\
			read.o						\
			reg_mod.o					\
			reg_read.o					\
			reg_read_raw.o				\
			reg_write.o					\
			reset_device.o				\
			rx_cable.o					\
			rx_fifo_ae.o				\
			rx_fifo_af.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.o				\
			rx_set_clock_source.o		\
			rxc_usc_config.o			\
			sync_byte_set.o				\
			timeout_set_read.o			\
			timeout_set_write.o			\
			tx_cable.o					\
			tx_cable_clock.o			\
			tx_cable_data.o				\
			tx_fifo_ae.o				\
			tx_fifo_af.o				\
			tx_fifo_count.o				\
			tx_fifo_size.o				\
			tx_io_abort.o				\
			tx_io_mode.o				\
			tx_set_clock_source.o		\
			txc_usc_config.o			\
			usc_reset.o					\
			write.o						\
			zilog_reset.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 *.o
	@echo ==== release Done

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

${TARGET}: makefile ${OBJ_FILES}
	@echo ==== Linking: $@
	@ld -r -o $@ ${OBJ_FILES}

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

include ${DEP_FILE}
