# Makefile for the Linux sound card driver
#
# Note 2! The CFLAGS definitions are now inherited from the
# parent makes. (hopefully)
#
#

VERSION		= `head -1 .version`
TARGET_OS	= linux
USRINCDIR	= /usr/include
MODULEDIR	= /lib/modules/misc

FIXEDOBJS	= soundcard.o


OBJS   = audio.o
	 
ifndef TOPDIR
TOPDIR=/usr/src/linux
endif

ifndef HOSTCC
build:
	@echo Compiling modularized sound driver
	@make sound.o
	@echo Sound module compiled.

install:	sound.o
	cp sound.o $(MODULEDIR)
endif

.c.o:
	$(CC) $(CFLAGS) -c $<

ifeq ($(CONFIG_SOUND),y)

all:	local.h sound.a

OBJS += $(FIXEDOBJS)

else
all:
endif

ifndef HOSTCC
#
#	Running outside the kernel build.
#
CC	= gcc
HOSTCC	= gcc
CFLAGS	= -D__KERNEL__ -DMODULE -I/usr/src/linux/include -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -pipe -m486
USE_DEPEND=y
else
include $(TOPDIR)/Rules.make
endif

sound.a: $(OBJS) 
	-rm -f sound.a
	$(AR) rcs sound.a $(OBJS)
	sync

clean:
	rm -f core core.* *.o *.a tmp_make *~ x y z *%
	rm -f configure sound_stub.c objects/*.o

indent:
	for n in *.c;do echo indent $$n;indent $$n;done

local.h: 
	$(MAKE) clean
	$(MAKE) setup-$(TARGET_OS)
	$(MAKE) dep
	@echo

clrconf:
	rm -f local.h .depend synth-ld.h trix_boot.h smw-midi0001.h .defines

dep:
	$(CPP) -M *.c > .depend

setup-linux:
	@echo Compiling Sound Driver v $(VERSION) for Linux

sound.o: local.h $(FIXEDOBJS) sound.a
	-rm -f sound.o
	$(LD) -r -o sound.o $(FIXEDOBJS) sound.a

modules: local.h sound.o
	ln -fs `pwd`/sound.o $(TOPDIR)/modules/sound.o


ifdef USE_DEPEND
#
# include a dependency file if one exists
#
ifeq (.depend,$(wildcard .depend))
include .depend
endif
endif
