# $Id: Makefile,v 1.4 2004/02/21 01:24:48 Tux Exp $
# Name: Makefile
# Goal: Main makefile for the Linux driver for Eagle-based USB ADSL Modems
# Author: Jerome Marant

-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"
INSTALL_OK_MSG="\n\nInstallation has finished!\nYou should now run eagleconfig to setup your connexion.\n"
UNINSTALL_OK_MSG="\n\nUninstall has finished."
UNINSTALL_OK2_MSG="You can now replug your modem (if necessary).\n"
#CVS_MSG="\n\nOnly CVS version can do that!\n"
ARCHNAME="eagle-usb-`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 && \
	$(MAKE) -C utils/scripts

install:
	#@if [ `id -ur` != 0 ] && [ "x`expr substr $(SBINDIR) 1 6`" != "x/home/"  ] ; 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 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 pppoa uninstall && \
	$(MAKE) -C driver uninstall && \
	hash -r && \
	echo -e $(UNINSTALL_OK_MSG) && \
	if test $(BUILD_MODULE) == 1 ; then \
		echo -e $(UNINSTALL_OK2_MSG) ; \
	else \
		echo ; \
	fi

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`

rpm: dist
	#@if [ `id -ur` != 0 ] ; then \
	#	echo -e $(ROOT_MSG) ; \
	#	exit 1 ; \
	#fi
	rm -f /usr/src/RPM/SOURCES/$(ARCHNAME).tar.bz2
	cp ../eagle-usb.dist/$(ARCHNAME).tar.bz2 /usr/src/RPM/SOURCES
	rpm -ba eagle.spec
	mv -f /usr/src/RPM/RPMS/i586/eagle-usb-*.rpm ../eagle-usb.dist ; \
	mv -f /usr/src/RPM/SRPMS/eagle-usb-*.rpm ../eagle-usb.dist ; \

.PHONY: all build install uninstall clean distclean maintainer-clean dist rpm
