################################################################################
#
# File:		Makefile
#
# Project:      Roland MPU-401 Device driver for Linux 1.1.64 and higher.
#		MIDI/Sequencer library.
#
# Version:	Device driver:          0.1 alpha  1994-12-01
#		MIDI/Sequencer library: 0.11 alpha 1994-12-04
#
# Authors:	Kim Burgaard, <burgaard@daimi.aau.dk>
#
# Copyrights:	Copyright (c) 1994 Kim Burgaard.
#
#		This program is free software; you can redistribute it and/or
#		modify it under the terms of the GNU General Public License as
#		published by the Free Software Foundation; either version 2, or
#		(at your option) any later version.
#
#		This program is distributed in the hope that it will be useful,
#		but WITHOUT ANY WARRANTY; without even the implied warranty of
#		MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#		GNU General Public License for more details.
#
#		You should have received a copy of the GNU General Public
#		License along with this program; see the file COPYING.  If not,
#		write to the Free Software Foundation, 675 Mass Ave, Cambridge,
#		MA 02139, USA.
#
################################################################################

DEVELOPMENT = FALSE

SHELL   = /bin/sh
CC      = gcc

LIBDIR  = /usr/local/lib
BINDIR  = /usr/local/bin
MODDIR  = /usr/lib/modules

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

ifeq ($(DEVELOPMENT),TRUE)
  CFLAGS  = -I/usr/include -pipe -Wall -fomit-frame-pointer -fstrict-prototypes -O2 -m486 -pedantic
  MPUFLAG = -D__MPU_STATISTICS
else
  CFLAGS  = -I/usr/include -pipe -Wall -fomit-frame-pointer -fstrict-prototypes -O2 -m486
  MPUFLAG = 
endif

LFLAGS  =

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

SRCS    = mpu401.c module.c mpuconfig.c mpuinfo.c gsreset.c\
	  midiqueue.c midiprint.c midifile.c\
	  smfcheck.c smfplay.c

DRIVERS   = mpu401.mod
UTILITIES = mpuconfig mpuinfo gsreset smfcheck smfplay
LIBRARIES = libmidifile.a

OBJS	  = midiqueue.o midiprint.o midifile.o smfplay.o smfcheck.o

WRKDIR    = mpu401-0.11a

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

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

all:		depend $(DRIVERS) $(UTILITIES) $(LIBRARIES)

mpuconfig:
		$(CC) $(CFLAGS) $(LFLAGS) -o $@ $@.c

mpuinfo:
		$(CC) $(CFLAGS) $(LFLAGS) -o $@ $@.c

gsreset:
		$(CC) $(CFLAGS) $(LFLAGS) -o $@ $@.c

mpu401.mod:	$(OBJS)
		$(CC) $(CFLAGS) $(MPUFLAG) -D__KERNEL__ -c -o mpu401.o mpu401.c
		$(CC) $(CFLAGS) -D__KERNEL__ -c -o module.o module.c
		ld -r -o $@ module.o midiqueue.o mpu401.o

smfplay:	$(OBJS) $(LIBRARIES)
		$(CC) $(CFLAGS) $(LFLAGS) -o $@ libmidifile.a $@.o

smfcheck:	$(OBJS) $(LIBRARIES)
		$(CC) $(CFLAGS) $(LFLAGS) -o $@ libmidifile.a $@.o

libmidifile.a:  $(OBJS)
		ld -r -o $@ midi*.o

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

clean:	
		-rm -f $(DRIVERS) $(UTILITIES) $(LIBRARIES)
		-rm -f core *.o *.a *.s .depend kernel-version.h
		-rm -f burgaard/*

install:	all
		install --directory --mode a+rx $(MODDIR)
		install --directory --mode a+rx $(BINDIR)
###		install --directory --mode a+rx $(LIBDIR)
	        if test -e /dev/mpu401data; then rm -f /dev/mpu401data; else true; fi
	        if test -e /dev/mpu401stat; then rm -f /dev/mpu401stat; else true; fi
		mknod --mode a+rw /dev/mpu401data c 14 0; chown root.sys /dev/mpu401data
		mknod --mode a+rw /dev/mpu401stat c 14 1; chown root.sys /dev/mpu401stat
		install --owner root --group sys --mode u+r $(DRIVERS) $(MODDIR)
		install --strip --mode a+rx $(UTILITIES) $(BINDIR)
###		install --mode a+rx $(LIBRARIES) $(LIBDIR)
		@mpuconfig
		@sync
		@-rmmod mpu401
		insmod $(MODDIR)/$(DRIVERS)
		@mpuinfo

uninstall:
		-rm $(MODDIR)/$(DRIVERS)
		-rm $(BINDIR)/$(UTILITIES)
###		-rm $(LIBDIR)/$(LIBRARIES)

dist:		clean
		-rm *~ #*#
		cd .. && tar cf $(WRKDIR).tar $(WRKDIR) && gzip -9 $(WRKDIR).tar

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

kernel-version.h: Makefile
		echo "#define KERNEL_VERSION \"`cat /proc/version |\
		cut -d" " -f3`\"" > kernel-version.h

depend:		dep

dep:		kernel-version.h .depend

.depend:
		$(CC) -M $(SRCS) > .depend

ifeq (.depend,$(wildcard.depend))
include .depend
endif

### End of File #################################################################
