# $URL: http://subversion:8080/svn/gsc/trunk/drivers/LINUX/SIO4%20and%20SIO8/SIO4_Linux_2.x.x_GSC_DN/samples/irq/makefile $
# $Rev: 54311 $
# $Date: 2024-03-19 10:44:57 -0500 (Tue, 19 Mar 2024) $

# SIO4: Sample Application: make file

default:	all

CC			= gcc
CC_FLAGS	= -c -Wall -I../../include -L/usr/lib
DEP_FILE	= makefile.dep
LIB_FILES	= ../../lib/sio4_main.a ../../lib/libsio4_api.so
TARGET		= irq

.NOTPARALLEL: %.o

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

ifeq ("${GSC_APP_COMP_FLAGS}","")
GSC_APP_COMP_FLAGS_MSG=
else
GSC_APP_COMP_FLAGS_MSG="  (added '${GSC_APP_COMP_FLAGS}')"
endif

ifeq ("${GSC_APP_LINK_FLAGS}","")
GSC_APP_LINK_FLAGS_MSG=
else
GSC_APP_LINK_FLAGS_MSG="  (added '${GSC_APP_LINK_FLAGS}')"
endif

OBJ_FILES	:=							\
			main.o						\
			main_dma.o					\
			perform.o					\
										\
			main_gsc.o					\
			main_pci.o					\
										\
			rx_envelope.o				\
			rx_fifo_almost_full.o		\
			rx_fifo_empty.o				\
			rx_fifo_full.o				\
			rx_frame_error.o			\
			rx_parity_error.o			\
			rx_spare.o					\
			sync_detected.o				\
			tx_fifo_almost_empty.o		\
			tx_fifo_empty.o				\
			tx_fifo_full.o				\
										\
			usc_brg0_zero.o				\
			usc_brg1_zero.o				\
			usc.o						\
			usc_cts_down.o				\
			usc_cts_up.o				\
			usc_dcd_down.o				\
			usc_dcd_up.o				\
			usc_dpll_desync.o			\
			usc_rcc_underrun.o			\
			usc_rx_abort_pe.o			\
			usc_rx_bound.o				\
			usc_rx_break_abort.o		\
			usc_rxc_down.o				\
			usc_rxc_up.o				\
			usc_rx_data.o				\
			usc_rx_exited_hunt.o		\
			usc_rx_idle_received.o		\
			usc_rx_overrun.o			\
			usc_rxreq_down.o			\
			usc_rxreq_up.o				\
			usc_tx_abort_sent.o			\
			usc_txc_down.o				\
			usc_tx_crc_sent.o			\
			usc_txc_up.o				\
			usc_tx_data.o				\
			usc_tx_eof_eom_sent.o		\
			usc_tx_idle_sent.o			\
			usc_tx_preamble_sent.o		\
			usc_txreq_down.o			\
			usc_txreq_up.o				\
			usc_tx_underrun.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_APP_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_APP_COMP_FLAGS}

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

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

include ${DEP_FILE}
