# $Id: Makefile,v 1.21 2004/08/26 21:36:41 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_MSG="==============================================================================="
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\n"
UNINSTALL_OK_MSG="\n\nUninstall has finished."
UNINSTALL_OK2_MSG="\n\n ********************************************************************\n"\
"* You should now unplug and replug your modem to clear its memory. *\n"\ "********************************************************************\n\n"
#UNINSTALL_OK2_MSG="You can now replug your modem (if necessary).\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 && \
	$(MAKE) -C utils/eagleconnect && \
	$(MAKE) -C doc

install:
	@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 && \
	$(MAKE) -C utils/eagleconnect install && \
	$(MAKE) -C doc install && \
	hash -r && \
	echo -e $(SEP_MSG) && \
	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 doc uninstall && \
	$(MAKE) -C utils/scripts uninstall && \
	$(MAKE) -C utils/eagleconnect uninstall && \
	$(MAKE) -C pppoa uninstall && \
	$(MAKE) -C driver uninstall && \
	hash -r && \
	echo -e $(SEP_MSG) && \
	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/eagleconnect clean && \
	$(MAKE) -C utils/scripts clean
	#$(MAKE) -C doc clean

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

maintainer-clean: distclean
	rm -f configure aclocal.m4
	rm -Rf autom4te.cache
	$(MAKE) -C doc clean

dist: maintainer-clean
	rm -f ../$(ARCHNAME).tar.bz2 && \
	./makedist $(ARCHNAME) `pwd`

rpm: dist
	if [ `id -ur` == 0 ] ; then \
		rm -f /usr/src/RPM/SOURCES/$(ARCHNAME).tar.bz2 ; \
		cp ../eagle-usb.dist/$(ARCHNAME).tar.bz2 /usr/src/RPM/SOURCES ; \
		rpmbuild --define='_prefix /usr' -ba eagle-usb.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 ; \
	else \
		if [ "`whereis -b rpmbuild`" = "rpmb:" ] ; then \
			echo "Error: rpm-build was not found on your system!" ; \
			exit 1 ; \
		fi ; \
		if [ ! -d ~/rpm ] ; then \
			echo "Error: ~/rpm missing, you should consider reading Mandrake's RpmHowTo..." ; \
			exit 1 ; \
		fi ; \
		rm -f ~/rpm/SOURCES/$(ARCHNAME).tar.bz2 ; \
		cp ../eagle-usb.dist/$(ARCHNAME).tar.bz2 ~/rpm/SOURCES ; \
		rpmbuild --define='_prefix /usr' -ba eagle-usb.spec ; \
		mv -f ~/rpm/RPMS/i586/eagle-usb-*.rpm ../eagle-usb.dist ; \
		mv -f ~/rpm/SRPMS/eagle-usb-*.rpm ../eagle-usb.dist ; \
	fi
		#rpmbuild -ta ../eagle-usb.dist/$(ARCHNAME).tar.bz2 ; \

DEBVERSION = $(shell sed -ne '1s/.*(\(.*\)-\(.*\)).*/\1/p' debian/changelog)
deb:
	fakeroot debian/rules clean
	cp -r . ../eagle-usb-${DEBVERSION}.orig
	if test `basename \`pwd\`` != eagle-usb-${DEBVERSION}; then \
		rm -rf ../eagle-usb-${DEBVERSION}; \
		ln -s `basename \`pwd\`` ../eagle-usb-${DEBVERSION}; fi
	cd .. ; dpkg-source -b -I"CVS" -I".*" -I"*~" -I"#*" \
		-sU "eagle-usb-${DEBVERSION}" "eagle-usb-${DEBVERSION}.orig"
	debian/rules build
	fakeroot debian/rules binary
	if test -L ../eagle-usb-${DEBVERSION}; then \
		rm -f ../eagle-usb-${DEBVERSION}; fi
	rm -rf ../eagle-usb-${DEBVERSION}.orig
	#pversion=`sed -ne '1s/.*(\(.*\)).*/\1/p' debian/changelog` ; \
	#arch=`dpkg-architecture -qDEB_HOST_ARCH` ; \
	#dpkg-genchanges >../eagle-usb_$${pversion}_$${arch}.changes

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

#***************************************************************************
# $Log: Makefile,v $
# Revision 1.21  2004/08/26 21:36:41  Tux
# - "make clean" does not remove manpages anymore
#
# Revision 1.20  2004/08/25 13:55:25  mcoolive
# - fix deb rule: there was a bug when the name of the directory was
#   "eagle-usb-version" instead of "eagleusb" (tarball versus cvs)
#
# Revision 1.19  2004/08/16 21:42:39  Tux
# - rpm generation : use /usr as default prefix (instead of /usr/local)
#
# Revision 1.18  2004/08/12 22:27:12  mcoolive
# - fix deb rule : fix the generation of the files `changes'
#
# Revision 1.17  2004/08/09 21:28:45  mcoolive
# - correct the generation of *.orig.tar.gz (by default tar dump symlinks)
#
# Revision 1.16  2004/08/07 12:31:51  Tux
# - add rules to generate docs
#
# Revision 1.15  2004/08/06 09:59:10  mcoolive
# - edit "deb" rule to remove warnings
#
# Revision 1.14  2004/08/05 15:36:31  mcoolive
# - the "clean" rule is propagated in "doc" subdirectory
# - add rule "deb" to construct debian packages
#
# Revision 1.13  2004/08/01 20:08:21  Tux
# - eagleconnect support
#
# Revision 1.12  2004/05/30 01:50:04  Tux
# - "rpm -ba" => "rpmbuild"
#
# Revision 1.11  2004/05/11 19:42:49  Tux
# - eagle.spec => eagle-usb.spec
# - add "hash -r" after "make install"
#
# Revision 1.10  2004/04/20 19:55:07  Tux
# - cosmetic changes
#
# Revision 1.9  2004/04/18 19:46:38  Tux
# - a string was badly displayed
#
# Revision 1.8  2004/04/18 13:55:03  Tux
# *** empty log message ***
#
# Revision 1.7  2004/04/03 16:09:07  Tux
# - ask the user to unplug&replug modem
#
#***************************************************************************/
