builddir = @builddir@
top_builddir = @top_builddir@
srcdir = @srcdir@
top_srcdir = @top_srcdir@

prefix	= @prefix@
exec_prefix	= @exec_prefix@
libexecdir	= @libexecdir@
bindir		= @bindir@

VPATH = @srcdir@

CC              = @CC@
CFLAGS          = @CFLAGS@
WARNINGS	= @WARNINGS@
MDYNAMICNOPIC   = @MDYNAMICNOPIC@
CPPFLAGS        = @CPPFLAGS@
DEFS            = @DEFS@ @ENDIAN_FLAG@
LDFLAGS         = @LDFLAGS@
HAVE_PRIVEXT    = @HAVE_PRIVEXT@
HAVE_FOREIGN_HEADERS    = @HAVE_FOREIGN_HEADERS@

ifeq ($(HAVE_PRIVEXT),NO)
INCPRIVEXT      = -include $(top_srcdir)/include/extern.h
endif

ifeq ($(HAVE_FOREIGN_HEADERS),YES)
FORHDRS         = -I$(top_srcdir)/include/foreign
endif

INSTALL		= @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
ASLIBEXECDIR    = @ASLIBEXECDIR@
transform	= @program_transform_name@

MYINCLUDES      = -I$(srcdir) -I$(top_builddir)/include \
			-I$(top_srcdir)/include $(INCPRIVEXT) \
			$(FORHDRS)
MYWARNINGS      = 
MYDEFS          = -DNeXT_MOD -DASLIBEXECDIR="\"$(ASLIBEXECDIR)/\""
MYLDFLAGS	= -L$(top_builddir)/libstuff
MYLIBS		= -lstuff

MYCOMPILEFLAGS	= $(WARNINGS) $(MYWARNINGS) $(DEFS) $(MYDEFS) \
	$(CPPFLAGS) $(MYINCLUDES) $(CFLAGS) $(MDYNAMICNOPIC) 

MYLINKFLAGS	= $(LDFLAGS) $(MYLDFLAGS) $(MYLIBS)

ASTARGETS = @ASTARGETS@

CFILES = driver.c
OBJS = $(CFILES:.c=.o)

.c.o:
	$(CC) $(MYCOMPILEFLAGS) -c -o $@ $<

.PHONY: default install clean distclean $(ASTARGETS)

default: driver $(ASTARGETS)

$(ASTARGETS):
	cd $@ && $(MAKE)

driver: $(OBJS)
	$(CC) -o $@ $^ $(MYLINKFLAGS)

install: driver install-arch
	mkdir -p $(DESTDIR)/$(bindir)
	$(INSTALL_PROGRAM) driver \
		$(DESTDIR)/$(bindir)/`echo as | sed '$(transform)'`

install-arch:
	for ast in $(ASTARGETS); do				\
		(cd $${ast} && $(MAKE) install) || exit 1;	\
	done

clean:
	rm -r -f *.o
	rm -f driver
	for ast in $(ASTARGETS); do			\
		(cd $${ast} && $(MAKE) $@) || exit 1;	\
	done
