# $URL: http://subversion:8080/svn/gsc/trunk/drivers/LINUX/DIO40/legacy/DIO40_Linux_1.00.0_GSC_DN/utils/makefile $
# $Rev: 34235 $
# $Date: 2016-01-08 17:55:40 -0600 (Fri, 08 Jan 2016) $

DEVICE		= dio40
default: all

CC			= gcc
CC_FLAGS	= -c -Wall
CC_FLAGS	+= -I../docsrc
CC_FLAGS	+= -I../driver
CC_FLAGS	+= -I../lib
DEP_FILE	= makefile.dep
TARGET		= ${DEVICE}_utils.a
VPATH		=

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

OBJ_FILES	=					\
			./util_count.o		\
			./util_id.o			\
			./util_label.o



include ./os_util_makefile.inc



.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: ${GSC_TARGET} ${TARGET}
	@echo ==== All Done

release: ${GSC_TARGET} ${TARGET}
	@rm -f *.o
	@echo ==== release Done

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

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

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

include ${DEP_FILE}
