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

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

VPATH = @srcdir@:@srcdir@/..

CC              = @CC@
WARNINGS	= @WARNINGS@
CFLAGS          = @CFLAGS@
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@

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

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

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

CFILES = app.c as.c atof-generic.c atof-ieee.c expr.c fixes.c flonum-const.c \
         flonum-copy.c flonum-mult.c frags.c hash.c hex-value.c input-file.c \
         input-scrub.c layout.c messages.c obstack.c read.c sections.c \
         symbols.c write_object.c xmalloc.c $(CFILES_$(ARCH))

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

.PHONY: default clean distclean install

default: as

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

install: as
	mkdir -p $(DESTDIR)/$(ASLIBEXECDIR)/$(ARCH)
	$(INSTALL_PROGRAM) as $(DESTDIR)/$(ASLIBEXECDIR)/$(ARCH)/as

clean:
	rm -r -f *.o
	rm -f as
