# Makefile for AutoMount
# Written and (C) Copyright Wolfram Saringer 1995/96/98


# programs to use
EDITOR        = emacsclient
LATEX	      = latex
CREATETAGS    = etags
# use less under linux:
MORE	      = less
#MORE	      = more

# locations to install the binaries to
DAEMONDIR     = /usr/sbin
CLIENTDIR     = /usr/bin
CONFIGDIR     = /etc

# the owner of the binary files
OWNER         = root
GROUP         = root
#GROUP         = users


# Compiler to use
# 1) on Solaris:
#CC            = cc
#CC            = gcc
# 2) on Linux:
CC            = gcc

###############################################
# Here you can add any options for the source code
# as described in the User guide.
# options as of ver. 0.09.05 are:
#OPTIONFLAGS   = -DUSE_EXTENDED_SIGARGS \
#                -DUSE_SYSLOGD \
#                -DDEFAULT_INTERVALL=5 \
#		 -DDEFAULT_INIT_FILE=/etc/automountd.conf \
#		 -DFIFO_NAME=/tmp/automountd.fifo \
#		 -DEJECT_ON_EXIT \
#		 -DFORCE_UNMOUNT_ON_EXIT \
#		 -DDONT_CATCH_SIGSEGV \
#		 -DDONT_USE_SELECT \
#		 -DMONITOR_MOUNT_COUNT \
#		 -DDONT_EJECT \
#                -DSKIP_ROUNDS=2

OPTIONFLAGS   = -DFORCE_UNMOUNT_ON_EXIT \
		-DMONITOR_MOUNT_COUNT 

# this is a special option:
# it selects the mount function to use (see Manual)
# Normally you can safely go on with the default
MOUNTERPROC = mount_std

# There are no special libraries needed, as index and rindex are
# now handled via makros under Solaris.
# 1) on Solaris:
#EXTRALIBS     = 
# 2) on Linux:
EXTRALIBS     = 

# produce debugging info
# 1) on Solaris:
#DEBUGFLAGS    = -g -xsb -xs -DDEBUG
# 2) on Linux:
#DEBUGFLAGS   = -g -DDEBUG

# additional defs:
# 1) on Solaris: (implies -DSVR4)
#ADDDEFS       = -DSOLARIS2
# 2) on Linux:
ADDDEFS       = -DLINUX

# "Production code" optimization
# 1) on Solaris:
#OPTFLAGS      = -O -native -xpentium -fast -xO4
#OPTFLAGS      = -O4
# 2) on Linux:
OPTFLAGS      = -O4


# Additional FLAGS
# 1) on Solaris: (reject non-ansi code, extended checking)
#ADDFLAGS       = -Xc -v
# -Xc cannot be used with signal.c
#ADDFLAGS       = -v
# 2) on Linux:
ADDFLAGS       = -Wall


# Flags to use:
CCFLAGS = $(DEBUGFLAGS) $(ADDDEFS) $(OPTFLAGS) $(ADDFLAGS) $(OPTIONFLAGS)

###########################################################
# Don't change anything below this line
# Definitions:
DAEMONSOURCES = main.c daemon_init.c main_loop.c signal_handlers.c \
		read_initfile.c check_cmdline.c check_fifo.c unmount.c \
		eject_volume.c answer_request.c $(MOUNTERPROC).c
DAEMONOBJECTS = main.o daemon_init.o main_loop.o signal_handlers.o \
		read_initfile.o check_cmdline.o check_fifo.o unmount.o \
		eject_volume.o answer_request.o $(MOUNTERPROC).o
CLIENTSOURCES = eject.c
CLIENTOBJECTS = eject.o
VOLCHECKSOURCES = volcheck.c
VOLCHECKOBJECTS = volcheck.o
COMMONSOURCES = get_line.c panic.c log_msg.c signal.c
COMMONOBJECTS = get_line.o panic.o log_msg.o signal.o
DOCSOURCES    = Doc/automount.tex Doc/Advanced.tex Doc/Copyright.tex \
		Doc/Internals.tex Doc/Introduction.tex Doc/Problems.tex \
		Doc/Usage.tex Doc/History.tex
HEADERS       = main.h consts.h functions.h typedef.h global.h panic.h \
		log_msg.h process_options.h client_err.h version.h
# Note that 'MOUNTERPROC' is a really source file, not an option
SOURCES	      = $(DAEMONSOURCES) $(CLIENTSOURCES) $(VOLCHECKSOURCES) $(COMMONSOURCES) $(MOUNTERPROC)

###########################################################
# toplevel targets

all: automountd eject volcheck

dist: docs
	@echo Creating distribution archive...
	@./package.sh
	@echo Done.

install: all
	if [ ! -f $(CONFIGDIR)/automound.conf ]; then \
	  cp -i automountd.conf $(CONFIGDIR); \
    fi
	cp -i ./automountd $(DAEMONDIR)
	chown $(OWNER) $(DAEMONDIR)/automountd
	chgrp $(GROUP) $(DAEMONDIR)/automountd
	cp -i ./eject $(CLIENTDIR)
	chown $(OWNER) $(CLIENTDIR)/eject
	chgrp $(GROUP) $(CLIENTDIR)/eject
	cp -i ./volcheck $(CLIENTDIR)
	chown $(OWNER) $(CLIENTDIR)/volcheck
	chgrp $(GROUP) $(CLIENTDIR)/volcheck

# lint all files in context
lint:
	lint $(ADDDEFS) $(DEBUGFLAGS) $(DAEMONSOURCES) $(COMMONSOURCES) |$(MORE)
	lint $(ADDDEFS) $(DEBUGFLAGS) $(CLIENTSOURCES) $(COMMONSOURCES) |$(MORE)

automountd: $(DAEMONOBJECTS) $(COMMONOBJECTS)
	$(CC) $(CCFLAGS) -o automountd $(COMMONOBJECTS) $(DAEMONOBJECTS) $(EXTRALIBS)

eject: $(CLIENTOBJECTS) $(COMMONOBJECTS)
	$(CC) $(CCFLAGS) -o eject $(COMMONOBJECTS) $(CLIENTOBJECTS) $(EXTRALIBS)

volcheck: $(CLIENTOBJECTS) $(COMMONOBJECTS) $(VOLCHECKOBJECTS)
	$(CC) $(CCFLAGS) -o volcheck $(COMMONOBJECTS) $(VOLCHECKOBJECTS) $(EXTRALIBS)

clean:
	rm -f *.o core automountd eject volcheck
realclean:
	rm -f *.o *~ core automountd eject volcheck Doc/*.dvi Doc/*.aux

edit:
	# create TAGS file
	$(CREATETAGS) $(SOURCES) $(HEADERS)
	# load into editor
	$(EDITOR) *.h *.c Doc/*.tex 

docs:	Doc/automount.dvi


###########################################################
# The subtargets:

Doc/automount.dvi:	$(DOCSOURCES)
	(cd Doc; $(LATEX) automount.tex;detex automount.tex >automount.txt; ../makeHTMLDocs.sh)

%.o: %.c $(HEADERS)
	$(CC) $(CCFLAGS) -c $*.c

$(MOUNTERPROC).o: $(MOUNTERPROC).c $(HEADERS)
	$(CC) $(CCFLAGS) -c $(MOUNTERPROC).c
