#
# Copyright (c) C-Media Electronics Inc.
#
# 
#

MODULE = cmaudio.o

# SYSINCLUDE can be overridden by environment variable or command line argument
# TARGET_KERNEL can be overridden by build system
TARGET_KERNEL ?= $(shell uname -r)
LINUXDIR = $(shell uname -r | awk '{sub(/-.*/,"",$$0); print $$0}')
SYSINCLUDE = /usr/src/linux-2.4/include


# Find kernel sources, if they're installed
ifeq ($(filter build, $(notdir $(wildcard /lib/modules/$(TARGET_KERNEL)/*))), build)
	KERNSRC = /lib/modules/$(TARGET_KERNEL)/build
else
	KERNSRC = /usr/src/linux-$(LINUXDIR)
endif


SYSINCLUDE ?= $(KERNSRC)/include


# Flags for kernel modules
CFLAGS= -D__KERNEL__ $(ARCHDEFS) -I$(SYSINCLUDE) -Wall -Wstrict-prototypes -O -fno-strict-aliasing -mpreferred-stack-boundary=2 -march=i686 -falign-functions=4 -DMODULE

#
# Modversion settings
#  
CFLAGS += $(if $(wildcard $(SYSINCLUDE)/linux/modversions.h), -DMODVERSIONS -include $(SYSINCLUDE)/linux/modversions.h)

TARGET = cmaudio
OBJS = main.o cmi9739.o cmi9738.o sis_7018.o via_82cxxx.o intel_ichx.o ali_5451.o

# 
# 
# 
all:	$(TARGET).o

$(TARGET).o: $(OBJS)
	$(LD) -r $^ -o $@

#	mv cmaudio.o $(MODULE)

# Installation

TARGETDIR = /lib/modules/$(TARGET_KERNEL)/kernel/drivers/sound


# Double install; try first without setting root, then try again with
# so we can build rpm files
install:
	mkdir -p $(INSTROOT)/$(TARGETDIR)
	install -b -m 644 $(MODULE) $(INSTROOT)/$(TARGETDIR)
	-install -b -m 644 -o root $(MODULE) $(INSTROOT)/$(TARGETDIR)
	-/sbin/depmod -a

uninstall:
	rm -f $(TARGETDIR)/$(MODULE)
	/sbin/depmod -a

clean:
	rm -f *.o *~ core
