# This line is needed on some machines.
@SET_MAKE@
VPATH=@srcdir@
prefix=@prefix@
INSTALL=@INSTALL@
SRCDIR=@srcdir@
CC=@CC@
PIKE=@PIKE@
LIBS=@LIBS@   @GTK_LIBS@
MODULE=GTK
LDFLAGS=@LINKFORSHARED@ @LDFLAGS@
LD=@LDSHARED@
CFLAGS=-I$(SRCDIR) -I@PIKEINCLUDE@ -I. @WARN@ @CFLAGS@ @CPPFLAGS@ @GTK_CFLAGS@
OBJS=""
DEST=@DEST@
OS=`uname -srm|sed -e 's/ /-/g'|tr '[A-Z]' '[a-z]'|tr '/' '_'`
BUILDDIR=build/$(OS)

# FIXME: This should be automatic
DISTDIR=pigtk_1.1.2
# OBJS=$(shell cat files_to_compile)
# This is only possible with GNU make...
#.. so we use a trick instead. :-)

all: sources
	$(MAKE) "SOURCES=`cat sources`" all2

all2: files_to_compile
	$(MAKE) "OBJS=`cat files_to_compile`" "SOURCES=`cat sources`" $(MODULE).@SO@

debug: 
	$(MAKE) "CFLAGS=-g $(CFLAGS)" all

install: files_to_compile
	$(MAKE)  "OBJS=`cat files_to_compile`" "SOURCES=`cat sources`" real-install


sources: source
	$(PIKE) $(SRCDIR)/make_sources.pike $(SRCDIR)/source

clean:
	rm *.c *.o *.so files_to_compile prototypes.h

ChangeLog:
	(cd $(SRCDIR) && make_changelog.pike > ChangeLog)

ChangeLog.gz:
	(cd $(SRCDIR) && make_changelog.pike | gzip -9 > ChangeLog.gz)

configure: configure.in
	@echo Rebuilding the configure-script...; \
	echo; \
	aclocal && autoconf;

cvs_proper: CVS
	@echo Fixing CVS pointers...; \
	for f in `find $(DISTDIR) -type d -name CVS -print`; do \
	  if egrep '^*@beldandy.idonex.se:/cvs' "$$f/Root" 2>&1 >/dev/null; \
	  then \
	    echo "Altering $$f..."; \
	    echo "anonymous@beldandy.idonex.se:/cvs" >"$$f/Root"; \
	  else :; fi; \
	done;

dist_setup: ChangeLog
	@echo Building distribution...; \
	dist_dir=pigtk_1.1.1; \
	mkdir -p $(DISTDIR); \
	cp $(SRCDIR)/* $(DISTDIR) 2>&1| grep -v "omitting dir"; \
	cp $(SRCDIR)/.cvsignore $(DISTDIR); \
	cp -rf $(SRCDIR)/$(MODULE)Support.pmod $(DISTDIR); \
	cp -rf $(SRCDIR)/GDKSupport.pmod $(DISTDIR); \
	cp -rf $(SRCDIR)/pcdocs $(DISTDIR); \
	cp -rf $(SRCDIR)/CVS $(DISTDIR); \
	cp -rf $(SRCDIR)/examples $(DISTDIR); \
	rm -f $(DISTDIR)/config.[^h]*; \
	rm -f $(DISTDIR)/config.h; \
	rm -f $(DISTDIR)/*.tar.gz; \
	rm -f $(DISTDIR)/*.c; \
	rm -f $(DISTDIR)/Makefile;

dist: dist_setup cvs_proper
	@echo  Building tar files...; \
	tar cf - $(DISTDIR) | gzip -9 >$(DISTDIR).tar.gz;

$(MODULE).@SO@: $(OBJS)
	$(LD) $(LDFLAGS) $(OBJS) -o $(MODULE).@SO@ $(LIBS)

files_to_compile: configure pgtk.c.head $(SOURCES) build_pgtk.pike
	$(PIKE) $(SRCDIR)/build_pgtk.pike $(SRCDIR)

real-install: $(MODULE).@SO@
	cp -r $(SRCDIR)/$(MODULE)Support.pmod $(DEST);
	cp -r $(SRCDIR)/GDKSupport.pmod $(DEST);
	$(INSTALL) $(SRCDIR)/$(MODULE).pmod $(DEST);
	$(INSTALL) $(SRCDIR)/GDK.pmod $(DEST);
	$(INSTALL) $(MODULE).@SO@ $(DEST);

quick_docs:
	$(PIKE) $(SRCDIR)/build_pgtk.pike $(SRCDIR) docs

docs: install
	$(MAKE) quick_docs
