#/********************************************************************
#*	THE USE BY YOU OF THIS SOFTWARE IS GOVERNED IN ALL
#*	RESPECTS BY THE MADGE NETWORKS LTD OPEN SOURCE LICENSE.		
#*	WE ADVISE YOU TO READ THE TERMS OF THE OPEN SOURCE LICENSE
#*	WHICH CAN BE FOUND WITHIN THE LICENSE.TXT FILE WHICH IS PART OF
#*	THE SOFTWARE OR BY VISITING THE URL
#*	http://www.madge.com/Connect/Downloads/Software/.		
#*	MADGE NETWORKS LTD RESERVES THE RIGHT TO SEEK REDRESS FOR
#*	ANY VIOLATION OF THE LICENSE'S TERMS					
#*********************************************************************/

##############################################################################
#
# Makefile
#
# Makefile for Madge Networks Linux Driver
#
#  $Id: $
#    
##############################################################################

#
# First thing include the driver options file if it exists
# or make it if it doesn't exist.
#

ifeq (.configured,$(wildcard .configured))
include .config.mk
do-it-all:      all
else
do-it-all:      config
endif

#
# Build as a module?
#

MODULE=y

# Madge Product Identification Strings
#
OPTFLAGS+=-DMVER_STRINGS

#
# Used for compiling auxillary programs
#

HOSTCFLAGS=-I. -Iudt $(OPTFLAGS)
HOSTCC=gcc

#################################################################################

#
# Do not edit any of these options
#

# 
# Should we use Madge's proprietary priority mechanism
#

# OPTFLAGS+=-DUDT_TRANSMIT_PRIORITY_SUPPORT 

#################################################################################

#
# Compilation flags.
#

ifeq ($(DEBUG),y)
DBGFLAGS=-DDEBUG
else
DBGFLAGS=
endif

CFLAGS=$(DBGFLAGS) $(OPTFLAGS) -O2 -DMODULE -D__KERNEL__

ifeq ($(ARCH),intel)
CFLAGS+=-Wstrict-prototypes -Wall -fomit-frame-pointer
LD=ld
LDFLAGS=
else
ifeq ($(ARCH),sparc64)

IS_EGCS=y

LD=ld
LDFLAGS=-m elf64_sparc

#
# Setup variables for Sparc 64 Architecture
#

ifneq ($(IS_EGCS),y)
  CFLAGS += -pipe -mno-fpu -mtune=ultrasparc -mmedlow \
	    -ffixed-g4 -fcall-used-g5 -fcall-used-g7 -Wno-sign-compare
  CC = sparc64-linux-gcc
  HOSTCC = $(CC)
else
  CFLAGS += -m64 -pipe -mno-fpu -mcpu=ultrasparc -mcmodel=medlow \
	    -ffixed-g4 -fcall-used-g5 -fcall-used-g7 -Wno-sign-compare
  AFLAGS += -m64 -mcpu=ultrasparc
  CC = sparc64-redhat-linux-egcs
  HOSTCC = $(CC)
endif

else
endif
endif

ifeq ($(PCMCIA_HELPER),y)
CFLAGS+=-I$(PCMCIA)/include
endif

#
# Universal driver toolkit objects.
#

UDT_INIT_OBJS=	piotest.o		\
             	knossosi.o		\
             	decomp.o

DL_OBJS=       	knoscode.o 		\
             	fmplus.o

UDT_OBJS=    	at24.o 			\
		config.o 		\
             	hc46.o 			\
             	pio.o 			\
             	knossosr.o 		\
	 	knos2r.o		\
	     	knos3r.o		\
             	udmi.o 			\
             	util.o

DRIVER_OBJS=	madgetr.o

SCRIPTS=scripts


VPATH=udt
INCS=-I. -Iudt -I- -Iinclude -I$(LINUX)/include


config:
	@$(SCRIPTS)/configure
	@cd include/linux ; ln -sf ../mtok/config.h config.h ; ln -sf ../mtok/config.h version.h ; cd ../..
	@echo Cleaning old files...
	@make clean > /dev/null

#
# If we are not embedding micro code into the driver we must look
# in the microcode directory for files as well.
#
ifndef EMBEDDED_MICRO_CODE
VPATH+=microcode
INCS+=-Imicrocode
endif

