# Makefile for GNU superoptimizer

srcdir =	@srcdir@
VPATH =		@srcdir@

prefix =	@prefix@
exec_prefix =	@exec_prefix@

bindir =	$(exec_prefix)/bin
libdir =	$(exec_prefix)/lib
incdir =	$(prefix)/include
infodir =	$(prefix)/info
guidedir =	$(prefix)/guide

INSTALL =	@INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA =	@INSTALL_DATA@

SHELL =		/bin/sh
CC =		@CC@
AR =		ar
RM =		rm
RANLIB =	@RANLIB@
DEFS =		@DEFS@
LIBS =		@LIBS@
CFLAGS =	@CFLAGS@
LDFLAGS =	@LDFLAGS@

INCLUDES =	-I. -I$(srcdir)
OUR_CFLAGS =	-DDBUG $(DEFS) $(INCLUDES) $(CFLAGS)

.SUFFIXES:	.r .r~ .c .c~

.c.o:
		$(CC) -c $(OUR_CFLAGS) $<


MAXCOST = 3
EXTRA = -shifts -extracts

ALL_MACHINES =	superopt-sparc \
		superopt-power \
		superopt-powerpc \
		superopt-m88000 \
		superopt-am29k \
		superopt-mc68000 \
		superopt-mc68020 \
		superopt-i386 \
		superopt-i960a \
		superopt-i960b \
		superopt-pyr \
		superopt-alpha \
		superopt-sh \
		superopt-hppa

OBJS	= superopt.o
SRCS	= superopt.c
HDRS	= run_program.def insn.def goal.def superopt.h version.h longlong.h
FILES	= README COPYING Makefile TODO ChangeLog superopt.c synth.def $(HDRS)

VERSION = `sed 's,char \*version_string = "\([0-9.]*\)";,\1,' < version.h`

all:	superopt superopt020

superopt: $(srcdir)/superopt.c $(HDRS)
	$(CC) $(OUR_CFLAGS) $(LDFLAGS) -DMC68000 -o superopt $(srcdir)/superopt.c

superopt020: $(srcdir)/superopt.c $(HDRS)
	$(CC) $(OUR_CFLAGS) $(LDFLAGS) -DMC68020 -o superopt020 $(srcdir)/superopt.c

clean:
	rm -f $(OBJS) superopt $(ALL_MACHINES) *.tmp

install: superopt
	$(INSTALL) superopt $(bindir)/superopt
	$(INSTALL) superopt020 $(bindir)/superopt020

all-machines: $(ALL_MACHINES)

install-all: all
	for x in $(ALL_MACHINES); do $(INSTALL) $$x $(bindir)/$$x; done

run-all: sparc.res power.res powerpc.res m88000.res am29k.res mc68000.res \
	mc68020.res i386.res i960a.res i960b.res pyr.res alpha.res sh.res \
	hppa.res
	@echo "Done!"

superopt-sparc: superopt.c $(HDRS)
	$(CC) $(OUR_CFLAGS) $(LDFLAGS) -DSPARC -o superopt-sparc $(srcdir)/superopt.c

sparc.res: superopt-sparc
	./superopt-sparc -all $(EXTRA) -max $(MAXCOST) -as >sparc.tmp 2>&1
	mv sparc.tmp sparc.res

superopt-power: superopt.c $(HDRS)
	$(CC) $(OUR_CFLAGS) $(LDFLAGS) -DPOWER -o superopt-power $(srcdir)/superopt.c

power.res: superopt-power
	./superopt-power -all $(EXTRA) -max $(MAXCOST) -as >power.tmp 2>&1
	mv power.tmp power.res

superopt-powerpc: superopt.c $(HDRS)
	$(CC) $(OUR_CFLAGS) $(LDFLAGS) -DPOWERPC -o superopt-powerpc $(srcdir)/superopt.c

powerpc.res: superopt-powerpc
	./superopt-powerpc -all $(EXTRA) -max $(MAXCOST) -as >powerpc.tmp 2>&1
	mv powerpc.tmp powerpc.res

superopt-m88000: superopt.c $(HDRS)
	$(CC) $(OUR_CFLAGS) $(LDFLAGS) -DM88000 -o superopt-m88000 $(srcdir)/superopt.c

