PACKAGE = @SND_PACKAGE@
VERSION = @SND_VERSION@

CC = @CC@
SHELL = @SHELL@
INSTALL = @INSTALL@
INSTALL_DATA = ${INSTALL} -m 0644

CFLAGS = @CFLAGS@
GTK_CFLAGS = @GTK_CFLAGS@
XEN_CFLAGS = @XEN_CFLAGS@
CAIRO_CFLAGS = @CAIRO_CFLAGS@
MOTIF_FLAGS = @XFLAGS@
FFTW_CFLAGS = @FFTW_CFLAGS@
GL_FLAGS = @GL_FLAGS@
GSL_FLAGS = @GSL_CFLAGS@
JACK_FLAGS = @JACK_FLAGS@

ORIGINAL_LDFLAGS = @ORIGINAL_LDFLAGS@
LDFLAGS = @LDFLAGS@

LIBS = @LIBS@
XEN_LIBS = @XEN_LIBS@
GTK_LIBS = @GTK_LIBS@
GTK_LD_LIBS = @GTK_LD_LIBS@
MOTIF_LIBS = @XLIBS@
AUDIO_LIB = @AUDIO_LIB@
GSL_LIBS = @GSL_LIBS@
GL_LIBS = @GL_LIBS@
GL_FILES = @GL_FILES@
FFTW_LIBS = @FFTW_LIBS@
SNDLIB_LIB = @SNDLIB_LIB@
FAM_LIB = @FAM_LIB@
JACK_LIBS = @JACK_LIBS@
GMP_LIBS = @GMP_LIBS@

LDSO_FLAGS = @LDSO_FLAGS@
SO_FLAGS = @SO_FLAGS@
SO_LD = @SO_LD@

prefix = @prefix@
exec_prefix = @exec_prefix@
datadir = @datadir@
bindir = @bindir@
srcdir = @srcdir@
VPATH = @srcdir@
mandir = @mandir@
top_srcdir = @top_srcdir@

datarootdir = ${prefix}/share
pkgdatadir = ${datarootdir}/snd
# snd-help.c looks for the documentation in /usr/local/share/doc/snd-11 -- perhaps it should be pkgdatadir? or passed at compile time
DEFS = -DSCRIPTS_DIR=\"$(pkgdatadir)\" @DEFS@

SNDLIB_FILES = $(@SNDLIB_FILES@)

GX_FILES = $(@GX_FILES@)
GX_HEADERS = $(@GX_HEADERS@)

.SUFFIXES:
.SUFFIXES: .c .o

.c.o:
	$(CC) -c $(DEFS) $(GTK_CFLAGS) $(CAIRO_CFLAGS) $(CFLAGS) $(XEN_CFLAGS) $(MOTIF_FLAGS) $(GSL_FLAGS) $(GL_FLAGS) $(JACK_FLAGS) $(FFTW_CFLAGS) $<

SND_SCRIPTS = *.scm *.fs *.rb *.fsm
SNDLIB_HEADERS = mus-config.h sndlib.h _sndlib.h sndlib-strings.h clm.h vct.h sndlib2xen.h clm2xen.h xen.h clm-strings.h
SND_HEADERS = mus-config.h sndlib.h _sndlib.h clm.h snd.h snd-0.h snd-1.h snd-strings.h xen.h snd-menu.h snd-file.h
SND_X_HEADERS = snd-x0.h snd-x1.h
SND_G_HEADERS = snd-g0.h snd-g1.h
SNDLIB_O_FILES = headers.o audio.o io.o sound.o clm.o xen.o vct.o sndlib2xen.o clm2xen.o

S7_HEADERS = s7.h mus-config.h
S7_FILES = s7.c
S7_O_FILES = @S7_LIB@

NO_GUI_HEADERS = snd-nogui0.h snd-nogui1.h

O_FILES = snd-io.o snd-utils.o snd-listener.o snd-error.o snd-completion.o snd-menu.o snd-axis.o snd-data.o snd-fft.o snd-marks.o snd-file.o snd-edits.o snd-chn.o snd-dac.o snd-region.o snd-select.o snd-find.o snd-snd.o snd-help.o snd-main.o snd-print.o snd-trans.o snd-mix.o snd.o snd-env.o snd-xen.o snd-ladspa.o snd-kbd.o snd-sig.o snd-draw.o run.o

