#	Id	
#	$NetBSD: Makefile.in,v 1.1.1.1 2016/02/09 20:29:11 plunky Exp $
#
# Makefile.in for the front end driver of PCC
#

srcdir=@srcdir@
top_srcdir=@top_srcdir@
top_builddir=@top_builddir@
bindir=@bindir@
libdir=@libdir@
libexecdir=@libexecdir@
includedir=@includedir@
mandir=@mandir@
man1dir=$(mandir)/man1
man1ext=.1
EXEEXT=@EXEEXT@
CC=@CC@
SHELL=@SHELL@
TARGOS=@targos@
TARGOSVER=@targosver@
TARGMACH=@targmach@
TARGET=@target@
VERSION=@PACKAGE_VERSION@
CFLAGS=@CFLAGS@ @ADD_CFLAGS@
CPPFLAGS=@CPPFLAGS@ @ADD_CPPFLAGS@ \
	-DLIBEXECDIR=\"$(libexecdir)/\" \
	-DINCLUDEDIR=\"$(includedir)/\" \
	-DPCCINCDIR=\"$(libdir)/pcc/$(TARGET)/$(VERSION)/include\" \
	-DPCCLIBDIR=\"$(libdir)/pcc/$(TARGET)/$(VERSION)/lib\" \
	-I$(top_builddir) -I$(top_srcdir)/os/$(TARGOS) -I$(MIPDIR)
LIBS=@LIBS@
LDFLAGS=@LDFLAGS@
INSTALL=@INSTALL@
INSTALL_PROGRAM=@INSTALL_PROGRAM@
INSTALL_DATA=@INSTALL_DATA@

# and fix these in configure.ac
TARGETS=amd64 i386
PROGRAMS=cc cpp c++ ftn

MIPDIR=$(top_srcdir)/mip

DEST=	driver
OBJS=	compat.o driver.o list.o opt.o options.o target.o xalloc.o

HDRS=	$(srcdir)/driver.h

all: $(DEST)

$(DEST) $(OBJS)
	$(CC) $(LDFLAGS) $(OBJS) -o $@ $(LIBS)

$(OBJS): $(HDRS)

compat.o: $(MIPDIR)/compat.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(MIPDIR)/compat.c

driver.o: $(srcdir)/driver.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/driver.c

list.o: $(srcdir)/list.c $(srcdir)
	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/list.c

opt.c: $(srcdir)/mkopt.sh
	$(SHELL) $(srcdir)/mkopt.sh > $@

opt.o: opt.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ opt.c

options.o: $(srcdir)/options.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/options.c

xalloc.o: $(srcdir)/xalloc.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(srcdir)/xalloc.c

target.i: $(srcdir)/target.c
	@for t in $(TARGETS); do \
		$(CC) $(CFLAGS) $(CPPFLAGS) \
		    -I../os/$(TARGOS) -Dos_$(TARGOS) \
		    -DTARGOS=\"$(TARGOS)\" -DTARGOSVER=$(TARGOSVER) \
		    -I../arch/$${t} -Dmach_$${t} \
		    -DTARGMACH=\"$${t}\" \
		    -DTARGET=targ_$${t} -E $(srcdir)/target.c ; \
	done > $@

target.o: target.i
	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ target.i

install: $(DEST)
	test -z "$(DESTDIR)$(bindir)" || mkdir -p $(DESTDIR)$(bindir)
	test -z "$(DESTDIR)$(man1dir)" || mkdir -p $(DESTDIR)$(man1dir)
	@for p in $(PROGRAMS); do				\
		$(INSTALL_PROGRAM) $(DEST)			\
		    $(DESTDIR)$(bindir)/$${p}$(EXEEXT) ;	\
		$(INSTALL_DATA) $(srcdir)/driver.man		\
		    $(DESTDIR)$(man1dir)/$${p}$(man1ext) ;	\
	done
	test -z "$(DESTDIR)$(PCCINCDIR)" || mkdir -p "$(DESTDIR)$(PCCINCDIR)"
	test -z "$(DESTDIR)$(PCCLIBDIR)" || mkdir -p "$(DESTDIR)$(PCCLIBDIR)"

clean:
	rm -f $(DEST) $(OBJS) target.i

distclean: clean
	rm -f Makefile
