
include Makefile.stub

all: lib/libasis$(arext) asistant

BLD=prod
tools = gnatstub gnatelim gnatmetric gnatpp gnatcheck
gu_tools = aunitstub aunitglue gnattest

I_BIN	= $(prefix)/bin
I_INC	= $(prefix)/include/asis
I_LIB	= $(prefix)/lib/asis
I_GPR	= $(prefix)/lib/gnat
I_DOC   = $(prefix)/share/doc/asis
I_GPS   = $(prefix)/share/gps/plug-ins
G_DOC   = $(prefix)/share/doc/gnat

install: install-lib install-asistant

install-lib:
	$(RMDIR) $(I_INC)
	$(RMDIR) $(I_LIB)
	$(MKDIR) $(I_BIN)
	$(MKDIR) $(I_INC)
	$(MKDIR) $(I_LIB)
	$(MKDIR) $(I_GPR)
	$(MKDIR) $(I_GPS)
	$(MKDIR) $(I_DOC)/html
	$(MKDIR) $(I_DOC)/info
	$(MKDIR) $(I_DOC)/pdf
	$(INSTALL_FILES) lib/*.ali $(I_LIB)
	$(CHMOD) a-w $(I_LIB)/*.ali
	$(INSTALL_FILES) lib/libasis$(arext) $(I_LIB)
	$(CHMOD) a-w $(I_LIB)/libasis$(arext)
ifneq ($(ATTRIB),)
	cd $(I_LIB) && $(ATTRIB) +r '*.ali'
	cd $(I_LIB) && $(ATTRIB) +r 'libasis$(arext)'
endif
	$(INSTALL_FILES) gnat/*.ads gnat/*.adb $(I_INC)
	$(INSTALL_FILES) asis/*.ads asis/*.adb $(I_INC)
	$(INSTALL_FILES) asis/asis.gpr $(I_GPR)
	$(INSTALL_FILES) documentation/gps_index.xml $(I_GPS)/asis.xml
	-$(INSTALL_FILES) documentation/asis_*.html $(I_DOC)/html/
	-$(INSTALL_FILES) documentation/asis_*.pdf  $(I_DOC)/pdf/
	-$(INSTALL_FILES) documentation/asis_*.info $(I_DOC)/info/

lib/libasis$(arext): force
	cd gnat && $(GNATMAKE) xsnamest && ./xsnamest \
		&& mv snames.ns snames.ads && mv snames.nb snames.adb
	$(GNATMAKE) -Pasis_bld -XBLD=$(BLD) -XOPSYS=$(OPSYS)

install-tools: $(tools:%=install-%)
	echo $<
	
install-gu_tools: $(gu_tools:%=install-%)
	echo $<

gnat%:
	$(GNATMAKE) "-Ptools/$@/$@" "-XBLD=$(BLD)" "-XOPSYS=$(OPSYS)" -p
	
aunit%:
	$(GNATMAKE) "-Ptools/$@/$@" "-XBLD=$(BLD)" "-XOPSYS=$(OPSYS)" -p

tools: $(tools)

gu_tools: $(gu_tools)

asistant:
	$(GNATMAKE) "-Ptools/$@/$@" "-XBLD=$(BLD)" "-XOPSYS=$(OPSYS)"

gnattest_hash_testing:
	$(GNATMAKE) "-Ptools/gnattest/hash_testing/$@" "-XBLD=$(BLD)" "-XOPSYS=$(OPSYS)"

install-asistant:
	$(MKDIR) $(I_BIN)
	$(INSTALL_FILES) tools/asistant/asistant$(exe_ext) $(I_BIN)

install-gnat%: gnat%
	$(MKDIR) $(I_BIN)
	$(INSTALL_FILES) tools/gnat$*/gnat$*$(exe_ext) $(I_BIN)
	
install-aunit%: aunit%
	$(MKDIR) $(I_BIN)
	$(INSTALL_FILES) tools/aunit$*/aunit$*$(exe_ext) $(I_BIN)

install-gnatcheck-doc:
	$(MKDIR) $(G_DOC)/html
	$(MKDIR) $(G_DOC)/info
	$(MKDIR) $(G_DOC)/pdf
	$(MKDIR) $(G_DOC)/txt
	$(INSTALL_FILES) documentation/gnatcheck_rm.pdf  $(G_DOC)/pdf/
	$(INSTALL_FILES) documentation/gnatcheck_rm*.html $(G_DOC)/html/
	$(INSTALL_FILES) documentation/gnatcheck_rm.info $(G_DOC)/info/
	$(INSTALL_FILES) documentation/gnatcheck_rm.txt $(G_DOC)/txt/

atre:
	gnat make -Ptools/$@/$@

clean-gnat%:
	gnat clean -Ptools/gnat$*/gnat$*
	
clean-aunit%:
	gnat clean -Ptools/aunit$*/aunit$*

clean: clean-gnatstub clean-gnatelim clean-gnatpp clean-gnatmetric clean-gnatcheck
	gnat clean -Pasis_bld
	
gu_clean: clean-aunitstub clean-aunitglue clean-gnattest
	gnat clean -Pasis_gu_bld

force:
