#								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
# these directories must exist for stages beyond 'make csound'

CDEP =	
COBS =	$(COBJS)
CC = cc
DDEP =	
DOBS =	$(DOBJS)
CC = cc
# choose either -
#	CDEP =			for UNIX
#	COBS = $(COBJS)
#	CC = cc
# or -
#	CDEP = $(CRFILE)	for MSDOS
#	COBS = @$(CDEP)
#	CC = gcc
#	.c.o:
#		$(CC) $(CFLAGS) -c $*.c -o $@

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 FG graphics)
#	-DRTAUDIO   include real-time sound i/o via DEC or other audio-board
#	-DDOSGCC    for PC, if above defined CC = gcc compiler under MSDOS
#	-DHPUX -D_HPUX_SOURCE	for HP compilation under HP Unix
# 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
#	-DHP		send rtaudio calls to HP  audio device handler

CFLAGS = -O -f $(DEFINES)
#	-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 -cckr 	as above, for SGI Unix
#	-f68881		employ the 68881 co-processor
#	-ffpa		employ the SUN fl-pt accelerator
#	-f -DWITHx87	for PC with 80x87 floating-point coprocessor
#	-w -D__STDC__	for PC 
#	-Aa		for HP to invoke ANSI C compiler
#	+e		for HPUX rtaudio compilation
#	+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/X11R4		to find HP X11 includes, v.4
#	-I/usr/include/sys		to find NeXT malloc.h

LIBS =	-lX11 -lm
#	-lm		    		required
#	-lX11				for X window calls
#	-L/usr/lib/X11R4		for HP X11 library, v.4
#	-L$(newlib)			for other special access
#	-lfm_s -lgl_s 			for SGI graphics library
#	fgp.lib				for PC FlashGraphics lib
#	-l881				tell -lm to use 68881
#	-laudio				on SUN, for SFSUN41
#	-laudio				on SGI, to include rt devaudio library
#	-lAlib				on HP, 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
#	winfg.o 	for PC  Flash Graphics

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)
#	SGIplay.o		rt_handler  for SGIaudio (with -DSGI)
#	HPplay.o		rt_handler  for HP audio (with -DHP)
#				blank for SUN audio lib  (with -Dsun)
#	[other things]		device handlers for other hardware

AUDHDR = DECplay.h
# ;if RTAUDIO enabled include
#	DECplay.h		for rtaudio and DECplay (with -DDEC)
# ;else leave blank


# The Csound MAKE can be run in separate stages, or as a single command.
# To create just the 'csound' executable, type
#	make csound
# This module contains most of the functions below as Utility options
# (see the Csound manual), but they are also available as standalones:

# To create the standalone 'hetro', 'lpanal', 'pvanal', type
#	make hetro
#	make lpanal
#	make pvanal
# To create all three standalones, type
#	make anals

# To create standalone 'scot', 'cscore', 'scsort', 'extract', type
#	make scots
#	make cscores
#	make scsort
#	make extract
# To create all four standalones, type
#	make utils1

# To create standalone 'sndinfo', type
#	make sndinfo
# or
#	make utils2

# To create all the above, from 'csound' to 'utils2', type
#	make all

# If you have completed the above, and have defined the INCLUDE, LIB & DEST
# directories, you can now install all the executables in a single command:
#	make install

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

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

MAKE = make -f makef $(MAC)

SHELL = /bin/sh

CSCM  = cscormai.o

COBS1 =	main.o musmon.o otran.o oload.o rdorch.o express.o rdscor.o linevent.o
COBS2 =	cscore.o cscorfns.o insert.o entry.o aops.o midiops.o midirecv.o
COBS3 =	fgens.o ugens1.o ugens2.o ugens3.o ugens4.o ugens5.o ugens6.o
COBS4 =	ugens7.o ugens8.o spectra.o disprep.o window.o winascii.o $(WINOBJ)
COBS5 =	hetro.o lpanal.o lptrkfns.o pvanal.o pvoc.o fft.o dsputil.o
COBS6 =	sndinfo.o sfheader.o soundin.o soundio.o ulaw.o aiff.o wave.o ieee80.o
COBS7 =	filopen.o memalloc.o memfiles.o auxfd.o windin.o dumpf.o $(AUDOBJ)
COBS8 = scot.o scsort.o scxtract.o sread.o sort.o extract.o twarp.o swrite.o
COBJS =	$(COBS1) $(COBS2) $(COBS3) $(COBS4) $(COBS5) $(COBS6) $(COBS7) $(COBS8)

DOBS1 =	dmain.o musmon.o oload.o rdscor.o linevent.o
DOBS2 =	insert.o entry.o aops.o midiops.o midirecv.o
DOBS3 =	fgens.o ugens1.o ugens2.o ugens3.o ugens4.o ugens5.o ugens6.o
DOBS4 =	ugens7.o ugens8.o spectra.o disprep.o window.o winascii.o $(WINOBJ)
DOBS5 =	pvoc.o fft.o dsputil.o
DOBS6 =	sndinfo.o sfheader.o soundin.o soundio.o ulaw.o aiff.o wave.o ieee80.o
DOBS7 =	filopen.o memalloc.o memfiles.o auxfd.o windin.o dumpf.o $(AUDOBJ)
DOBJS = $(DOBS1) $(DOBS2) $(DOBS3) $(DOBS4) $(DOBS5) $(DOBS6) $(DOBS7)

CRFILE = makec.res
$(CRFILE):	makefile
		echo $(COBS1) > $(CRFILE)
		echo $(COBS2) >> $(CRFILE)
		echo $(COBS3) >> $(CRFILE)
		echo $(COBS4) >> $(CRFILE)
		echo $(COBS5) >> $(CRFILE)
		echo $(COBS6) >> $(CRFILE)
		echo $(COBS7) >> $(CRFILE)
		echo $(COBS8) >> $(CRFILE)

DRFILE = maked.res
$(DRFILE):	makefile
		echo $(DOBS1) > $(DRFILE)
		echo $(DOBS2) >> $(DRFILE)
		echo $(DOBS3) >> $(DRFILE)
		echo $(DOBS4) >> $(DRFILE)
		echo $(DOBS5) >> $(DRFILE)
		echo $(DOBS6) >> $(DRFILE)
		echo $(DOBS7) >> $(DRFILE)

PROGS   = csound
CSA     = csound.a
SUBDIRS = anals utils1 utils2

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

csound:		$(COBJS) $(CSCM) $(CDEP)
		$(CC) $(CFLAGS) -o csound $(COBS) $(LIBS)

csound.a:	$(COBJS) $(CDEP)
		-rm csound.a
		ar q csound.a $(COBS)
		-ranlib csound.a

dsound:		$(DOBJS) $(DDEP)
		$(CC) $(CFLAGS) -o dsound $(DOBS) $(LIBS)

X	=	sysdep.h prototyp.h cs.h
A	=	aops.h
C	=	cscore.h
D	=	disprep.h
F	=	fft.h
H	=	sfheader.h
I	=	insert.h
J	=	oload.h
L	=	lpc.h
M	=	midiops.h
N	=	soundin.h
O	=	soundio.h
P	=	pvoc.h
S	=	spectra.h
U	=	dsputil.h
W	=	window.h

1	=	ugens1.h
2	=	ugens2.h
3	=	ugens3.h
4	=	ugens4.h
5	=	ugens5.h
6	=	ugens6.h
7	=	ugens7.h
8	=	ugens8.h

scot.o:		scot.h

sread.o twarp.o: $X sort.h

scsort.o scxtract.o sort.o extract.o swrite.o:	sort.h

main.o:		$X $O

dmain.o:	$X

musmon.o:	$X $C $M $O

otran.o oload.o: $X $J

rdorch.o express.o rdscor.o linevent.o:	$X

cscore.o cscormai.o cscorfns.o:	$X $C

insert.o:	$X $I $A $M

entry.o:	$X $I $A $M $1 $2 $3 $4 $5 $6 $7 $8 $L $U $S $W windin.h $D $O

aops.o:		$X $A

midiops.o midirecv.o:	$X $M

fgens.o:	$X $W $O

ugens1.o:	$X $1

ugens2.o:	$X $2

ugens3.o:	$X $3

ugens4.o:	$X $4

ugens5.o:	$X $5 $L

ugens6.o:	$X $6

ugens7.o:	$X $7

ugens8.o:	$X $8 $O $F $U $P

spectra.o:	$X $S $W

disprep.o:	$X $D $W $F $U

window.o winascii.o $(WINOBJ):	$X $W

soundin.o soundio.o hetro.o sndinfo.o:  $X $O

lpanal.o:	$X $O $L

lptrkfns.o:	$X $L

pvanal.o:	$X $O $F $P $U

pvoc.o: 	$X $P

fft.o:  	$X $F

dsputil.o:  	$X $U dpwelib.h

sfheader.o:	$X $O $H

aiff.o: 	$X $O $H aiff.h

wave.o:		$X $O $H wave.h

filopen.o memalloc.o memfiles.o auxfd.o:  $X

