#
# Makefile for Ada-Binding to Motif/X Revision 0.3
#
# 30.09.96 H.-F. Vogt
# 15.11.96 H.-F. Vogt: automatic detection of big/little endian
# 11.01.97 H.-F. Vogt: replace "[" by "test"
# 09.08.97 H.-F. Vogt: replace echo by printf
# 02.08.99 H.-F. Vogt: added IS_LESSTIF
# 29.02.00 H.-F. Vogt: added dependence on Local.conf
# 26 Aug 2001 H.-F. Vogt: add configuration variable GNAT313p_BUG
#

include Local.conf

SUBDIRS = lib utils
ALL_SUBDIRS = $(SUBDIRS) examples

all: config
	for i in $(SUBDIRS) ; \
	do \
		(cd $$i; make all); \
	done

config: Local.conf utils/preprocess utils/islittleend
	@cd lib; \
	if test -f ../config ; \
	then \
		$(RM) ../config; \
	fi; \
	printf '' > ../config; \
	if test -n "$(IS_MOTIF21)" -a -n "$(IS_MOTIF20)" ; \
	then \
		printf 'choose only ONE OF IS_MOTIF21 and IS_MOTIF20!'; \
		printf ' -DMotif2.1' >> ../config; \
	else \
		if test -n "$(IS_MOTIF21)" ; \
		then \
			printf ' -DMotif2.1' >> ../config; \
		fi; \
		if test -n "$(IS_MOTIF20)" ; \
		then \
			printf ' -DMotif2.0' >> ../config; \
		fi; \
	fi; \
	if test -n "$(IS_LESSTIF)" ; \
	then \
		printf ' -DLesstif' >> ../config; \
	fi; \
	if test -n "$(IS_X11R63)" -a -n "$(IS_X11R6)" ; \
	then \
		printf 'choose only ONE OF IS_X11R63 and IS_X11R6!'; \
		printf ' -DX11R6.3' >> ../config; \
	else \
		if test -n "$(IS_X11R63)" ; \
		then \
			printf ' -DX11R6.3' >> ../config; \
		fi; \
		if test -n "$(IS_X11R6)" ; \
		then \
			printf ' -DX11R6' >> ../config; \
		fi; \
	fi; \
	if test -n "$(IS_64BIT)" ; \
	then \
		printf ' -D64Bit' >> ../config; \
	fi; \
	if test -n "$(GNAT313p_BUG)" ; \
	then \
		printf ' -DGnat3.13p' >> ../config; \
	fi; \
	little=`../utils/islittleend`; \
	echo $$little; \
	if test -n "$$little" ; \
	then \
		printf ' -DLittleEndian' >> ../config; \
	fi; \
	pre_opts=`cat ../config`; \
	if test -f xxx ; \
	then \
		$(RM) xxx; \
	fi; \
	for i in *.ad[sb] ; \
	do \
		../utils/preprocess $$pre_opts $$i > xxx && $(MV) xxx $$i ; \
	done
	@echo 'Ada files preprocessed!'

utils/preprocess:
	cd utils; make preprocess

utils/islittleend:
	cd utils; make islittleend

clean:
	for i in $(SUBDIRS) ; \
	do \
		(cd $$i; make clean); \
	done

distclean:
	for i in $(ALL_SUBDIRS) ; \
	do \
		(cd $$i; make distclean); \
	done
	@$(RM) config
