#								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
# 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 -DSYS5 -DLINUX -DPIPES -DMACROS -DTCLTK -DIV_SCHED -DRWD_DBFS
# 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
#	-DPIPES     if system supports popen and pclose calls
# 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
#	-Dsol		send rtaudio calls to solaris audio handler
#	-DHP		send rtaudio calls to HP  audio device handler
#	-DLINUX		send rtaudio calls to Linux audio device handler
# Defining LINUX also enables an additional command-line option (-V <volume>)
# and includes an extra header in 'midirecv.c'.
# If LINUX is defined, but the target is Linux on a big-endian architecture
# (e.g., Linux on SPARC [not tested]), you should also define -
#       -DLINUX_BE      Linux audio device handler for big-endian samples

CFLAGS = -O2 -malign-loops=4 -malign-jumps=4 -ffast-math -fomit-frame-pointer -finline-functions -funroll-loops -DWITHx87 $(RPM_OPT_FLAGS) $(DEFINES)
#	-O		Simple optimisation
#	-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
#	-DWITHx87	for fpt chip on LINUX
#	-march=i586 -mcpu=i686	Recommended for GNU/Linux is PentiumIII/Athlon.#
#			Still not clear for which processor this works
#	-malign-loops=4	Recommended for GNU/Linux
#	-malign-jumps=4	Recommended for GNU/Linux
#       -malign-functions=4
#       -fno-gcse -fno-strict-aliasing    (recommended bug-arounds for gcc 2.9x)
#       -mfancy-math-387                  (may not be necessary, but safe to add)
#       -ffast-math                       produces faster and smaller code, not
#						 fully tested:
#   these produce larger code, but may (or may not) be faster:
#     -fomit-frame-pointer
#     -finline-functions                  (N.B. do not use this with gcc 2.95.2)
#     -funroll-loops                      (unfortunately this option generates
#                                           much larger executables)
#	-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
#	-I/usr/openwin/include		Solaris openwin interface
#	-I/usr/demo/SOUND/include	Solaris sound interface
#       -I/usr/X11R6/include            non-RedHat distributions of Linux
LIBS =	-L /usr/X11R6/lib -lX11 -ltcl -ltk -lm 
#	-lefence
#	-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
#	-lbsd				on old LINUX
#	-L/usr/demo/SOUND/lib		on Solaris 2.4
#	-L/usr/X11R6/lib		on LINUX
# note: SuSE 7.3 users should use -ltcl8.3 -ltk8.3, but another
# (probably better) solution is to create symbolic links

WINSRC = winX11.c
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


AUDSRC = rtlinux.c LINUXaudio.c
AUDOBJ = rtlinux.o LINUXaudio.o
# ;if RTAUDIO enabled in DEFINES, include one of
#	rtaudio.o		general interface to audio handlers & libraries
#	rtDEC.c		rtSGI.c		rtHP.c		rtSUN.c
#	rtmacintosh.c	rtnext.c	rtlinux.c	rtwin32.c
# and at most one set of -
#	rtDEC.c DECaudio.o DECplay.o	rt_handlers for DECaudio (with -DDEC)
#	rtSGI.c SGIplay.o		rt_handler  for SGIaudio (with -DSGI)
#	rtHP.c HPplay.o		rt_handler  for HP audio (with -DHP)
#	rtSUN.c			for SUN audio lib  (with -Dsun)
#       rtlinux.c LINUXaudio.o  set Linux soundcard parameters (with -DLINUX)
#	rtmacintosh.c		macintosh
#	rtnext.c		NeXT
#	rtwin32.c		Windows 32bit MM library
#	[other things]		device handlers for other hardware

AUDHDR =
# ;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)" "LIBS=$(LIBS)"

MAKE = make -f makef $(MAC)

SHELL = /bin/sh

CSCMS  = cscormai.c natbem.c
CSRC1 =	main.c argdecode.c musmon.c otran.c oload.c rdorch.c express.c
CSRC2 = rdscor.c linevent.c cscore.c cscorfns.c insert.c entry1.c entry2.c aops.c
CSRC3 = midiops.c midirecv.c fgens.c ugens1.c ugens2.c ugens3.c ugens4.c
CSRC4 =	ugens5.c ugens6.c ugens7.c ugens8.c ugens9.c spectra.c disprep.c
CSRC5 =	window.c winascii.c $(WINSRC) hetro.c lpanal.c lptrkfns.c pvanal.c
CSRC6 =	pvoc.c fft.c dsputil.c sndinfo.c sfheader.c soundin.c soundio.c
CSRC7 = ulaw.c aiff.c wave.c ieee80.c filopen.c memalloc.c memfiles.c auxfd.c
CSRC8 = windin.c dumpf.c $(AUDSRC) scot.c scsort.c scxtract.c sread.c sort.c
CSRC9 = extract.c twarp.c swrite.c butter.c grain.c vdelay.c cmath.c follow.c
CSRCA = cvanal.c grain4.c pvinterp.c pvread.c sndwarp.c vpvoc.c hrtferX.c
CSRCB = winEPS.c nlfilt.c opcode.c ugrw1.c ugrw2.c ugensa.c cross2.c dam.c
CSRCC = midiout.c midiops2.c midisend.c wavegde.c filter.c complex.c repluck.c
CSRCD = pluck.c physutil.c physmod.c modal4.c shaker.c fm4op.c diskin.c
CSRCE = pvadd.c moog1.c singwave.c mandolin.c space.c locsig.c dcblockr.c
CSRCF = pvocext.c flanger.c aifc.c lowpassr.c uggab.c biquad.c one_file.c
CSRCG = schedule.c midiops3.c pitch.c getstring.c ugsc.c fout.c sndinfUG.c
CSRCH = pvlook.c scansyn.c sfont.c vbap.c vbap_four.c vbap_eight.c 
CSRCI = vbap_sixteen.c vbap_zak.c control.c bowedbar.c phisem.c sdif.c
CSRCJ = sdif-mem.c babo.c ugmoss.c bbcut.c spat3d.c pvxanal.c mxfft.c
CSRCK = pvsanal.c pstream.c pvfileio.c oscbnk.c scansynx.c oscils.c
CSRCL = wave-terrain.c dnoise.c dnfft.c mididevice.c clfilt.c midiinterop.c

CSRCS =	$(CSRC1) $(CSRC2) $(CSRC3) $(CSRC4) $(CSRC5) $(CSRC6) $(CSRC7) \
	$(CSRC8) $(CSRC9) $(CSRCA) $(CSRCB) $(CSRCC) $(CSRCD) $(CSRCE) \
	$(CSRCF) $(CSRCG) $(CSRCH) $(CSRCI) $(CSRCJ) $(CSRCK) $(CSRCL)

CSCM  = cscormai.o natben.o
COBJ1 =	main.o argdecode.o musmon.o otran.o oload.o rdorch.o express.o
COBJ2 = rdscor.o linevent.o cscore.o cscorfns.o insert.o entry1.o entry2.o aops.o
COBJ3 = midiops.o midirecv.o fgens.o ugens1.o ugens2.o ugens3.o ugens4.o
COBJ4 =	ugens5.o ugens6.o ugens7.o ugens8.o ugens9.o spectra.o disprep.o
COBJ5 =	window.o winascii.o $(WINOBJ) hetro.o lpanal.o lptrkfns.o pvanal.o
COBJ6 =	pvoc.o fft.o dsputil.o sndinfo.o sfheader.o soundin.o soundio.o
COBJ7 = ulaw.o aiff.o wave.o ieee80.o filopen.o memalloc.o memfiles.o auxfd.o
COBJ8 = windin.o dumpf.o $(AUDOBJ) scot.o scsort.o scxtract.o sread.o sort.o
COBJ9 = extract.o twarp.o swrite.o butter.o grain.o vdelay.o cmath.o follow.o
COBJA = cvanal.o grain4.o pvinterp.o pvread.o sndwarp.o vpvoc.o hrtferX.o
COBJB = winEPS.o nlfilt.o opcode.o ugrw1.o ugrw2.o ugensa.o cross2.o dam.o
COBJC = midiout.o midiops2.o midisend.o wavegde.o filter.o complex.o repluck.o
COBJD = pluck.o physutil.o physmod.o modal4.o shaker.o fm4op.o diskin.o
COBJE = pvadd.o moog1.o singwave.o mandolin.o space.o locsig.o dcblockr.o
COBJF = pvocext.o flanger.o aifc.o lowpassr.o uggab.o biquad.o one_file.o
COBJG = schedule.o midiops3.o pitch.o getstring.o ugsc.o fout.o sndinfUG.o
COBJH = pvlook.o scansyn.o sfont.o vbap.o vbap_four.o vbap_eight.o
COBJI = vbap_sixteen.o vbap_zak.o control.o bowedbar.o phisem.o sdif.o 
COBJJ = sdif-mem.o babo.o ugmoss.o bbcut.o spat3d.o pvxanal.o mxfft.o
COBJK = pvsanal.o pstream.o pvfileio.o oscbnk.o scansynx.o oscils.o
COBKL = wave-terrain.o dnoise.o dnfft.o mididevice.o clfilt.o midiinterop.o
COBJS =	$(COBJ1) $(COBJ2) $(COBJ3) $(COBJ4) $(COBJ5) $(COBJ6) $(COBJ7) \
	$(COBJ8) $(COBJ9) $(COBJA) $(COBJB) $(COBJC) $(COBJD) $(COBJE) \
	$(COBJF) $(COBJG) $(COBJH) $(COBJI) $(COBJJ) $(COBJK) $(COBKL)