m88000.res: superopt-m88000
	./superopt-m88000 -all $(EXTRA) -max $(MAXCOST) -as >m88000.tmp 2>&1
	mv m88000.tmp m88000.res

superopt-am29k: superopt.c $(HDRS)
	$(CC) $(OUR_CFLAGS) $(LDFLAGS) -DAM29K -o superopt-am29k $(srcdir)/superopt.c

am29k.res: superopt-am29k
	./superopt-am29k -all $(EXTRA) -max $(MAXCOST) -as >am29k.tmp 2>&1
	mv am29k.tmp am29k.res

superopt-mc68000: superopt.c $(HDRS)
	$(CC) $(OUR_CFLAGS) $(LDFLAGS) -DMC68000 -o superopt-mc68000 $(srcdir)/superopt.c

mc68000.res: superopt-mc68000
	./superopt-mc68000 -all $(EXTRA) -max $(MAXCOST) -as >mc68000.tmp 2>&1
	mv mc68000.tmp mc68000.res

superopt-mc68020: superopt.c $(HDRS)
	$(CC) $(OUR_CFLAGS) $(LDFLAGS) -DMC68020 -o superopt-mc68020 $(srcdir)/superopt.c

mc68020.res: superopt-mc68020
	./superopt-mc68020 -all $(EXTRA) -max $(MAXCOST) -as >mc68020.tmp 2>&1
	mv mc68020.tmp mc68020.res

superopt-i386: superopt.c $(HDRS)
	$(CC) $(OUR_CFLAGS) $(LDFLAGS) -DI386 -o superopt-i386 $(srcdir)/superopt.c

i386.res: superopt-i386
	./superopt-i386 -all $(EXTRA) -max $(MAXCOST) -as >i386.tmp 2>&1
	mv i386.tmp i386.res

superopt-i960a: superopt.c $(HDRS)
	$(CC) $(OUR_CFLAGS) $(LDFLAGS) -DI960 -o superopt-i960a $(srcdir)/superopt.c

i960a.res: superopt-i960a
	./superopt-i960a -all $(EXTRA) -max $(MAXCOST) -as >i960a.tmp 2>&1
	mv i960a.tmp i960a.res

superopt-i960b: superopt.c $(HDRS)
	$(CC) $(OUR_CFLAGS) $(LDFLAGS) -DI960B -o superopt-i960b $(srcdir)/superopt.c

i960b.res: superopt-i960b
	./superopt-i960b -all $(EXTRA) -max $(MAXCOST) -as >i960b.tmp 2>&1
	mv i960b.tmp i960b.res

superopt-pyr: superopt.c $(HDRS)
	$(CC) $(OUR_CFLAGS) $(LDFLAGS) -DPYR -o superopt-pyr $(srcdir)/superopt.c

pyr.res: superopt-pyr
	./superopt-pyr -all $(EXTRA) -max $(MAXCOST) -as >pyr.tmp 2>&1
	mv pyr.tmp pyr.res

superopt-alpha: superopt.c $(HDRS)
	$(CC) $(OUR_CFLAGS) $(LDFLAGS) -DALPHA -o superopt-alpha $(srcdir)/superopt.c

alpha.res: superopt-alpha
	./superopt-alpha -all $(EXTRA) -max $(MAXCOST) -as >alpha.tmp 2>&1
	mv alpha.tmp alpha.res

superopt-sh: superopt.c $(HDRS)
	$(CC) $(OUR_CFLAGS) $(LDFLAGS) -DSH -o superopt-sh $(srcdir)/superopt.c

sh.res: superopt-sh
	./superopt-sh -all $(EXTRA) -max $(MAXCOST) -as >sh.tmp 2>&1
	mv sh.tmp sh.res

superopt-hppa: superopt.c $(HDRS)
	$(CC) $(OUR_CFLAGS) $(LDFLAGS) -DHPPA -o superopt-hppa $(srcdir)/superopt.c

hppa.res: superopt-hppa
	./superopt-hppa -all $(EXTRA) -max $(MAXCOST) -as >hppa.tmp 2>&1
	mv hppa.tmp hppa.res

dist:
	mkdir superopt-$(VERSION)
	ln $(FILES) superopt-$(VERSION)
	tar cf - superopt-$(VERSION) | gzip --best > superopt-$(VERSION).tar.gz
	rm -rf superopt-$(VERSION)
