# Makefile for NDir
# Copyright (c) 1998 - 2003 Michael Weers
#
# This is the main Makefile for NDir. Below are some customization settings.
#
#------------------------------------
# The installation directory prefix: Files will be installed in 
# some of its subdirectories

prefix= /usr/local
#prefix=$(HOME)

#------------------------------------
# Install with multi machine type option (n/y for no/yes, usually no)

multi_machine_mode= n 

#------------------------------------
#  Uncomment next line if you are using the GNU C++ standard library ver. 2.7.x
#  (only on very old systems)
#CPPFLAG += -DGNU_CPPSTDLIB_VER27
#------------------------------------
#  Uncomment next line for compatibility with libc versions that are not able
#  to do thousands grouping (%'d format for printf())
#CFLAGS += -DNO_THOUSANDS_GROUPING
#------------------------------------
#  Uncomment next line if using EGCS as compiler
#CPPFLAGS += -fno-rtti -fno-exceptions
#------------------------------------
#  Default compiler flags. Alter only if neccessary.
CFLAGS +=  -Wall -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
#------------------------------------
#  End of the customization settings.
#------------------------------------
export CFLAGS
export CPPFLAGS
#====================================
version= 0.8.7
package_revision= 1
#------------------------------------
machine= $(shell uname -m)
#------------------------------------
# directory prefix, for executable's directories
exec_prefix= $(prefix)
# general executables' directory
bindir= $(exec_prefix)/bin
# man page directory
# TODO: change to share/man (if /usr/local/share/man is commonly used)
mandir= $(prefix)/man

# directory for machine-dependend files (executables)
ifeq ($(multi_machine_mode),y)
binexecdir=$(bindir)/$(machine)
else
binexecdir=$(bindir)
endif
#------------------------------------
distname= NDir-$(version)-$(package_revision)
distdir= NDir-$(version)
distfiles= README INSTALL VERSION COPYING ChangeLog "To do.html" Makefile ndir.1 lv.1 lw.1 src bin \
ndir-$(version)-$(package_revision).spec
#------------------------------------

.PHONY : compile clean distclean doc dist install uninstall install_alt print_defines

compile :
	$(MAKE) -C src ;

clean : 
	$(MAKE) clean -C src

distclean : clean
	rm -f *~

doc :
	$(MAKE) doc -C src 

dist : distclean doc
	echo $(version) > VERSION
	rm -rf $(distdir)
	mkdir $(distdir)
	cp -R $(distfiles) $(distdir)/
	tar czf $(distname).tar.gz $(distdir)
	rm -rf $(distdir)

install :
ifeq ($(multi_machine_mode),y)
	@echo "Installing NDir with multi machine type mode to $(binexecdir)"
else
	@echo "Installing NDir to $(bindir)"
endif
	mkdir -p $(bindir) $(binexecdir) $(mandir)/man1
	cp src/ndir $(binexecdir)/
	cp bin/uninstall-ndir $(bindir)/  
	cp *.1 $(mandir)/man1/
	cd $(bindir) ; chmod 744 uninstall-ndir 
	cd $(binexecdir) ; strip ndir ; ln -f -s ndir lw ; ln -f -s ndir lv ;
             
uninstall :
	echo "Please run 'uninstall-ndir' from the installation directory."

print_defines :
	$(CXX) -E -dM src/dir.cpp