X_O_FILES = snd-xutils.o snd-xhelp.o snd-xfind.o snd-xmenu.o snd-xdraw.o snd-xlistener.o snd-xchn.o snd-xsnd.o snd-xregion.o snd-xdrop.o snd-xmain.o snd-xmix.o snd-xrec.o snd-xenv.o snd-gxbitmaps.o snd-gxcolormaps.o snd-xfft.o snd-xprint.o snd-xfile.o snd-xprefs.o

XM_O_FILES = snd-xutils.o snd-xhelp.o snd-xfind.o snd-xmenu.o snd-xdraw.o snd-xlistener.o snd-xchn.o snd-xsnd.o snd-xregion.o snd-xdrop.o snd-xmain.o snd-xmix.o snd-xrec.o snd-xenv.o snd-gxbitmaps.o snd-gxcolormaps.o snd-xfft.o snd-xprint.o snd-xfile.o snd-xprefs.o xm.o

G_O_FILES = snd-gutils.o snd-ghelp.o snd-gfind.o snd-gmenu.o snd-gdraw.o snd-glistener.o snd-gchn.o snd-gsnd.o snd-gregion.o snd-gdrop.o snd-gmain.o snd-gmix.o snd-grec.o snd-genv.o snd-gxbitmaps.o snd-gxcolormaps.o snd-gfft.o snd-gprint.o snd-gfile.o snd-gprefs.o

XG_O_FILES = snd-gutils.o snd-ghelp.o snd-gfind.o snd-gmenu.o snd-gdraw.o snd-glistener.o snd-gchn.o snd-gsnd.o snd-gregion.o snd-gdrop.o snd-gmain.o snd-gmix.o snd-grec.o snd-genv.o snd-gxbitmaps.o snd-gxcolormaps.o snd-gfft.o snd-gprint.o snd-gfile.o snd-gprefs.o xg.o

NO_GUI_O_FILES = snd-nogui.o
GM_FILES = xm.o
GM_SO_FILE = xm.so
GG_FILES = xg.o
GG_SO_FILE = xg.so
NO_FILES =

main_target: @MAKE_TARGET@

snd: $(SNDLIB_HEADERS) $(SND_HEADERS) $(GX_HEADERS) $(S7_HEADERS) $(S7_O_FILES) $(SNDLIB_FILES) $(O_FILES) $(GX_FILES) $(GL_FILES)
	$(CC) $(LDFLAGS) $(CFLAGS) $(S7_O_FILES) $(SNDLIB_FILES) $(O_FILES) $(GX_FILES) $(GL_FILES) -o snd $(SNDLIB_LIB) $(XEN_LIBS) $(GTK_LIBS) $(GL_LIBS) $(MOTIF_LIBS) $(JACK_LIBS) $(AUDIO_LIB) $(FFTW_LIBS) $(GSL_LIBS) $(FAM_LIB) $(GMP_LIBS) $(LIBS)

xm: 	xen.h mus-config.h $(S7_HEADERS)
	$(CC) -c xm.c -DUSE_SND=0 $(DEFS) $(SO_FLAGS) $(GTK_CFLAGS) $(CAIRO_CFLAGS) $(CFLAGS) $(XEN_CFLAGS) $(MOTIF_FLAGS) $(GSL_FLAGS) $(JACK_FLAGS) $(GL_FLAGS)
	$(SO_LD) $(GM_FILES) -o $(GM_SO_FILE) $(SO_FLAGS) $(LDSO_FLAGS) $(ORIGINAL_LDFLAGS) $(GL_LIBS) $(MOTIF_LIBS) $(FAM_LIB) $(GMP_LIBS) $(LIBS)

xg: 	xen.h mus-config.h $(S7_HEADERS)
	$(CC) -c xg.c -DUSE_SND=0 $(DEFS) $(SO_FLAGS) $(GTK_CFLAGS) $(CAIRO_CFLAGS) $(CFLAGS) $(XEN_CFLAGS) $(MOTIF_FLAGS) $(GSL_FLAGS) $(JACK_FLAGS) $(GL_FLAGS)
	$(SO_LD) $(GG_FILES) -o $(GG_SO_FILE) $(LDSO_FLAGS) $(ORIGINAL_LDFLAGS) $(GTK_LD_LIBS) $(FAM_LIB) $(GMP_LIBS) $(LIBS)


