# $Id: Makefile,v 2.7 1997/10/25 20:14:16 i2c Exp i2c $

#
# uncomment any of the following:
#   
# --- BIT adapters 
BIT_LP		= "Philips style parallel port adapter"
#BIT_LPC		= "Parallel Port over control port"
#BIT_SER	= "Serial port version"
#BIT_ELV		= "ELV Parallel port adapter"
BIT_VELLE	= "Vellemann parallel port interface"
# 
#PCF_ISA	= "PCF 8584 on ISA bus adapter (`a la Elektor)"
PCF_LP 		= "PCF 8584 on parallel port"
#PCF_ELEK 	= "PCF 8584 on Elektor card"
# ... the other ones remain to be defined ...
#
# 

BITADAPS	= 0
PCFADAPS	= 0

#
# Now we define everything we need for the selected hardware adapters:
#
ifdef BIT_LP
BITADAPS	+= +1
HW_OPTS		+= -DBIT_LP 
BIT_SRCS	+= bit-lp.c
endif

ifdef BIT_ELV
BITADAPS	+= +1
HW_OPTS		+= -DBIT_ELV
BIT_SRCS	+= bit-elv.c
endif

ifdef BIT_VELLE
BITADAPS	+= +1
HW_OPTS		+= -DBIT_VELLE
BIT_SRCS	+= bit-velle.c
endif

ifdef BIT_LPC
BITADAPS	+= +1
HW_OPTS		+= -DBIT_LPC
BIT_SRCS	+= bit-lpc.c
endif


# example:
ifdef BIT_SER
BITADAPS	+= +1
HW_OPTS		+= -DBIT_SER
BIT_SRCS	+= bit-ser.c
endif

ifdef PCF_LP
PCFADAPS	+= +1
HW_OPTS		+= -DPCF_LP
PCF_SRCS	+= pcf-lp.c
endif

ifdef PCF_ISA
PCFADAPS	+= +1
HW_OPTS		+= -DPCF_ISA
PCF_SRCS	+= pcf-isa.c
endif

ifdef PCF_ELEK
PCFADAPS	+= +1
HW_OPTS		+= -DPCF_ELEK
PCF_SRCS	+= pcf-elektor.c
endif

I2C_HOME	= ..

#----------------------------------------------------------------------------
HW_OPTS		+= 	-DBITADAPS=$(shell echo $$[$(BITADAPS)])	\
			-DPCFADAPS=$(shell echo $$[$(PCFADAPS)])
I2C_OPT         = -DVERIFY_HEADERS -DSLOW_STARTER
KERNEL_OPT      = -D__KERNEL__ -DKERNEL -DLINUX -DMODULE 
WARNINGS        = -Wall -Wstrict-prototypes
COMPILE         = -pipe -fomit-frame-pointer -m486 -O2 \
		  -I$(I2C_HOME)/include -I.
DEBUG           =

SRCS  		= i2c-main.c alg-illeg.c
INCLUDES	= i2c-priv.h
OBJS  		= $(SRCS:.c=.o)
HDRS		= i2c-priv.h
MOD   		= i2c

# If there is only one adapter per type, we shall compile the
# algorithm & hw layers at one time, which allows inline functions
# to be used correctly.

ifneq ($(BITADAPS),0)
ifeq ("$(BITADAPS)","0 +1")
	ALGS		+= .bit
#	BIT_SRCS	+= alg-bit.c
	LDOBJS		+= alg-bit.o
else
	SRCS		+= alg-bit.c $(BIT_SRCS)
endif
endif

ifneq ($(PCFADAPS),0)
ifeq ("$(PCFADAPS)","0 +1")
	ALGS		+= .pcf
#	PCF_SRCS	+= alg-pcf.c
	LDOBJS		+= alg-pcf.o
else
	SRCS		+= alg-pcf.c $(PCF_SRCS)
endif
endif

CFLAGS = $(DEBUG) $(WARNINGS) $(COMPILE) $(I2C_OPT) $(KERNEL_OPT) $(HW_OPTS)
SFLAGS = -fverbose-asm $(WARNINGS) $(COMPILE) $(PRT_OPT) $(KERNEL_OPT)


%.s : %.c
	$(CC) -ggdb $(CFLAGS) $(SFLAGS) -S $< -o $@
%.i : %.c
	$(CC) $(CFLAGS) $(SFLAGS) -E $< -o $@


all: .depend $(MOD).o
	@echo "---------------------------------------------------"
	@echo "built i2c driver for $$[$(BITADAPS)] bit- and $$[$(PCFADAPS)] pcf adapters"


$(MOD).o: $(OBJS) $(ALGS) $(SRCS)
	ld -r $(LDOBJS) $(OBJS)  -o $(MOD).o


.bit: $(BIT_SRCS) alg-bit.c
	@echo "------------->$(BITADAPS)< $(BIT_SRCS)"
	$(CC)  $(CFLAGS) $(SFLAGS) -DBIT_SRCS=\"$(BIT_SRCS)\" -c alg-bit.c -o alg-bit.o
	cat /dev/null > .bit

.pcf: $(PCF_SRCS) alg-pcf.c
	@echo "------------->$(PCFADAPS)< $(PCF_SRCS)"
	$(CC) $(CFLAGS) $(SFLAGS) -DPCF_SRCS=\"$(PCF_SRCS)\" -c alg-pcf.c -o alg-pcf.o
	cat /dev/null > .pcf

ifeq ("$(BITADAPS)","0 +1")
alg-bit.i: $(BIT_SRCS)
	@echo "------------->$(BITADAPS)< $(BIT_SRCS)"
	$(CC)  $(CFLAGS) $(SFLAGS) -DBIT_SRCS=\"$(BIT_SRCS)\" -E alg-bit.c -o alg-bit.i
	cat /dev/null > .bit
endif


run: $(MOD).o
	-rmmod $(MOD)
	insmod -v -m ./$(MOD).o 2>i2c.loc |sort|uniq>$(MOD).map


install: $(MOD).o
	cp $(MOD).o $(MODULE_DIR)

clean:
	-rm -f a.out $(OBJS) $(MOD).map $(MOD).loc core
	-rm -f .depend .bit .pcf

tst:
	echo $(AA)

.depend: $(SRCS) $(HDRS)
	gcc $(CFLAGS) $(SRCS) -M >.depend

#
# include dependency files if they exist
#
ifeq ( .depend , $(wildcard .depend) )
include .depend
endif
