MAKE   = @MAKE@
RM     = @RM@
SHELL  = @SHELL@

# The empty string, "", in PKGS is needed to avoid /bin/sh from complaining
# when @PKGS@ is/are really empty.
PKGS   = "" @subdirs@

all:
	@-for pkg in $(PKGS) ; do \
	      if [ -n "$$pkg" -a -s $$pkg/Makefile ] ; then \
	          echo "Making $$pkg" ; \
	          ( cd $$pkg && $(MAKE) ) ; \
	      fi ; \
	  done

install:
	@if [ -n "$(PREFIX)" ] ; then \
	     ./sbin/install-package -prefix=$(PREFIX) ; \
	 else \
	     ./sbin/install-package ; \
	 fi

uninstall:
	@-./sbin/uninstall-package

clean:
	@-for pkg in $(PKGS) ; do \
	      if [ -n "$$pkg" -a -s $$pkg/Makefile ] ; then \
	          ( cd $$pkg && $(MAKE) clean ) ; \
	      fi ; \
	  done

rmprog:
	@-for file in bin/* sbin/* ; do \
	      suffix="`echo $$file|sed -e 's%\.% %'|awk '{print $$NF}' -`" ; \
	      if [ "X$$suffix" != "Xin" ] ; then \
	          $(RM) $$file ; \
	      fi ; \
	  done

distclean-misc:
	@-$(RM) sbin/install-package
	@-$(RM) Makefile
	@-$(RM) simple.class simple.jar simple_swing.class simple_swing.jar
	@-$(RM) config.log config.status
	@-$(RM) -r autom4te*.cache

distclean: rmprog distclean-misc
	@-for pkg in $(PKGS) ; do \
	      if [ -n "$$pkg" -a -s $$pkg/Makefile ] ; then \
	          ( cd $$pkg && $(MAKE) distclean ) ; \
	      fi ; \
	  done

maintainer-clean: rmprog distclean-misc
	@-for pkg in $(PKGS) ; do \
	      if [ -n "$$pkg" -a -s $$pkg/Makefile ] ; then \
	          ( cd $$pkg && $(MAKE) maintainer-clean ) ; \
	      fi ; \
	  done

owner-clean: rmprog distclean-misc
	@-for pkg in $(PKGS) ; do \
	      if [ -n "$$pkg" -a -s $$pkg/Makefile ] ; then \
	          ( cd $$pkg && $(MAKE) owner-clean ) ; \
	      fi ; \
	  done
	@-$(RM) configure