windin.o:	$X $W windin.h

dumpf.o:	$X dumpf.h

rtaudio.o:	$X $O $(AUDHDR)

DECaudio.o:	DECaudio.h

DECplay.o:	DECaudio.h DECplay.h

ADSYNS = hetro 						#targets in anal/adsyn
LPCS = lpanal						#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 = sndinfos					#targets in util2
utils2 $(UTILS2):
		cd util2; $(MAKE) $@

install:	$(PROGS) $(CSA)
		-strip $(PROGS)
		-rm $(DEST)/csound
		cp $(PROGS) $(DEST)
		-rm $(LIB)/libcsound.a
		cp csound.a $(LIB)/libcsound.a
		cd anal; $(MAKE) install
		cd util1; $(MAKE) install
		cd util2; $(MAKE) install

MANPP = csound hetro lpanal 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 $(COBS) cscormai.o dmain.o $(PROGS) $(CSA) dsound *.s
		cd anal; $(MAKE) clean
		cd util1; $(MAKE) clean
		cd util2; $(MAKE) clean
		cd testfils; rm -f core score.srt score.xtr
		cd tutofils; rm -f core score.srt score.xtr
		cd scorfils; rm -f core score.srt score.xtr
		cd morefils; rm -f core score.srt score.xtr
		cd midifils; rm -f core score.srt score.xtr
		cd analfils; rm -f core pv.medlab
		cd cscofils; rm -f core cscore csound *.o *.out *.srt

rmbak:
		-rm *.bak *~
		cd anal; $(MAKE) rmbak
		cd util1; $(MAKE) rmbak
		cd util2; $(MAKE) rmbak
		cd man; rm -f *.bak *~
		cd testfils; rm -f *.bak *~
		cd tutofils; rm -f *.bak *~
		cd scorfils; rm -f *.bak *~ 
		cd morefils; rm -f *.bak *~ 
		cd midifils; rm -f *.bak *~ 
		cd cscofils; rm -f *.bak *~ 

SRC = /ti/u/bv
TMP = /ti/u/bv/tmp

PUBLIC = /fa/ftp/pub/Csound
CSBETA = /fa/ftp/pub/Csound/csbeta
CSPC  = /ti/u/bv/cspc
CSPCBETA  = /ti/u/bv/cspcbeta
CSMAC  = /ti/u/bv/csmac
CSMBETA  = /ti/u/bv/csmbeta

cspublic:
		cd $(TMP); rm -rf csound;
		cd $(SRC); tar cf - csound | (cd $(TMP); tar xf -);
		cd $(TMP)/csound; make rmbak; make clean;
		cd $(TMP); 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 $(TMP); rm -rf csound;
		cd $(SRC); tar cf - csound | (cd $(TMP); tar xf -);
		cd $(TMP)/csound; make rmbak; make clean;
		cd $(TMP); 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 cspublic
cspc:
		cd $(CSPC); rm -rf csound;
		cd $(CSPC); tar xf $(PUBLIC)/csound.tar;
		cd $(CSPC)/csound; rm -rf DEC* HP* SGI* *SGI* *X11* \
			THINKC man rtaudio.c winfg.c
		cd $(CSPC)/csound/analfils; rm -rf ad* lp* pv*

	# run the following only after csbeta
cspcbeta:
		cd $(CSPCBETA); rm -rf csound;
		cd $(CSPCBETA); tar xf $(CSBETA)/csound.tar;
		cd $(CSPCBETA)/csound; rm -rf DEC* HP* SGI* *SGI* *X11* \
			THINKC man rtaudio.c winfg.c
		cd $(CSPCBETA)/csound/analfils; rm -rf ad* lp* pv*

	# run the following only after cspublic
csmac:
		cd $(CSMAC); rm -rf csound;
		cd $(CSMAC); tar xf $(PUBLIC)/csound.tar;
		cd $(CSMAC)/csound; rm -rf DEC* HP* SGI* *SGI* *X11* \
			man cscormai.c dmain.c rtaudio.c winfg.c
		cd $(CSMAC)/csound/analfils; rm -rf ad* lp* pv*

	# run the following only after csbeta
csmbeta:
		cd $(CSMBETA); rm -rf csound;
		cd $(CSMBETA); tar xf $(CSBETA)/csound.tar;
		cd $(CSMBETA)/csound; rm -rf DEC* HP* SGI* *SGI* *X11* \
			man cscormai.c dmain.c rtaudio.c winfg.c
		cd $(CSMBETA)/csound/analfils; rm -rf ad* lp* pv*

