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

prefix	= @prefix@
exec_prefix	= @exec_prefix@
bindir		= @bindir@
mandir		= @mandir@

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@
INSTALL_DATA	= @INSTALL_DATA@
transform	= @program_transform_name@
RANLIBPROG      = $(shell echo ranlib | sed '$(transform)')

MYINCLUDES      = -I$(srcdir) -I$(top_builddir)/include \
			-I$(top_srcdir)/include $(INCPRIVEXT) $(FORHDRS)
MYWARNINGS      =
MYDEFS          = -DBINDIR="\"$(bindir)\"" -DRANLIBPROG="\"$(RANLIBPROG)\""
MYLDFLAGS	= -L$(top_builddir)/libstuff
MYLIBS		= -lstuff

MYCOMPILEFLAGS	= $(WARNINGS) $(MYWARNINGS) $(DEFS) $(MYDEFS) \
	$(CPPFLAGS) $(MYINCLUDES) $(CFLAGS) $(MDYNAMICNOPIC) 
	
MYLINKFLAGS	= $(LDFLAGS) $(MYLDFLAGS) $(MYLIBS)

CFILES = append.c ar.c archive.c contents.c delete.c extract.c misc.c \
	move.c print.c replace.c 
OBJS = $(CFILES:.c=.o)

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

.PHONY: default install clean distclean

default: ar

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

install: ar
	mkdir -p $(DESTDIR)/$(bindir)
	mkdir -p $(DESTDIR)$(mandir)/man1
	mkdir -p $(DESTDIR)$(mandir)/man5
	$(INSTALL_PROGRAM) ar \
		$(DESTDIR)/$(bindir)/`echo ar | sed '$(transform)'`
	$(INSTALL_DATA) $(srcdir)/ar.1 $(DESTDIR)$(mandir)/man1
	$(INSTALL_DATA) $(srcdir)/ar.5 $(DESTDIR)$(mandir)/man5


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