
MEDTARGETS := test clean distclean
TOPTARGETS := all install uninstall
#distclean is called at launchpad build, for here if there were configures

SUBDIRS := dev src oad oaas
ALLDIRS := example $(SUBDIRS)

ifndef prefix
prefix=/usr
endif

ifeq ($(shell dpkg-architecture -qDEB_HOST_ARCH), i386)
#let error if not dpkg-architecture to be visible for correction . or || uname -m , patsubst
	conv_64=1
else
	ifndef conv_64
		conv_64=0
	endif
endif

$(TOPTARGETS): $(SUBDIRS)
$(MEDTARGETS): $(ALLDIRS)
$(ALLDIRS):
	$(MAKE) -C $@ conv_64=${conv_64} $(MAKECMDGOALS)

test:
	RUN__SHELL=$(SHELL) . ./shl && cd csrc && conv_64=${conv_64} make && cd ../tests && \
	conv_64=${conv_64} RUN__SHELL="$${RUN__SHELL}" $${RUN__SHELL} ./as && conv_64=${conv_64} $${RUN__SHELL} ./c 1 && \
	$${RUN__SHELL} ./apy && conv_64=${conv_64} $${RUN__SHELL} ./c 1 && \
	cd ffdec && conv_64=${conv_64} RUN__SHELL="$${RUN__SHELL}" $${RUN__SHELL} ./as && \
	cd ../data && conv_64=${conv_64} RUN__SHELL="$${RUN__SHELL}" $${RUN__SHELL} ./test x && \
	cd ../as3 && conv_64=${conv_64} RUN__SHELL="$${RUN__SHELL}" $${RUN__SHELL} ./as && \
	echo tests ok
clean:
	RUN__SHELL=$(SHELL) . ./shl && cd csrc && make clean && cd ../tests && \
	$${RUN__SHELL} ./c && cd ffdec && $${RUN__SHELL} ./c && cd ../data && $${RUN__SHELL} ./c && cd ../as3 && $${RUN__SHELL} ./c
install:
	install -D oaalternative.sh $(DESTDIR)$(prefix)/bin/oaalternative.sh
	install -D oaalternative.py $(DESTDIR)$(prefix)/bin/oaalternative.py
	install -D oaalternativer.py $(DESTDIR)$(prefix)/bin/oaalternativer.py
	install -D oaas3 $(DESTDIR)$(prefix)/bin/oaas3
uninstall:
	-rm -f $(DESTDIR)$(prefix)/bin/oaalternative.sh
	-rm -f $(DESTDIR)$(prefix)/bin/oaalternative.py
	-rm -f $(DESTDIR)$(prefix)/bin/oaalternativer.py
	-rm -f $(DESTDIR)$(prefix)/bin/oaas3

.PHONY: $(TOPTARGETS) $(MEDTARGETS) $(ALLDIRS)
.NOTPARALLEL:
