#
# Copyright (c) 2001 Conexant Systems, Inc.
# 
# 1.   Permitted use. Redistribution and use in source and binary forms,
# with or without modification, are permitted under the terms set forth
# herein.
# 
# 2.   Disclaimer of Warranties. CONEXANT AND OTHER CONTRIBUTORS MAKE NO
# REPRESENTATION ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE.
# IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTIES OF ANY KIND.
# CONEXANT AND OTHER CONTRIBUTORS DISCLAIMS ALL WARRANTIES WITH REGARD TO
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE, GOOD TITLE AND AGAINST INFRINGEMENT.
# 
# This software has not been formally tested, and there is no guarantee that
# it is free of errors including, but not limited to, bugs, defects,
# interrupted operation, or unexpected results. Any use of this software is
# at user's own risk.
# 
# 3.   No Liability.
# 
# (a) Conexant or contributors shall not be responsible for any loss or
# damage to Company, its customers, or any third parties for any reason
# whatsoever, and CONEXANT OR CONTRIBUTORS SHALL NOT BE LIABLE FOR ANY
# ACTUAL, DIRECT, INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL, OR CONSEQUENTIAL
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED, WHETHER IN CONTRACT, STRICT OR OTHER LEGAL THEORY OF
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
# WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
# OF SUCH DAMAGE.
# 
# (b) User agrees to hold Conexant and contributors harmless from any
# liability, loss, cost, damage or expense, including attorney's fees,
# as a result of any claims which may be made by any person, including
# but not limited to User, its agents and employees, its customers, or
# any third parties that arise out of or result from the manufacture,
# delivery, actual or alleged ownership, performance, use, operation
# or possession of the software furnished hereunder, whether such claims
# are based on negligence, breach of contract, absolute liability or any
# other legal theory.
# 
# 4.   Notices. User hereby agrees not to remove, alter or destroy any
# copyright, trademark, credits, other proprietary notices or confidential
# legends placed upon, contained within or associated with the Software,
# and shall include all such unaltered copyright, trademark, credits,
# other proprietary notices or confidential legends on or in every copy of
# the Software.
#
TOP = ..

SUBDIRS= osspec

include common.mak

ALL_MODS= hsfosspec.o hsfbasic2.o hsfich.o hsfvia.o hsfali.o hsfyukon.o hsfengine.o hsfserial.o

# Build hsfscrdmp debug module?
ifeq ($(IMPORTED_SCR_SUPPORT),yes)
ifeq ($(IMPORTED_DMP_SUPPORT),yes)
ALL_MODS+= hsfscrdmp.o
endif
endif

all: $(ALL_MODS)

#mod_basic2.o mod_engine.o mod_ich.o mod_via.o mod_ali.o mod_yukon.o mod_osspec.o mod_scrdmp.o: CFLAGS += -DEXPORT_SYMTAB
# The following is a workaround as the previous line causes certain
# versions of GNU make to crash with the message:
# "make: expand.c:489: allocated_variable_append: Assertion `current_variable_set_list->next != 0' failed."
CFLAGS-mod_osspec = -DEXPORT_SYMTAB
CFLAGS-mod_basic2 = -DEXPORT_SYMTAB
CFLAGS-mod_ich = -DEXPORT_SYMTAB
CFLAGS-mod_via = -DEXPORT_SYMTAB
CFLAGS-mod_ali = -DEXPORT_SYMTAB
CFLAGS-mod_yukon = -DEXPORT_SYMTAB
CFLAGS-mod_engine = -DEXPORT_SYMTAB
CFLAGS-mod_scrdmp = -DEXPORT_SYMTAB

# Remove the following if your OS already has the new serial core
# (expected to be merged one day in linux 2.5)
#serial_hsf.o: CFLAGS += -DCNXTSERIAL_INCLUDE_CORE
# The following is a workaround as the previous line causes certain
# versions of GNU make to crash with the message:
# "make: expand.c:489: allocated_variable_append: Assertion `current_variable_set_list->next != 0' failed."
CFLAGS-serial_hsf = -DCNXTSERIAL_INCLUDE_CORE

serial_hsf.o: serial_core.c serial_core.h

hsfserial.o: serial_hsf.o
	@echo "> linking kernel module $@"
	@$(LD) -r -o $@ $^
	@echo ""

hsfengine.o hsfbasic2.o hsfich.o hsfvia.o hsfali.o hsfyukon.o: hsf%.o: mod_%.o $(IMPORTED)/hsf%.O
	@echo "> linking kernel module $@"
	@$(LD) -r -o $@ $^
	@echo ""

osspec/libosspec.a: $(SUBDIRS)

hsfosspec.o: mod_osspec.o osspec/libosspec.a
	@echo "> linking kernel module $@"
	@$(LD) -r -o $@ $^
	@echo ""

hsfscrdmp.o:: mod_scrdmp.o $(IMPORTED)/hsfdbgscr.O
	@echo "> linking kernel module $@"
	@$(LD) -r -o $@ $^
	@echo ""

HSF_MODS_DIR= $(KMODS_DIR)/misc

.PHONY: check_kernelver modules_install minstall mi
check_kernelver:
	@if [ -z "$(KERNELVER)" ]; then \
		echo 1>&2 "Unable to determine version of kernel source directory $(KERNELSRC)"; false; \
	else \
		true; \
	fi

modules_install minstall mi: check_kernelver all $(HSF_MODS_DIR)
	rm -f "$(HSF_MODS_DIR)/hsf"*.o
	$(INSTALL) -m 644 $(ALL_MODS) $(HSF_MODS_DIR)

.PHONY: link-identical-binaries install uninstall
link-identical-binaries: # to save space
	prevsum=""; md5sum `find binaries -type f -print` </dev/null | sort | while read sum file ; do \
		if [ "$$sum" = "$$prevsum" ] && cmp -s "$$file" "$$prevfile"; then \
			rm -f "$$file"; \
			ln "$$prevfile" "$$file"; \
		else \
			prevsum="$$sum"; \
			prevfile="$$file"; \
		fi; \
	done

install: uninstall $(HSFMODDIR) link-identical-binaries
	(cd $(TOP) && find config.mak imported -depth -print | cpio -pdm $(HSFLIBDIR))
	find . \( -name COPYING -o -name '*.sh' -o -name '*.[ch]' -o -name '*.mak' -o -name '[Mm]akefile' \) -print | cpio -pdm $(HSFMODDIR)
	find binaries -depth -print | cpio -pdm $(HSFMODDIR)

$(HSF_MODS_DIR) $(HSFMODDIR):
	$(MKDIR) -p $@

uninstall:
	rm -rf "$(HSFLIBDIR)/config.mak" "$(HSFLIBDIR)/imported" "$(HSFMODDIR)"

