CC=gcc
TARG=$(shell $(CC) -dumpmachine)
# CPU specific options

GNATMAKE=gnatmake

ifneq ($(shell $(CC) -dumpspecs | grep gnatmon),)
  SPECSTARG:=specs-fromgcc
else
  SPECSTARG:=$(shell if [ -f ../specs/$(TARG) ]; then echo "specs-predef"; else echo "specs-error"; fi >&1)
endif

.PHONY: bin exec

all: $(SPECSTARG) bin exec

bin:
	$(GNATMAKE) -f -pg main.adb -largs --specs=./specs

exec:
	./main
	gprof ./main

specs-fromgcc:
	@echo "modifying gcc specs to include ../../libgnatmon.a"
	$(CC) -dumpspecs | sed -e 's/-lgnatmon/..\/..\/libgnatmon.a/' > specs

specs-predef:
	@echo "using ../specs/$(TARG) as gcc specs"
	cp ../specs/$(TARG) specs

specs-error:
	@echo "*** Unsupported target $(TARG) !!!"
	@echo "  please furnish a gcc spec in ../specs/$(TARG) taking into account libgnatmon.a"
	error


orig:
	$(GNATMAKE) -pg main.adb -o main-orig -f

clean:
	rm -f specs gmon.out b~* *~ *.ali *.o main main-orig *.exe