HDRS =  3Dug.h aiff.h aops.h bowed.h brass.h butter.h clarinet.h \
	cmath.h complex.h convolve.h cs.h cscore.h dam.h diskin.h disprep.h \
	dpwelib.h dsputil.h dumpf.h fft.h fhtfun.h filter.h flute.h fm4op.h \
	follow.h ftgen.h grain.h grain4.h hrtferx.h ieee80.h insert.h \
	lpc.h marimba.h midioops.h midiops.h midiops2.h midiout.h modal4.h \
	moog1.h nlfilt.h oload.h physutil.h pluck.h prototyp.h ptrigtbl.h \
	pvadd.h pvinterp.h pvoc.h pvread.h repluck.h revsets.h scot.h \
	sfheader.h shaker.h singwave.h sndwarp.h sort.h soundio.h spectra.h \
	sysdep.h ugens1.h ugens2.h ugens3.h ugens4.h ugens5.h ugens6.h \
	ugens7.h ugens8.h ugens9.h ugensa.h ugrw1.h ugrw2.h vdelay.h \
	version.h vibraphn.h vpvoc.h wave.h wavegde.h winEPS.h windin.h \
	cwindow.h mandolin.h space.h locsig.h dcblockr.h pvocext.h flanger.h \
	lowpassr.h uggab.h biquad.h schedule.h midiops3.h pitch.h text.h \
	ugsc.h fout.h sndinfUG.h scansyn.h sf.h sfont.h sfenum.h sftype.h \
	vbap.h control.h bowedbar.h phisem.h sdif.h sdif-mem.h babo.h \
	ugmoss.h bbcut.h spat3d.h pstream.h pvfileio.h pvxanal.h oscbnk.h \
	scansynx.h oscils.h wave-terrain.h clfilt.h midiinterop.h opcode.h

PROGS   = csound
SUBDIRS = anals utils1 utils2 utils3

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

csound:		$(COBJS) $(CSUM) $(CDEP) csound.xmg
		$(CC) $(CFLAGS) -o csound $(COBJS) $(LIBS)

TAGS:	$(CSRCS) $(HDRS)
		etags $(CSRCS) $(HDRS)

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

xmg:	American.xmg English.xmg csound.xmg

American.xmg:	all_strings makedb
	./makedb all_strings American

English.xmg:	english-strings makedb
	./makedb english-strings English

csound.xmg:	all_strings English.xmg
	cp English.xmg csound.xmg
#	cp American.xmg csound.xmg

makedb:	makedb.c text.h
	$(CC) -o makedb makedb.c

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

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): natben.o
		cd util1; $(MAKE) $@

UTILS2 = sndinfos scale mixers extractor envelope pvlook dnoise srconv #targets in util2
utils2 $(UTILS2):
		cd util2; $(MAKE) $@

UTIL3 = sdif2adsyn.c sdif.c sdif-mem.c

UTILS3 = sdif2ad
utils3: $(UTILS3)

sdif2ad: sdif2adsyn.o sdif.o sdif-mem.o
	$(CC) sdif2adsyn.o sdif.o sdif-mem.o -o sdif2ad

install:	$(PROGS) $(CSA) csound.a sdif2ad
		-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
		-cp sdif2ad $(DEST)/sdif2ad
#		cd util3; $(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 *~