libxm:  xen.h mus-config.h $(S7_HEADERS) $(S7_O_FILES) 
	rm -f xen.o 
	$(CC) -c xen.c -DUSE_SND=0 $(DEFS) $(SO_FLAGS) $(GTK_CFLAGS) $(CAIRO_CFLAGS) $(CFLAGS) $(XEN_CFLAGS) $(MOTIF_FLAGS) $(GSL_FLAGS) $(JACK_FLAGS) $(GL_FLAGS) 
	$(CC) -c xm.c -DUSE_SND=0 $(DEFS) $(SO_FLAGS) $(GTK_CFLAGS) $(CAIRO_CFLAGS) $(CFLAGS) $(XEN_CFLAGS) $(MOTIF_FLAGS) $(GSL_FLAGS) $(JACK_FLAGS) $(GL_
	$(SO_LD) xen.o $(S7_O_FILES) $(GM_FILES) -o libxm.so $(SO_FLAGS) $(LDSO_FLAGS) $(ORIGINAL_LDFLAGS) $(GL_LIBS) $(MOTIF_LIBS) $(FAM_LIB) $(GMP_LIBS) $(XEN_LIBS) $(LIBS) 

libxg:	xen.h mus-config.h $(S7_HEADERS) $(S7_O_FILES) 
	rm -f xen.o 
	$(CC) -c xen.c -DUSE_SND=0 $(DEFS) $(SO_FLAGS) $(GTK_CFLAGS) $(CAIRO_CFLAGS) $(CFLAGS) $(XEN_CFLAGS) $(MOTIF_FLAGS) $(GSL_FLAGS) $(JACK_FLAGS) $(GL_FLAGS) 
	$(CC) -c xg.c -DUSE_SND=0 $(DEFS) $(SO_FLAGS) $(GTK_CFLAGS) $(CAIRO_CFLAGS) $(CFLAGS) $(XEN_CFLAGS) $(MOTIF_FLAGS) $(GSL_FLAGS) $(JACK_FLAGS) $(GL_FLAGS) 
	$(SO_LD) xen.o $(S7_O_FILES) $(GG_FILES) -o libxg.so $(LDSO_FLAGS) $(ORIGINAL_LDFLAGS) $(GTK_LD_LIBS) $(FAM_LIB) $(GMP_LIBS) $(XEN_LIBS) $(LIBS) 

widget: snd_widget.o

snd_widget.o: $(SNDLIB_HEADERS) $(SND_HEADERS) $(GX_HEADERS) $(S7_HEADERS) $(SNDLIB_FILES) $(O_FILES) $(GX_FILES) $(GL_FILES)
	$(LD) -r $(LDFLAGS) $(SNDLIB_FILES) $(O_FILES) $(GX_FILES) $(GL_FILES) -o snd_widget.o

$(SNDLIB_O_FILES): $(SNDLIB_HEADERS) $(SND_HEADERS) $(S7_HEADERS)
$(O_FILES): $(SNDLIB_HEADERS) $(SND_HEADERS) $(SND_X_HEADERS) $(S7_HEADERS)
$(X_O_FILES): $(SNDLIB_HEADERS) $(SND_HEADERS) $(SND_X_HEADERS) $(S7_HEADERS)
$(G_O_FILES): $(SNDLIB_HEADERS) $(SND_HEADERS) $(SND_G_HEADERS) $(S7_HEADERS)
$(S7_O_FILES): $(S7_HEADERS) $(S7_FILES)

clean:
	rm -f $(SNDLIB_O_FILES)
	rm -f $(O_FILES)
	rm -f $(X_O_FILES)
	rm -f $(G_O_FILES)
	rm -f $(NO_GUI_O_FILES)
	rm -f $(GM_FILES)
	rm -f $(GM_SO_FILE)
	rm -f $(GG_FILES)
	rm -f $(GG_SO_FILE)
	rm -f $(GL_FILES)
	rm -f $(S7_O_FILES)
	rm -f sndplay.o audinfo.o sndinfo.o
	rm -f snd sndplay audinfo sndinfo

distclean: clean
	rm -f mus-config.h config.log config.status makefile

clmclean:
	rm io.o headers.o audio.o sound.o clm.o

allclean:
	rm -f *.o
	rm -f *.so
	rm -f *.a
	rm -f snd sndplay audinfo sndinfo

sndplay: $(SNDLIB_HEADERS) $(S7_HEADERS)
	$(CC) -c $(DEFS) $(CFLAGS) -DUSE_SND=0 headers.c
	$(CC) -c $(DEFS) $(CFLAGS) -DUSE_SND=0 io.c
	$(CC) -c $(DEFS) $(CFLAGS) -DUSE_SND=0 audio.c
	$(CC) -c $(DEFS) $(CFLAGS) -DUSE_SND=0 sound.c
	$(CC) -c $(DEFS) $(CFLAGS) -DUSE_SND=0 sndplay.c
	$(CC) $(LDFLAGS) $(CFLAGS) headers.o io.o audio.o sound.o sndplay.o -o sndplay $(JACK_LIBS) $(AUDIO_LIB) $(LIBS)

sndinfo: $(SNDLIB_HEADERS) $(S7_HEADERS)
	$(CC) -c $(DEFS) $(CFLAGS) -DUSE_SND=0 headers.c
	$(CC) -c $(DEFS) $(CFLAGS) -DUSE_SND=0 io.c
	$(CC) -c $(DEFS) $(CFLAGS) -DUSE_SND=0 audio.c
	$(CC) -c $(DEFS) $(CFLAGS) -DUSE_SND=0 sound.c
	$(CC) -c $(DEFS) $(CFLAGS) -DUSE_SND=0 sndinfo.c
	$(CC) $(LDFLAGS) $(CFLAGS) headers.o io.o audio.o sound.o sndinfo.o -o sndinfo $(JACK_LIBS) $(AUDIO_LIB) $(LIBS)

audinfo: $(SNDLIB_HEADERS) $(S7_HEADERS)
	$(CC) -c $(DEFS) $(CFLAGS) -DUSE_SND=0 headers.c
	$(CC) -c $(DEFS) $(CFLAGS) -DUSE_SND=0 io.c
	$(CC) -c $(DEFS) $(CFLAGS) -DUSE_SND=0 audio.c
	$(CC) -c $(DEFS) $(CFLAGS) -DUSE_SND=0 sound.c
	$(CC) -c $(DEFS) $(CFLAGS) -DUSE_SND=0 audinfo.c
	$(CC) $(LDFLAGS) $(CFLAGS) headers.o io.o audio.o sound.o audinfo.o -o audinfo $(JACK_LIBS) $(AUDIO_LIB) $(LIBS)

install: snd
	${SHELL} ${top_srcdir}/mkinstalldirs ${DESTDIR}/${bindir}
	${SHELL} ${top_srcdir}/mkinstalldirs ${DESTDIR}/${mandir}
	${SHELL} ${top_srcdir}/mkinstalldirs ${DESTDIR}/${mandir}/man1
	${SHELL} ${top_srcdir}/mkinstalldirs ${DESTDIR}/${pkgdatadir}
	$(INSTALL) snd ${DESTDIR}/${bindir}/snd
	$(INSTALL_DATA) ${top_srcdir}/snd.1 ${DESTDIR}/${mandir}/man1
	(cd ${top_srcdir} && for f in ${SND_SCRIPTS}; do ${INSTALL_DATA} ${top_srcdir}/$${f} ${DESTDIR}/${pkgdatadir}/$${f}; done)

uninstall:
	rm -f ${bindir}/snd
	rm -f ${mandir}/man1/snd.1
	for f in ${SND_SCRIPTS};  do rm -f ${pkgdatadir}/$${f}; done

install-strip: snd
	${SHELL} ${top_srcdir}/mkinstalldirs ${DESTDIR}/${bindir}
	${SHELL} ${top_srcdir}/mkinstalldirs ${DESTDIR}/${mandir}
	${SHELL} ${top_srcdir}/mkinstalldirs ${DESTDIR}/${mandir}/man1
	${SHELL} ${top_srcdir}/mkinstalldirs ${DESTDIR}/${pkgdatadir}
	$(INSTALL) -s snd ${DESTDIR}/${bindir}/snd
	$(INSTALL_DATA) ${top_srcdir}/snd.1 ${DESTDIR}/${mandir}/man1
	(cd ${top_srcdir} && for f in ${SND_SCRIPTS}; do ${INSTALL_DATA} ${top_srcdir}/$${f} ${DESTDIR}/${pkgdatadir}/$${f}; done)

Makefile: Makefile.in config.status
	./config.status

config.status: configure
	./config.status --recheck

configure: configure.in
	cd $(srcdir); autoconf
