#								Csound Makefile
# edit the following definitions according to need:

INCLUDE	= /usr/local/include
LIB	= /usr/local/lib
DEST	= /usr/local/bin
MAN	= /usr/local/man
MAN1	= $(MAN)/man1
CAT1	= $(MAN)/cat1

DEFINES = -DWINDOWS -DRTAUDIO -DSFIRCAM -DDEC
# choose any of -
#	-DSYS5	    invoke System 5 headers (e.g. 'string.h' for 'strings.h')
#	-DWINDOWS   include window system calls (X11, SGI or Starbase graphics)
#	-DRTAUDIO   include real-time sound i/o via DEC or other audio-board
# at most one of -
#	-DSFIRCAM   read/write IRCAM-format soundfiles, with 1024-byte header;
#	-DSFSUN41   read/write SUN4.1-format soundfiles, with their own header;
#	-DNeXT      read/write NeXT-format soundfiles, with their own header;
#			(else read/write sound with no headers)
# and at most one of -
#	-DDEC		send rtaudio calls to DEC audio device handler
#	-DSGI		send rtaudio calls to SGI audio device handler
#	-Dsun		send rtaudio calls to sun audio device handler

CFLAGS = -O -f $(DEFINES) -I$(INCLUDE)/csound
#	-O2		to be more specific about the optimization level
#	-f		compile single-precision floats (4.3,VAX,DEC-RISC)
# 	-fsingle	as above, for SUN Unix
# 	-float -ckkr 	as above, for SGI Unix
#	-f68881		employ the 68881 co-processor
#	-ffpa		employ the SUN fl-pt accelerator
#	+x		generate HP inline 68020 and 68881 code
#	+Nd1200		expand SYS5 pass3 tablesize
#	-I/usr/demo/SOUND		to find SUN4.1 audio includes
#	-I/usr/include/sys		to find NeXT malloc.h
#	-I$(INCLUDE)/csound		required (for shared csound includes)

LIBS =	-L$(LIB) -lcsound -lX11 -lm
#	-L$(LIB) -lcsound -lm		required (for shared csound modules)
#	-lX11				for X window calls
#	-lfm_s -lgl_s 			for SGI graphics library
#	-lbsdipc -ldd98710 -lsb1 -lsb2	for HP Starbase Graphics
#	-l881				tell -lm to use 68881
#	-laudio				on SUN, for SFSUN41
#	-laudio				on SGI, to include rt devaudio library
#	-lmidi				on NeXT, to find the midi support

WINOBJ = winX11.o
# ;if WINDOWS enabled in DEFINES, choose one of -
#	winX11.o	for X11 window graphics
#	winSGI.o	for SGI window graphics
#    	win98.o		for Starbase Graphics on HP98700 terminals

AUDOBJ = rtaudio.o DECaudio.o DECplay.o
# ;if RTAUDIO enabled in DEFINES, include
#	rtaudio.o		general interface to audio handlers & libraries
# and at most one set of -
#	DECaudio.o DECplay.o	rt_handlers for DECaudio (with -DDEC)
#	[other things]		device handlers for other hardware

# do not edit below this line
# --------------------------------------------------------------------------

# macros passed to lower-level Makef files
#	CFLAGS INCLUDE LIB DEST
M = "CFLAGS=$(CFLAGS)" "INCLUDE=$(INCLUDE)" "LIB=$(LIB)" "DEST=$(DEST)"

MAKE = make -f Makef $M

SHELL = /bin/sh

OBJS =	main.o musmon.o oload.o rdorch.o express.o rdscor.o linevent.o \
	insert.o entry.o fgens.o aops.o midiops.o midirecv.o \
	ugens1.o ugens2.o ugens3.o ugens4.o ugens5.o ugens6.o ugens7.o \
	ugens8.o spectra.o disprep.o window.o winascii.o $(WINOBJ) \
	sfheaders.o soundin.o soundio.o ulaw.o aiff.o IEEE80.o \
	filopen.o memalloc.o memfiles.o auxfd.o windin.o $(AUDOBJ)

SCOBJ = scot.o

SOBJS = scsort.o scxtract.o sread.o sort.o extract.o twarp.o swrite.o

I	= $(INCLUDE)/csound
CSLIB	= $(LIB)/libcsound.a
PROGS   = csound
SUBDIRS = anals utils1 utils2  #utils3			#utils3 not curr operative

all:		includes $(CSLIB) $(PROGS) $(SUBDIRS)	#must be run in this order

includes:
		-mkdir -p $I
		cd include;	  $(MAKE) includes
		cd util1/cscore;  $(MAKE) includes

LIBSRC	= lib/dsputil.c lib/fft.c lib/pvoc.c lib/sndf.c
LIBHDR	= $I/dsputil.h $I/fft.h $I/pvoc.h $I/sndf.h
cslib $(CSLIB):	$(LIBSRC) $(LIBHDR)
		cd lib;  $(MAKE) $@

csound:		$(OBJS) $(SCOBJ) $(SOBJS) $(CSLIB)
		$(CC) $(CFLAGS) -o csound $(OBJS) $(SCOBJ) $(SOBJS) $(LIBS)

$(OBJS):	$I/sysdep.h $I/prototypes.h cs.h

$(SCOBJ):	scot.h

$(SOBJS):	sort.h

oload.o:	oload.h ugens3.h ugens5.h ugens8.h soundio.h

insert.o:	insert.h aops.h midiops.h

entry.o:	insert.h aops.h midiops.h ugens1.h ugens2.h ugens3.h ugens4.h \
		ugens5.h $I/lpc.h ugens6.h ugens7.h ugens8.h $I/dsputil.h \
		spectra.h window.h windin.h disprep.h soundio.h

aops.o:		aops.h

musmon.o midiops.o midirecv.o:	midiops.h

ugens1.o:	ugens1.h

ugens2.o:	ugens2.h

ugens3.o:	ugens3.h

ugens4.o:	ugens4.h

ugens5.o:	ugens5.h $I/lpc.h

ugens6.o:	ugens6.h

ugens7.o:	ugens7.h

ugens8.o:	ugens8.h soundio.h $I/fft.h $I/dsputil.h $I/pvoc.h

spectra.o:	spectra.h window.h

disprep.o:	disprep.h window.h $I/fft.h $I/dsputil.h

window.o winascii.o winX11.o winSGI.o:	window.h

windin.o:	window.h windin.h

fgens.o:	window.h soundio.h

main.o musmon.o soundin.o soundio.o:  soundio.h

sfheaders.o:	soundio.h $I/sfheader.h

aiff.o: 	soundio.h $I/sfheader.h aiff.h

rtaudio.o:	soundio.h DECplay.h

DECaudio.o DECplay.o:	DECaudio.h

DECplay.o:	DECplay.h

ADSYNS = hetro 						#targets in anal/adsyn
LPCS = lpcanal						#targets in anal/lpc
PVOCS = pvanal 						#targets in anal/pvoc
ANALS = adsyns $(ADSYNS) lpcs $(LPCS) pvocs $(PVOCS)	#targets in anal
anals $(ANALS):
		cd anal; $(MAKE) $@

SCOTS = scots						#targets in util1/scot
CSCORES = cscores					#targets in util1/cscore
SORTEXS = scsort extract				#targets in util1/sortex
UTILS1 = $(SCOTS) $(CSCORES) sortexs $(SORTEXS)		#targets in util1
utils1 $(UTILS1):
		cd util1; $(MAKE) $@

UTILS2 = sndinfo scale					#targets in util2
utils2 $(UTILS2):
		cd util2; $(MAKE) $@

SNDINS = sndin sndout   				#targets in util3/
UNDECS = undec vaxify   				#targets in util3/undecv
UTILS3 = sndins $(SNDINS) rescale undecs $(UNDECS)      #targets in util3
utils3 $(UTILS3):
		cd util3; $(MAKE) $@

install:	$(PROGS)
		-strip $(PROGS)
		-rm $(DEST)/csound
		cp $(PROGS) $(DEST)
		cd anal; $(MAKE) install
		cd util1; $(MAKE) install
		cd util2; $(MAKE) install
	#	cd util3; $(MAKE) install		# currently inoperative

MANPP = csound hetro lpcanal pvanal
manpp:
		-for i in $(MANPP); do rm -f $(CAT1)/$$i.1; done
		-for i in $(MANPP); do cp man/$$i.man $(MAN1)/$$i.1; done

clean:
		-rm $(OBJS) $(SCOBJ) $(SOBJS) $(PROGS) *.s
		cd lib; $(MAKE) clean
		cd anal; $(MAKE) clean
		cd util1; $(MAKE) clean
		cd util2; $(MAKE) clean
		cd util3; $(MAKE) clean
		cd testfiles; rm -f core score.srt score.xtr
		cd tutorfiles; rm -f core score.srt score.xtr
		cd scorefiles; rm -f core score.srt score.xtr
		cd morefiles; rm -f core score.srt score.xtr
		cd midifiles; rm -f core score.srt score.xtr

rmbak:
		-rm *.bak *~
		cd include; $(MAKE) rmbak
		cd lib; $(MAKE) rmbak
		cd anal; $(MAKE) rmbak
		cd util1; $(MAKE) rmbak
		cd util2; $(MAKE) rmbak
		cd util3; $(MAKE) rmbak
		cd man; rm -f *.bak *~
		cd testfiles; rm -f *.bak *~
		cd tutorfiles; rm -f *.bak *~
		cd scorefiles; rm -f *.bak *~ 
		cd morefiles; rm -f *.bak *~ 
		cd midifiles; rm -f *.bak *~ 

SOURCE = /u/bv
EXPORT = /u/bv/export
PUBLIC = /fa/ftp/pub/Csound
CSBETA = /fa/ftp/pub/Csound/csbeta
CSMAC  = /u/bv/csmac
csexport:
		cd $(EXPORT); rm -rf csound;
		cd $(SOURCE); tar cf - csound | (cd $(EXPORT); tar xf -);
		cd $(EXPORT)/csound; make rmbak; make clean;
		cd $(EXPORT); tar cf $(PUBLIC)/csound.tar csound; rm -rf csound;
		cd $(PUBLIC); cp csound.tar tmp; compress tmp; \
			mv tmp.Z csound.tar.Z;

csbeta:
		cd $(EXPORT); rm -rf csound;
		cd $(SOURCE); tar cf - csound | (cd $(EXPORT); tar xf -);
		cd $(EXPORT)/csound; make rmbak; make clean;
		cd $(EXPORT); tar cf $(CSBETA)/csound.tar csound; rm -rf csound;
		cd $(CSBETA); cp csound.tar tmp; compress tmp; \
			mv tmp.Z csound.tar.Z;

	# run the following only after csexport
csmac:
		cd $(CSMAC); rm -rf csound;
		cd $(CSMAC); tar xf $(CSEXPORT)/csound.tar;
		cd $(CSMAC)/csound; rm -rf DEC* HP* man win98.c winSGI.c winX11.c;
		cd $(CSMAC)/csound/analfiles; rm -rf ad* lp* pv*
