
export

## generic autoconf stuff
SHELL = /bin/sh
VPATH = @srcdir@

subdirs = @subdirs@
top_srcdir = @top_srcdir@
srcdir = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
datadir = @datadir@
bindir = $(exec_prefix)/bin
infodir = $(prefix)/info
libdir = $(prefix)/lib/goo/
mandir = $(prefix)/man/man1
exe_suffix=@exe_suffix@

CC = @CC@
CPPFLAGS = @CPPFLAGS@
CFLAGS = $(CPPFLAGS) @CFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
INSTALL = @INSTALL@
INSTALL_PROGRAM=@INSTALL_PROGRAM@
INSTALL_SCRIPT=@INSTALL_PROGRAM@
INSTALL_DATA=@INSTALL_DATA@

## end generic stuff
THREADKIND=@THREADKIND@

GOO_ROOT=$(libdir)
GOO_LIB = $(libdir)/lib
GOO_MODS = $(libdir)/mods

build_gc = @build_gc@

ifeq ($(sub), )
  sub = g2c
endif

C_OBJS   = grt.o # unexelf.o midi.o threads.o timer.o 

ifeq ($(build_gc), yes)
  C_OBJS += gc.a
endif

LDFLAGS  += -Wl,--export-dynamic

default: all

gc-stamp: Makefile
	touch gc-stamp
ifeq ($(build_gc), yes)
	cd $(top_srcdir)/gc && $(MAKE) clean && ./configure --enable-threads=$(THREADKIND) && $(MAKE) libgc.la
	rm -f gc
	ln -s -f $(top_srcdir)/gc/include gc
	ln -s -f $(top_srcdir)/gc/.libs/libgc.a gc.a;
else
	rm -f gc gc.a;
endif

all: gc-stamp
	(cd $(sub); $(MAKE))

# Create installation
install: all
	$(top_srcdir)/mkinstalldirs $(bindir)
	$(top_srcdir)/mkinstalldirs $(GOO_LIB)
	$(top_srcdir)/mkinstalldirs $(GOO_MODS)
ifeq ($(sub), g2c)
	$(INSTALL_PROGRAM) $(sub)/$(sub)$(exe_suffix) $(bindir)/goo$(exe_suffix)
else
	$(INSTALL_PROGRAM) $(sub)/$(sub)$(exe_suffix) $(bindir)
endif
	$(INSTALL_DATA) grt.h $(GOO_LIB)
	$(INSTALL_DATA) config.h $(GOO_LIB)
	$(INSTALL_DATA) dlgrt.h $(GOO_LIB)
ifeq ($(build_gc), yes)
	cd $(top_srcdir)/gc/include/ && find . -name \*.h -exec $(INSTALL_DATA) -D {} $(GOO_LIB)/gc/{} \;
endif

clean:
	rm -f grt.o unexelf.o gc gc.a gc-stamp
	(cd $(sub); $(MAKE) clean)

distclean: clean
	rm -f Makefile config.h

.PHONY: all install clean distclean

