# $URL: http://subversion:8080/svn/gsc/trunk/drivers/LINUX/SIO4%20and%20SIO8/SIO4_Linux_2.x.x_GSC_DN/async/api/makefile $
# $Rev: 56250 $
# $Date: 2025-03-24 09:28:25 -0500 (Mon, 24 Mar 2025) $

# SIO4: Asynchronous Protocol Library: API Library: make file

default: all

CC			= gcc
CC_FLAGS	= -c -Wall -I../../include
DEP_FILE	= makefile.dep
TARGET		= ../../lib/sio4_async.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	:=								\
			cable_dcd.o						\
			cable_dtr_dsr.o					\
			cable_enable.o					\
			cable_legacy_rxc.o				\
			cable_legacy_rxd_dcd.o			\
			cable_legacy_txc.o				\
			cable_legacy_txd_cts.o			\
			cable_loopback_mode.o			\
			cable_mode.o					\
			cable_protocol.o				\
			cable_rts.o						\
			cable_term_enable.o				\
			cable_txaux.o					\
			cable_txc.o						\
			cable_txd.o						\
			close.o							\
			get.o							\
			init.o							\
			init_data.o						\
			ioctl.o							\
			open.o							\
			osc_prog.o						\
			osc_ref.o						\
			read.o							\
			rx.o							\
			rx_bit_rate.o					\
			rx_char_len.o					\
			rx_enable.o						\
			rx_encoding.o					\
			rx_fifo_ae.o					\
			rx_fifo_af.o					\
			rx_fifo_full_cfg.o				\
			rx_fifo_size.o					\
			rx_io_dma_thresh.o				\
			rx_io_mode.o					\
			rx_io_overrun.o					\
			rx_io_pio_thresh.o				\
			rx_io_timeout.o					\
			rx_io_underrun.o				\
			rx_mode.o						\
			rx_parity_enable.o				\
			rx_parity_type.o				\
			rx_status_word.o				\
			rx_sync_byte.o					\
			rx_time_stamp_clk_src.o			\
			rx_time_stamp_enable.o			\
			set.o							\
			sio4_async_t.o					\
			show.o							\
			tx.o							\
			tx_bit_rate.o					\
			tx_char_len.o					\
			tx_enable.o						\
			tx_encoding.o					\
			tx_fifo_ae.o					\
			tx_fifo_af.o					\
			tx_fifo_empty_cfg.o				\
			tx_fifo_size.o					\
			tx_fifo_space_cfg.o				\
			tx_idle_cond.o					\
			tx_io_dma_thresh.o				\
			tx_io_mode.o					\
			tx_io_overrun.o					\
			tx_io_pio_thresh.o				\
			tx_io_timeout.o					\
			tx_mode.o						\
			tx_parity_enable.o				\
			tx_parity_type.o				\
			usc_brg0_clk_src.o				\
			usc_brg0_divider.o				\
			usc_brg0_enable.o				\
			usc_brg0_mode.o					\
			usc_brg1_clk_src.o				\
			usc_brg1_divider.o				\
			usc_brg1_enable.o				\
			usc_brg1_mode.o					\
			usc_ctr0_clk_src.o				\
			usc_ctr0_rate.o					\
			usc_ctr1_clk_src.o				\
			usc_ctr1_rate_src.o				\
			usc_cts.o						\
			usc_cts_legacy.o				\
			usc_dcd.o						\
			usc_dcd_legacy.o				\
			usc_dpll_rate.o					\
			usc_mode.o						\
			usc_rx_clk_rate.o				\
			usc_rx_clk_src.o				\
			usc_rx_rxc.o					\
			usc_rx_rxc_legacy.o				\
			usc_tx_clk_rate.o				\
			usc_tx_clk_src.o				\
			usc_tx_stop_bits.o				\
			usc_tx_txc.o					\
			usc_tx_txc_legacy.o				\
			usc_txd.o						\
			write.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_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} ...
	@rm -f *.o ${TARGET}
	@-chmod +rw ${DEP_FILE}
	@echo > ${DEP_FILE}

${TARGET}: ${OBJ_FILES}
	@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}