#
# If there is no source code for the UDT we must use the binary
# library.
#
UDT_LIB=udt.lib
UDT_LIB_OBJS=$(UDT_OBJS) $(UDT_INIT_OBJS) $(DL_OBJS)


ALL_OBJS=$(DRIVER_OBJS) $(UDT_OBJS) $(UDT_INIT_OBJS)
#ifeq ($(EMBEDDED_MICRO_CODE),y)
ALL_OBJS+=$(DL_OBJS)
#endif

TARGETS=driver

#ifndef EMBEDDED_MICRO_CODE
#TARGETS += images
#endif

ifeq ($(PCMCIA_HELPER),y)
TARGETS += pcmcia
CFLAGS += -DPCMCIA_SET
endif

ifeq ($(DEBUG),y)
TARGETS += debug
endif

all: $(TARGETS)

driver: $(ALL_OBJS)
	@echo Linking mtok.o
	$(LD) $(LDFLAGS) -r $(ALL_OBJS) -o mtok.o
	@echo Setting checksum
	@./utils/mver mtok.o -s

#	strip --strip-unneeded mtok.o

utils: dummy
	$(MAKE) -C utils

madgeconfig: dummy
	$(MAKE) -C install

dummy:

pcmcia: mtok_cb.o mtok_cs.o
	@./utils/mver mtok_cs.o -s
	@./utils/mver mtok_cb.o -s


debug: mpoke.o

#
# This rule is for Madge to build the binary library from source.
# Do not attempt to build the UDT library without the source code.
# Uncomment this rule to rebuild the library
# $(UDT_LIB): $(UDT_LIB_OBJS)
#	ld -r -o $(UDT_LIB) $(UDT_LIB_OBJS)


mtok_cs.o: madgecs.o
	@echo Linking mtok_cs.o
	@ld -r -o mtok_cs.o madgecs.o 

mtok_cb.o: madgecb.o
	@echo Linking mtok_cb.o
	@ld -r -o mtok_cb.o madgecb.o 	

install: all
	@echo Installing in $(MODDIR)
	@mkdir -p $(MODDIR)/net
	@cp mtok.o $(MODDIR)/net
ifndef EMBEDDED_MICRO_CODE
	@$(shell if [ -f knosbin.bin ] ; then cp knosbin.bin $(MODDIR)/net ; fi)
	@$(shell if [ -f fmpbin.bin ] ; then cp fmpbin.bin $(MODDIR)/net ; fi)
endif
ifdef PCMCIA_MK
	@mkdir -p $(MODDIR)/pcmcia
	@cp mtok_cs.o $(MODDIR)/pcmcia
	@cp mtok_cb.o $(MODDIR)/pcmcia
endif
#	@echo Installing utilities in $(UTIL_DIR)
#	@install -d -g root -o root -m 755 $(UTIL_DIR)
#	@install -g root -o root -m 755 utils/trconfig $(UTIL_DIR)
#	@install -g root -o root -m 755 utils/mver $(UTIL_DIR)	
#	@install -g root -o root -m 755 utils/llcping $(UTIL_DIR)	

#
# General rule for C files.
#
.c.o:
	@echo Compiling $(CC) $(INCS) $(CFLAGS) $<
	@$(CC) $(INCS) $(CFLAGS) -c $< -o $@

#
# Make the download image binary files
#
images: 
	$(MAKE) -C microcode
	./microcode/mdgbin

patch:
	@scripts/patch-kernel

clean:
	rm -f $(shell find . | grep \~$ | xargs)
	rm -f core a.out *.o *.bin mdgbin tmp DEADJOE *.bak
	$(MAKE) -C utils clean
	$(MAKE) -C install clean
	$(MAKE) -C microcode clean

# Madge Internal Use.
# Run this rule when youve copied a new UDT into the distribution
# to convert line endings filenames and file permissions.
#
udt2unix:
	@scripts/2unix udt/*

distclean: clean
	rm -f .config.mk .config.sh  .configured .config.tmp.sh ksyms.tmp include/mtok/config.h



#### End of makefile ########################################################
