#Compiler
CC= gcc

#For Optimization
CFLAGS= -O2 -Wall
LFLAGS= -lncurses
#For debugging
#CFLAGS= -g

# Installation directory 
BIN_DIR= /sbin
# cofig dir & man pages
CFG_DIR= /etc
MAN_DIR= /usr/man/man8
DOC_DIR= /usr/doc/tmount

RM= /bin/rm -f
CP= /bin/cp
CHMOD= /bin/chmod
COMPRES= /usr/bin/strip
VER=1.1
#--- You shouldn't have to edit anything else. ---

.c.o: 
	$(CC) -c $(CFLAGS) $<

all: query

help :
	########################################################
	# Usage:    make <option>
	# Options:  none, compile program
	#           install, compile and install all
	#           install_exe, compile and install exe program
	#           clean, delete *.o and program files
	#           archive, create source archive in tar.gz
linux:
	make all

query: main.o conf.o mtab.o list.o mount.o color.o
	$(CC) main.o conf.o mtab.o list.o mount.o color.o -o tmount $(CFLAGS) $(LFLAGS)
	$(COMPRES) tmount

clean:
	$(RM) *.o *~ core tmount

install: install_exe
	mkdir $(DOC_DIR)
	$(CP) tmountrc $(CFG_DIR)
	$(CP) COPYING $(DOC_DIR)
	$(CP) ChangeLog $(DOC_DIR)
	$(CP) README $(DOC_DIR)
	$(CHMOD) 644 $(CFG_DIR)/tmountrc
	$(CHMOD) 644 $(DOC_DIR)/COPYING
	$(CHMOD) 644 $(DOC_DIR)/ChangeLog
	$(CHMOD) 644 $(DOC_DIR)/README

install_exe : all
	$(CP) tmount $(BIN_DIR)
	$(CP) tmount.8.gz $(MAN_DIR)
	$(CHMOD) 755 $(BIN_DIR)/tmount
	$(CHMOD) 644 $(MAN_DIR)/tmount.8.gz

archive:
	mkdir tmount\-$(VER)
	$(CHMOD) 755 tmount\-$(VER)
	$(CP) *.c tmount\-$(VER)
	$(CP) *.h tmount\-$(VER)
	$(CP) C* tmount\-$(VER)
	$(CP) Makefile tmount\-$(VER)
	$(CP) README tmount\-$(VER)
	$(CP) tmount.8.gz tmount\-$(VER)
	$(CP) tmountrc tmount\-$(VER)
	tar cf tmount\-$(VER).src.tar tmount\-$(VER)/
	gzip -9 tmount\-$(VER).src.tar
	$(RM) -r tmount\-$(VER)/
