#
# Copyright (c) 2001-2002 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= $(HCFTARGET)osspec.o $(HCFTARGET)engine.o $(HCFTARGET)serial.o

all: $(ALL_MODS)

#mod_engine.o mod_osspec.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_engine = -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_$(HCFTARGET).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_hcf = -DCNXTSERIAL_INCLUDE_CORE

serial_hcf.o: serial_core.c serial_core.h

$(HCFTARGET)serial.o: serial_hcf.o
	@echo "> linking kernel module $@"
	@$(LD) -r -o $@ $^
	@echo ""

$(HCFTARGET)engine.o: $(HCFTARGET)%.o: mod_%.o $(IMPORTED)/hcf%-$(IMPORTED_ARCH).O
	@echo "> linking kernel module $@"
	@$(LD) -r -o $@ $^
	@echo ""

osspec/libosspec.a: $(SUBDIRS)

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

HCF_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 $(HCF_MODS_DIR)
	rm -f "$(HCF_MODS_DIR)/$(HCFTARGET)"*.o
	$(INSTALL) -m 644 $(ALL_MODS) $(HCF_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 $(HCFMODDIR) link-identical-binaries
	(cd $(TOP) && find config.mak imported -depth -print | cpio -pdm $(HCFLIBDIR))
	find . \( -name COPYING -o -name '*.sh' -o -name '*.[ch]' -o -name '*.mak' -o -name '[Mm]akefile' \) -print | cpio -pdm $(HCFMODDIR)
	find binaries -depth -print | cpio -pdm $(HCFMODDIR)

$(HCF_MODS_DIR) $(HCFMODDIR):
	$(MKDIR) -p $@

uninstall:
	rm -rf "$(HCFLIBDIR)/config.mak" "$(HCFLIBDIR)/imported" "$(HCFMODDIR)"
