srcdir = @srcdir@
VPATH  = @srcdir@

rootdir = $(srcdir)
@MCFGR@@MCF@

foreigndirs=pc
codedirs=vfs lib doc slang gtkedit edit src gnome new_icons icons idl syntax
unixdirs=intl $(codedirs) doc-gnome @POSUB@
alldirs=$(unixdirs) $(foreigndirs) 
subdirs=$(alldirs)

INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@

DISTMAIN =	configure configure.in NEWS README INSTALL INSTALL.FAST \
		Makefile.in FAQ COPYING create_vcs install-sh \
		config.h.in mc-aclocal.m4 aclocal.m4 acconfig.h \
		VERSION mcfn_install.in Make.common.in README.PC \
		mc.spec mc.spec.in README.QNX VERSION.in \
		mkinstalldirs autogen.sh ABOUT-NLS gettext.m4 \
		config.guess config.sub README.smbfs

all: 
	@for dir in @INTLSUB@ ${codedirs} @POSUB@; do \
		(cd $$dir; ${MAKE} all || exit 1) \
	done

static:
	$(MAKE) _LDFLAGS="-static $(_LDFLAGS)"

configure: configure.in aclocal.m4
	chmod 755 configure

GNOME_M4_FILES = macros/gnome.m4 macros/gnome-vfs.m4 macros/gnome-undelfs.m4 \
	macros/linger.m4

aclocal.m4: mc-aclocal.m4 $(GNOME_M4_FILES) gettext.m4
	cd $(srcdir); cat $(GNOME_M4_FILES) mc-aclocal.m4 gettext.m4 > aclocal.m4

config.h.in: configure.in acconfig.h
	cd $(srcdir); autoheader

install: installdirs
	@for I in $(unixdirs); do cd $$I; $(MAKE) DESTDIR=$(DESTDIR) $@ || exit 1; cd ..; done
	$(INSTALL_DATA) $(srcdir)/FAQ $(DESTDIR)$(mclibdir)/FAQ
	$(INSTALL_PROGRAM) mcfn_install $(DESTDIR)$(suppbindir)/mcfn_install
	chmod +x $(DESTDIR)$(suppbindir)/mcfn_install
	@echo "Please verify that the configuration values are correctly"
	@echo "set in the mc.ext file in $(mclibdir)"

install.create_vcs:
	$(INSTALL_PROGRAM) $(srcdir)/create_vcs $(DESTDIR)$(suppbindir)/create_vcs
	if test x$(DESTDIR) = x; then $(SHELL) $(srcdir)/create_vcs; fi

installdirs:
	$(MKINSTALLDIRS) $(DESTDIR)$(bindir) $(DESTDIR)$(mclibdir)
	$(MKINSTALLDIRS) $(DESTDIR)$(mandir) $(DESTDIR)$(man8dir)
	$(MKINSTALLDIRS) $(DESTDIR)$(icondir) $(DESTDIR)$(suppbindir)
	$(MKINSTALLDIRS) $(DESTDIR)$(tidir) $(DESTDIR)$(extfsdir)
	$(MKINSTALLDIRS) $(DESTDIR)$(idldir) $(DESTDIR)$(syntaxdir)

mcfninstall:
	-/bin/sh ./mcfn_install

uninstall:
	@for I in $(unixdirs); do cd $$I; $(MAKE) $@ || exit 1; cd ..; done
	-$(RMF) $(DESTDIR)$(mclibdir)/FAQ
	-$(RMF) $(DESTDIR)$(suppbindir)/mcfn_install
	-rmdir $(DESTDIR)$(suppbindir)
	-rmdir $(DESTDIR)$(mclibdir)
	@echo Midnight Commander uninstalled

cross TAGS clean depend dep:
	@for I in $(unixdirs); do cd $$I; $(MAKE) $@ || exit 1; cd ..; done
	cd vfs/samba && $(MAKE) $@

Makefile: Makefile.in config.status
	CONFIG_FILES=Makefile CONFIG_HEADERS= $(SHELL) config.status

config.status: 
	if test -x config.status; then config.status --recheck; \
	else $(SHELL) configure; fi

realclean: clean 
	rm -f *~
	rm -f config.cache

# distclean goal is for making a clean source tree, but if you have run 
# configure from a different directory, then doesn't destroy all your
# hardly compiled and linked stuff. That's why there is always $(srcdir)/
# In that case most of those commands do nothing, except cleaning *~
# and cleaning source links.
distclean:
	rm -f $(srcdir)/*~ $(srcdir)/config.cache $(srcdir)/config.h
	rm -f $(srcdir)/mcfn_install
	@for I in $(alldirs); do cd $$I; $(MAKE) $@ || exit 1; cd ..; done
	rm -f $(srcdir)/Makefile $(srcdir)/Make.common
	rm -f lib/mc.ext mcfn_install 
	rm -f vfs/extfs/{ftplist,uzip,uzoo,lslR,ulha,ucpio,deb,urar,uar}
	rm -f $(srcdir)/config.log $(srcdir)/config.status 
	cd vfs/samba && $(MAKE) $@

distcopy:
	rm -rf $(top_srcdir)/mc-$(VERSION)
	mkdir $(top_srcdir)/mc-$(VERSION)
	for I in $(DISTMAIN); do cp $(top_srcdir)/$$I $(top_srcdir)/mc-$(VERSION) || cp $$I $(top_srcdir)/mc-$(VERSION); done
	for I in $(unixdirs); do \
	    mkdir $(top_srcdir)/mc-$(VERSION)/$$I; \
	    $(MAKE) -C $$I distcopy VERSION=$(VERSION) PACKAGE=mc || exit 1; \
	    done
	mkdir $(top_srcdir)/mc-$(VERSION)/macros
	for I in $(GNOME_M4_FILES); do cp $(top_srcdir)/$$I $(top_srcdir)/mc-$(VERSION)/macros; done
	$(MAKE) || exit 1; cd ..;
	cp $(top_srcdir)/po/Makefile.in.in $(top_srcdir)/mc-$(VERSION)/po;
	cp $(top_srcdir)/po/POTFILES.in $(top_srcdir)/mc-$(VERSION)/po;
	cp $(top_srcdir)/po/*.po $(top_srcdir)/po/*.gmo $(top_srcdir)/po/mc.pot $(top_srcdir)/po/stamp-cat-id $(top_srcdir)/po/cat-id-tbl.c $(top_srcdir)/mc-$(VERSION)/po;
	(cd $(top_srcdir); tar cvf - mc-$(VERSION) | \
	gzip -f9) > mc-$(VERSION).tar.gz

dist: configure config.h.in distcopy
	@:

#	rm -rf $(top_srcdir)/mc-$(VERSION) mc-$(VERSION)

mycheck: Makefile
	rm -rf mc-$(VERSION)
	tar xzvf $(top_srcdir)/mc-$(VERSION).tar.gz
	mkdir mc-$(VERSION)/=build
	mkdir mc-$(VERSION)/=inst
	dc_install_base=`cd mc-$(VERSION)/=inst && pwd`; \
	cd mc-$(VERSION)/=build \
	  && ../configure --srcdir=.. --prefix=$$dc_install_base \
	  && $(MAKE) \
	  && make install
	-rm -rf mc-$(VERSION)

mydistcheck: dist mycheck
	@echo ***********************************
	@echo mc-$(VERSION) is ready for release
	@echo ***********************************

distcheck:
	@echo use mydistcheck only if you know what you are doing.