##########################################################################
##########################################################################
#
# Main makefile for the Linux driver for Eagle-based USB ADSL Modems
#
##########################################################################
##########################################################################

-include Makefile.common

# Messages:
SEP="===================================================================================="
ROOT_MSG="\n\nYou have to be root to do that!\n"
AUTOGEN_MSG="\n\nYou have to run ./autogen.sh first!\n"
CONFIGURE_MSG="\n\nYou have to run ./configure first!\n"
CVS_MSG="\n\nOnly CVS version can do that!\n"
INSTALL_OK_MSG="\n\nInstallation has finished!\nYou should now run eagleconfig to setup your connexion.\n"
UNINSTALL_OK_MSG="\n\nUninstall has finished.\nYou can now replug your modem (if necessary).\n"
ARCHNAME="eagle-`cat VERSION`"

all: build

build:
	@if [ ! -e configure ] ; then \
		echo -e $(AUTOGEN_MSG) ; \
		exit 1 ; \
	fi
	@if [ ! -e Makefile.common ] ; then \
		echo -e $(CONFIGURE_MSG) ; \
		exit 1 ; \
	fi
	make -C driver && \
	make -C pppoa

eagleconfig:

install:
	@if [ `id -ur` != 0 ] ; then \
		echo -e $(ROOT_MSG) ; \
		exit 1 ; \
	fi
	@if [ ! -e configure ] ; then \
		echo -e $(AUTOGEN_MSG) ; \
		exit 1 ; \
	fi
	@if [ ! -e Makefile.common ] ; then \
		echo -e $(CONFIGURE_MSG) ; \
		exit 1 ; \
	fi
	mkdir -p $(SBINDIR) && \
	mkdir -p $(EU_DIR) && \
	mkdir -p $(EU_LANG_DIR) && \
	mkdir -p $(EU_SCRIPT_DIR) && \
	mkdir -p $(PPP_OPTIONS_DIR) && \
	make -C driver install && \
	make -C pppoa install && \
	make -C utils/scripts install && \
	echo -e $(INSTALL_OK_MSG)

uninstall:
	@if [ `id -ur` != 0 ] ; then \
		echo -e $(ROOT_MSG) ; \
		exit 1 ; \
	fi
	@if [ ! -e configure ] ; then \
		echo -e $(AUTOGEN_MSG) ; \
		exit 1 ; \
	fi
	@if [ ! -e Makefile.common ] ; then \
		echo -e $(CONFIGURE_MSG) ; \
		exit 1 ; \
	fi
	make -C utils/scripts uninstall && \
	make -C driver uninstall && \
	make -C pppoa uninstall && \
	hash -r && \
	echo -e $(UNINSTALL_OK_MSG)

clean:
	make -C driver clean && \
	make -C pppoa clean && \
	make -C utils/scripts clean

distclean: clean
	rm -f Makefile.common utils/eagleconfig/Makefile confdefs.h
	rm -rf config.{status,log,cache}

maintainer-clean: distclean
	@if [ ! -e makedist ] ; then \
		echo -e $(CVS_MSG) ; \
		exit 1 ; \
	fi
	rm -f configure aclocal.m4
	rm -Rf autom4te.cache

dist: maintainer-clean
	@if [ ! -e makedist ] ; then \
		echo -e $(CVS_MSG) ; \
		exit 1 ; \
	fi
	rm -f ../$(ARCHNAME).tar.bz2 && \
	./makedist $(ARCHNAME) `pwd`

.PHONY: install uninstall clean distclean maintainer-clean build all eagleconfig
