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

# SIO4: Fast Async Protocol Library: API Library: make file

default: all

CC			= gcc
CC_FLAGS	= -c -Wall -I../../include
DEP_FILE	= makefile.dep
TARGET		= ../../lib/sio4_fasync.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	:=						\
			access.o				\
			apply.o					\
			bitrate.o				\
			board_leds.o			\
			cable_enable.o			\
			cable_gpio_a.o			\
			cable_gpio_b.o			\
			cable_gpio_c.o			\
			cable_gpio_d.o			\
			cable_loopback.o		\
			cable_mode.o			\
			cable_protocol.o		\
			cable_term.o			\
			chan_leds.o				\
			close.o					\
			error.o					\
			fw_type.o				\
			get.o					\
			gpio_rx.o				\
			gpio_tx.o				\
			init_api.o				\
			init_data.o				\
			ioctl.o					\
			irq_direction.o			\
			irq_enable.o			\
			open.o					\
			osc_program.o			\
			parity_enable.o			\
			parity_type.o			\
			read.o					\
			reset.o					\
			rx_enable.o				\
			rx_frame_err_cfg.o		\
			rx_fifo_ae.o			\
			rx_fifo_af.o			\
			rx_fifo_bytes.o			\
			rx_fifo_full_cfg.o		\
			rx_fifo_overflow.o		\
			rx_fifo_reset.o			\
			rx_fifo_size.o			\
			rx_fifo_status.o		\
			rx_fifo_underflow.o		\
			rx_io_abort.o			\
			rx_io_dma_threshold.o	\
			rx_io_mode.o			\
			rx_io_overflow.o		\
			rx_io_pio_threshold.o	\
			rx_io_timeout.o			\
			rx_io_underflow.o		\
			rx_parity_err_cfg.o		\
			rx_rts.o				\
			rx_sb2_err_cfg.o		\
			rx_status.o				\
			set.o					\
			show.o					\
			show_util.o				\
			stop_bits.o				\
			tx_cts.o				\
			tx_data.o				\
			tx_enable.o				\
			tx_fifo_ae.o			\
			tx_fifo_af.o			\
			tx_fifo_bytes.o			\
			tx_fifo_empty_cfg.o		\
			tx_fifo_overflow.o		\
			tx_fifo_reset.o			\
			tx_fifo_size.o			\
			tx_fifo_status.o		\
			tx_gap.o				\
			tx_io_abort.o			\
			tx_io_dma_threshold.o	\
			tx_io_mode.o			\
			tx_io_overflow.o		\
			tx_io_pio_threshold.o	\
			tx_io_timeout.o			\
			tx_status.o				\
			verify.o				\
			verify_util.o			\
			wait_cancel.o			\
			wait_event.o			\
			wait_status.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}