CSLinux.bin.tgz: /usr/local/bin/csound /usr/local/bin/hetro \
	/usr/local/bin/lpanal /usr/local/bin/pvanal /usr/local/bin/scot \
	/usr/local/bin/scsort /usr/local/bin/extract /usr/local/bin/sndinfo \
	/usr/local/bin/scale /usr/local/bin/mixer /usr/local/bin/extractor \
	/usr/local/bin/envext /usr/local/bin/pvlook /usr/local/bin/sdif2ad \
	/usr/local/bin/dnoise /usr/local/bin/srconv
	(cd /usr/local/bin; tar cvzf ~/csound/CSLinux.bin.tgz csound \
	hetro lpanal pvanal scot scsort extract sndinfo scale mixer \
	extractor envext pvlook sdif2ad dnoise srconv)

Csound.tar.gz:  all_files \
	$(CSRCS) $(HDRS) \
	LINUXaudio.c DECaudio.c DECplay.c HPplay.c DECaudio.h \
	DECplay.h SGIplay.c anal/adsyn/main.c anal/adsyn/makef anal/lpc/main.c \
	anal/lpc/makef anal/makef anal/makef anal/pvoc/main.c anal/pvoc/makef \
	Makefile.sol cscofils/combine.c cscofils/default.c cscofils/pulse.c \
	cscofils/sine.orc cscofils/sine.sco cscofils/switch.c cscofils/test.c \
	cscofils/test2.c cscofils/README cscofils/aliases cscormai.c Makefile \
	util1/cscore/makef util1/makef util1/scot/main.c util1/scot/makef \
	util1/sortex/makef util1/sortex/smain.c util1/sortex/xmain.c \
	util2/envext/envext.c util2/envext/makef util2/exports/Makefile \
	util2/exports/het_export.c util2/exports/het_import.c \
	util2/exports/lpc_export.c util2/exports/pv_export.c \
	util2/exports/pv_import.c util2/makef util2/mixer/makef \
	util2/mixer/mixer.c util2/mixer/xtrct.c util2/mkgraph/fg.h \
	util2/mkgraph/fgdemo.c util2/mkgraph/mkgraph.c util2/scale.dir/makef \
	util2/scale.dir/scale.c util2/sndinfo/main.c \
	util2/sndinfo/makef util2/pvlook.dir/makef winSGI.c winbor.c winwat.c winfg.c
		tar cvf - `cat all_files` | gzip > Csound.tar.gz

distrib:	all Csound.tar.gz
	cp MUSIC/csound/Csound.tar.gz ~ftp/pub/dream
	cp MUSIC/csound/csound ~ftp/pub/dream/SGI
	cp MUSIC/csound/anal/hetro ~ftp/pub/dream/SGI
	cp MUSIC/csound/anal/lpanal ~ftp/pub/dream/SGI
	cp MUSIC/csound/anal/pvanal ~ftp/pub/dream/SGI
	cp MUSIC/csound/util1/scot/scot ~ftp/pub/dream/SGI
	cp MUSIC/csound/util1/cscore/cscore.a ~ftp/pub/dream/SGI
	cp MUSIC/csound/util1/sortex/extract ~ftp/pub/dream/SGI
	cp MUSIC/csound/util1/sortex/scsort ~ftp/pub/dream/SGI
	cp MUSIC/csound/util2/envext/envext ~ftp/pub/dream/SGI
	cp MUSIC/csound/util2/exports/het_import ~ftp/pub/dream/SGI
	cp MUSIC/csound/util2/exports/het_export ~ftp/pub/dream/SGI
	cp MUSIC/csound/util2/exports/pv_import ~ftp/pub/dream/SGI
	cp MUSIC/csound/util2/exports/pv_export ~ftp/pub/dream/SGI
	cp MUSIC/csound/util2/exports/lpc_export ~ftp/pub/dream/SGI
	cp MUSIC/csound/util2/mixer/mixer ~ftp/pub/dream/SGI
	cp MUSIC/csound/util2/mixer/extractot ~ftp/pub/dream/SGI
	cp MUSIC/csound/util2/scale.dir/scale ~ftp/pub/dream/SGI
	cp MUSIC/csound/util2/sndinfo/sndinfo ~ftp/pub/dream/SGI

depend:
	gcc -M $(DEFINES) $(CSRCS) $(CSMS) $(UTIL3) > deps
	cat Makefile deps > makefile

# DO NOT DELETE THIS LINE
