# $URL: http://subversion:8080/svn/gsc/trunk/drivers/LINUX/SIO4%20and%20SIO8/SIO4_Linux_2.x.x_GSC_DN/utils/makefile $
# $Rev: 56244 $
# $Date: 2025-03-21 13:43:31 -0500 (Fri, 21 Mar 2025) $

# SIO4: Utilities: make file

default: all

CC			= gcc
CC_FLAGS	= -c -Wall -I../include
DEP_FILE	= makefile.dep
TARGET		= ../lib/sio4_utils.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	:=		\
			close.o	\
			init.o	\
			ioctl.o	\
			open.o	\
			read.o	\
			write.o	\
			\
			count.o					\
			id.o					\
			reg.o					\
			reg_sio4.o				\
			reg_sio4a.o				\
			reg_sio4a_sync.o		\
			reg_sio4ahrm.o			\
			reg_sio4ahrm_sync.o		\
			reg_sio4ar.o			\
			reg_sio4ar_sync.o		\
			reg_sio4b.o				\
			reg_sio4b_sync.o		\
			reg_sio4bx.o			\
			reg_sio4bx_sync.o		\
			reg_sio4bx2.o			\
			reg_sio4bx2_sync.o		\
			reg_sio4bxr.o			\
			reg_sio4bxr_fasync.o	\
			reg_sio4bxr_sync.o		\
			reg_sio8bx2.o			\
			reg_sio8bx2_sync.o		\
			reg_sio8bx2v_fasync.o	\
			reg_sio8bxs.o			\
			reg_sio8bxs_sync.o		\
			\
			cbl_mode.o				\
			cbl_pin_status.o		\
			fifo_space_cfg.o		\
			gpio_direction_out.o	\
			gpio_input_latching.o	\
			gpio_input_read.o		\
			gpio_output_write.o		\
			gpio_polarity.o			\
			gpio_sense_edge.o		\
			hdlc_tx_frame_setup.o	\
			hdlc_tx_frame_status.o	\
			initialize.o			\
			irq_gsc_cfg_high.o		\
			irq_gsc_enable.o		\
			irq_usc_enable.o		\
			led_channel.o			\
			led_main.o				\
			loop_back.o				\
			osc_measure.o			\
			osc_program.o			\
			osc_reference.o			\
			query.o					\
			reg_mod.o				\
			reg_read.o				\
			reg_read_raw.o			\
			reg_write.o				\
			rx_fifo_ae.o			\
			rx_fifo_af.o			\
			rx_fifo_fill_level.o	\
			rx_fifo_full_cfg.o		\
			rx_fifo_full_cfg_glb.o	\
			rx_fifo_overrun.o		\
			rx_fifo_reset.o			\
			rx_fifo_status.o		\
			rx_fifo_underrun.o		\
			rx_io_abort.o			\
			rx_io_dma_threshold.o	\
			rx_io_mode.o			\
			rx_io_overrun.o			\
			rx_io_pio_threshold.o	\
			rx_io_timeout.o			\
			rx_io_underrun.o		\
			sync_leg_rxd_cfg.o		\
			sync_leg_txd_cfg.o		\
			sync_mode.o				\
			sync_rx_bit_count.o		\
			sync_rx_bit_order.o		\
			sync_rx_count_error.o	\
			sync_rx_count_reset.o	\
			sync_rx_enable.o		\
			sync_rx_gap_enable.o	\
			sync_rxc_cfg.o			\
			sync_rxc_pol.o			\
			sync_rxd_cfg.o			\
			sync_rxe_cfg.o			\
			sync_rxe_pol.o			\
			sync_tx_bit_order.o		\
			sync_tx_enable.o		\
			sync_tx_gap_size.o		\
			sync_tx_word_size.o		\
			sync_txauxc_cfg.o		\
			sync_txc_cfg.o			\
			sync_txc_idle.o			\
			sync_txc_idle_cfg.o		\
			sync_txc_pol.o			\
			sync_txc_src.o			\
			sync_txd_cfg.o			\
			sync_txd_idle_cfg.o		\
			sync_txe_cfg.o			\
			sync_txe_pol.o			\
			sync_txsp_cfg.o			\
			time_stamp_count.o		\
			time_stamp_enable.o		\
			time_stamp_src.o		\
			time_stamp_val.o		\
			tx_fifo_ae.o			\
			tx_fifo_af.o			\
			tx_fifo_empty_cfg.o		\
			tx_fifo_fill_level.o	\
			tx_fifo_overrun.o		\
			tx_fifo_reset.o			\
			tx_fifo_status.o		\
			tx_io_abort.o			\
			tx_io_dma_threshold.o	\
			tx_io_mode.o			\
			tx_io_overrun.o			\
			tx_io_pio_threshold.o	\
			tx_io_timeout.o			\
			usc_8023_rx_adrs_srch.o	\
			usc_8023_tx_underrun.o	\
			usc_accept_cv.o			\
			usc_acv_rx_ext_w.o		\
			usc_acv_tx_cv_pol.o		\
			usc_acv_tx_ext_w.o		\
			usc_acv_tx_stop_bit.o	\
			usc_async_rx_clk_rate.o	\
			usc_async_tx_clk_rate.o	\
			usc_async_tx_stop_bit.o	\
			usc_brg0_clk_src.o		\
			usc_brg0_enable.o		\
			usc_brg0_mode.o			\
			usc_brg1_clk_src.o		\
			usc_brg1_enable.o		\
			usc_brg1_mode.o			\
			usc_bsc_rx_short.o		\
			usc_bsc_rx_strip.o		\
			usc_bsc_rx_syn0.o		\
			usc_bsc_rx_syn1.o		\
			usc_bsc_tx_preamble.o	\
			usc_bsc_tx_short.o		\
			usc_bsc_tx_syn0.o		\
			usc_bsc_tx_syn1.o		\
			usc_bsc_tx_underrun.o	\
			usc_ctr0_clk_src.o		\
			usc_ctr0_rate.o			\
			usc_ctr1_clk_src.o		\
			usc_ctr1_rate.o			\
			usc_cts_cfg.o			\
			usc_cts_leg.o			\
			usc_dcd_cfg.o			\
			usc_dcd_leg.o			\
			usc_dpll_adj_sync.o		\
			usc_dpll_clk_src.o		\
			usc_dpll_miss_1.o		\
			usc_dpll_miss_2.o		\
			usc_dpll_mode.o			\
			usc_dpll_rate.o			\
			usc_dpll_sync.o			\
			usc_hdlc_rx_adrs_ctrl.o	\
			usc_hdlc_tx_l_chr_len.o	\
			usc_hdlc_tx_preamble.o	\
			usc_hdlc_tx_share_0.o	\
			usc_hdlc_tx_underrun.o	\
			usc_hdlcl_tx_active.o	\
			usc_hdlcl_tx_share_0.o	\
			usc_hdlcl_tx_underrun.o	\
			usc_isoc_tx_stop_bit.o	\
			usc_loop_sending.o		\
			usc_mono_rx_short.o		\
			usc_mono_rx_strip.o		\
			usc_mono_rx_sync.o		\
			usc_mono_tx_crc_under.o	\
			usc_mono_tx_preamble.o	\
			usc_mono_tx_short.o		\
			usc_mono_tx_sync.o		\
			usc_nbip_rx_clk_rate.o	\
			usc_nbip_rx_parity.o	\
			usc_nbip_tx_adrs_bit.o	\
			usc_nbip_tx_clk_rate.o	\
			usc_nbip_tx_parity.o	\
			usc_on_loop.o			\
			usc_oper_mode.o			\
			usc_rcc_fifo_clear.o	\
			usc_rcc_fifo_overrun.o	\
			usc_rcc_fifo_valid.o	\
			usc_reset.o				\
			usc_rx_char_cnt.o		\
			usc_rx_char_cnt_lim.o	\
			usc_rx_char_len.o		\
			usc_rx_clk_src.o		\
			usc_rx_cmd.o			\
			usc_rx_crc_enable.o		\
			usc_rx_crc_preset.o		\
			usc_rx_crc_type.o		\
			usc_rx_data_encode.o	\
			usc_rx_enable.o			\
			usc_rx_mode.o			\
			usc_rx_par_enable.o		\
			usc_rx_par_type.o		\
			usc_rx_queue_abort.o	\
			usc_rx_status.o			\
			usc_rx_status_block.o	\
			usc_rx_wait_dma_trig.o	\
			usc_rxc_cfg.o			\
			usc_rxc_leg.o			\
			usc_send_command.o		\
			usc_smono_rx_sync.o		\
			usc_smono_tx_active.o	\
			usc_smono_tx_short.o	\
			usc_smono_tx_sync.o		\
			usc_smono_tx_underrun.o	\
			usc_tbsc_rx_encoding.o	\
			usc_tbsc_tx_encoding.o	\
			usc_tbsc_tx_preamble.o	\
			usc_tbsc_tx_underrun.o	\
			usc_tc0.o				\
			usc_tc1.o				\
			usc_tx_char_cnt.o		\
			usc_tx_char_cnt_lim.o	\
			usc_tx_char_len.o		\
			usc_tx_clk_src.o		\
			usc_tx_cmd.o			\
			usc_tx_crc_enable.o		\
			usc_tx_crc_on_end.o		\
			usc_tx_crc_preset.o		\
			usc_tx_crc_type.o		\
			usc_tx_ctrl_block.o		\
			usc_tx_data_encode.o	\
			usc_tx_enable.o			\
			usc_tx_idle_cond.o		\
			usc_tx_mode.o			\
			usc_tx_par_enable.o		\
			usc_tx_par_type.o		\
			usc_tx_preamble_flag.o	\
			usc_tx_preamble_len.o	\
			usc_tx_preamble_pat.o	\
			usc_tx_status.o			\
			usc_tx_wait_dma_trig.o	\
			usc_tx_wait_underrun.o	\
			usc_txc_cfg.o			\
			usc_txc_leg.o			\
			usc_txd_cfg.o			\
			wait_cancel.o			\
			wait_event.o			\
			wait_status.o			\
			xcvr_enable.o			\
			xcvr_protocol.o			\
			xcvr_term.o				\
			z16_cbl_dcd_cfg.o		\
			z16_cbl_dtr_dsr_cfg.o	\
			z16_cbl_rts_cfg.o		\
			z16_cbl_txauxc_cfg.o	\
			z16_cbl_txc_cfg.o		\
			z16_cbl_txd_cfg.o		\
			z16_leg_rxc.o			\
			z16_leg_rxd_dcd_cfg.o	\
			z16_leg_txc.o			\
			z16_leg_txd_cts_cfg.o	\
			z16_rx_sts_wrd_enable.o	\
			z16_sync_byte.o

include ./gsc_util_makefile.inc
include ./gsc_util_makefile_pci.inc
include ./os_util_makefile.inc

# 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} ${GSC_TARGET} ${PLX_TARGET} ${OS_TARGET} ...
	@rm -f *.a *.o ${TARGET} ${GSC_TARGET} ${PLX_TARGET} ${OS_TARGET}
	@-chmod +rw ${DEP_FILE}
	@echo > ${DEP_FILE}

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