@SET_MAKE@

CC              = @CC@
CP              = cp -p
MKDIR           = mkdir -p
STRIP           = strip
INSTALL         = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA    = @INSTALL_DATA@
prefix          = @prefix@
bindir          = $(prefix)/bin

CFLAGS     = -g -O2 -funroll-loops
C_OBJECTS  = ../gnat/gexpect_tty.o ../pixmaps/pixmaps.o
GTK_LIBS   = @GTK_LIBS@
GTK_STATIC_LIBS = @GTK_STATIC_LIBS@
GTK_CFLAGS = @GTK_CFLAGS@
TARGET_CFLAGS = @TARGET_CFLAGS@
TARGET_LFLAGS = @TARGET_LFLAGS@
SOURCE_PATH = $(GTK_CFLAGS) -I../gnat -I../common
GNAT_FLAGS = -gnata -gnatwuwe
ALL_CFLAGS = $(CFLAGS) $(GNAT_FLAGS) $(SOURCE_PATH) $(TARGET_CFLAGS)
LINK_FLAGS = $(C_OBJECTS) $(TARGET_LFLAGS) $(GTK_LIBS)
ADALIB = $(strip $(shell gnatls -v | grep adalib))
GNATMAKE_FLAGS =

MAIN = gvd_main
EXEC = gvd

PKG_FILES=${wildcard *_pkg.adb}

all: $(EXEC)

stylechk: pkg_files style

style:
	make CFLAGS="-gnaty $(CFLAGS)" $(EXEC)

pkg_files: ${PKG_FILES}

${PKG_FILES}: force
	$(CC) -c $(ALL_CFLAGS) $@

$(EXEC): force
	gnatmake -m $(ALL_CFLAGS) $(MAIN) -o $(EXEC) $(GNATMAKE_FLAGS) \
	  -bargs -static -E -largs $(LINK_FLAGS)

static:
	make GTK_LIBS="$(GTK_STATIC_LIBS)" $(EXEC)

elim: $(EXEC)
	make GNATMAKE_FLAGS="-f -c -gnatc -gnatt $(GNATMAKE_FLAGS)" \
	     GNAT_FLAGS="-gnata" $(EXEC)
	gnatelim $(MAIN) > gnat.adc

libgvd:
	rm -f $(EXEC)
	$(CC) -c $(ALL_CFLAGS) gvd-api.adb
	gnatmake -m $(ALL_CFLAGS) $(MAIN) -o $(EXEC) $(GNATMAKE_FLAGS) \
	  -bargs -E -n -largs --LINK=true
	ar cr libgvd.a $(C_OBJECTS) b~$(MAIN).o gvd-api.o \
	  `grep '   --   ' b~$(MAIN).adb | grep '\.o$$' | sed 's/   --   //'`

gvd_test: gvd_test.o libgvd
	$(CC) -o gvd_test gvd_test.o $(GTK_LIBS) -L. -lgvd -L$(ADALIB) -lgnat

gvd_test.o: gvd_test.c gvd-api.h
	$(CC) -c $(CFLAGS) `gtk-config --cflags` gvd_test.c

# This rule should only be used under Windows NT/2000 systems
winps: force
	gnatmake -m $(ALL_CFLAGS) $@

install-nocheck: force
	$(MKDIR) $(bindir)
	$(INSTALL_PROGRAM) $(EXEC) $(bindir)
	$(STRIP) $(bindir)/$(EXEC)

install: $(EXEC) install-nocheck

clean:
	-$(RM) *.adt
	-$(RM) *.o
	-$(RM) *.ali
	-$(RM) *~
	-$(RM) b~*
	-$(RM) $(EXEC)
	-$(RM) *.exe
	-$(RM) libgvd.a
	-$(RM) gvd_test

mostlyclean: clean

distclean: mostlyclean
	-$(RM) Makefile

maintainer-clean: distclean

force:
