#
#
VERSION=0.14

#
# Your favorite compiler (you'll need an ANSI C Compiler).
#
CC=gcc
CPP=gcc -E
CFLAGS=-O 
LDFLAGS=

#
# Installation directories
#
prefix=/usr/local
bindir=$(prefix)/bin
libdir=$(prefix)/lib
mandir=$(prefix)/man/man1

# 
# This variables are based on the previous installation subdireectories
#
MC_HLP=-DHELPFILE=\""$(libdir)/mc.hlp"\"
MC_PROFILE=-DPROFILE=\""$(libdir)/mc.ini"\"
MC_MENU=-DMENU=\""$(libdir)/mc.menu"\"
MC_EXT=-DEXT=\""$(libdir)/mc.ext"\"

# 
# Uncomment the following line if you want to include mouse support
# In order to use this, you'll need the gpm linux mouse server and you
# need to point the MOULIB and MOUINC variables to the place where the
# GPM files resides.
#
#
# USEMOUSE=-Duse_mouse
# MOUSELIB=-lgpm
# MOULIB=-L/usr/local/lib
# MOUINC=-I/usr/local/include


VARS=$(MC_HLP) $(MC_PROFILE) $(MC_MENU) $(MC_EXT) \
     -DVERSION=\""$(VERSION)"\" $(XVAR)

#
# The directory where you installed the ncurses include files.
# On some Linux machines it's on /usr/include/ncurses, if you don't
# change this you will get another ncurses.h and get plenty of error
# messages when compiling main.c.
#
# If you compile under SystemV, set the NCURSES variable to `.'
#
NCURSES=/usr/local/include
ifeq ($(wildcard /usr/include/ncurses), /usr/include/ncurses)
NCURSES=/usr/include/ncurses
endif

# 
# The directory where the libncurses.a file resides if not in the
# standard
#
LIBPATH=/usr/local/lib

ALLFLAGS=$(CFLAGS) -I$(NCURSES) $(MOUINC) $(COPTS) -fwritable-strings \
	 $(VARS) $(USEMOUSE)

# 
# Use V=n for the production version.
# Use V=d for the debugging version.
V=n
#V=d

# ******* User's don't need to modify anything below this point *******

# Rules
.c.o:
	$(CC) $(ALLFLAGS) -c $<

#
# The files that made up the MouseLess Commander
#
OBJS = dir.o util.o main.o screen.o dialog.o key.o input.o menu.o\
       file.o win.o color.o help.o find.o profile.o user.o view.o \
       ext.o mouse.o setup.o $(GNU_OBJS)

LIBS = -ltermcap -L$(LIBPATH) $(MOULIB) $(MOUSELIB)
PROGS = mc

# 
# If you don't have GNU Make, comment out the following lines.
ifeq (Make.local,$(wildcard Make.local))
include Make.local
endif

ifeq ($(shell uname -r), 5.3)
CC=gcc-linux
CPP=gcc-linux -E
NCURSES=/usr/local/lib/gcc-lib/i386-linux-linux/include/ncurses
endif

#
# The dependencies
# If you don't have GNU Make, remove the following lines, then type
# make depend and include the contents of the .depend file at the
# end of this Makefile.
#

ifneq (.depend,$(wildcard .depend))
all: depend
endif

all: $(PROGS)

mc: $(OBJS)
	$(CC) $(ALLFLAGS) $(OBJS) $(LDFLAGS) -o mc $(LIBS) -l$(V)curses

ncl: $(OBJS)
	$(CC) $(ALLFLAGS) $(OBJS) $(LDFLAGS) -o ~/mc $(LIBS) -l$(V)curses
	
#
# Debugging target
mcd: $(OBJS)
	$(CC) $(ALLFLAGS) $(OBJS) -o mcd $(LIBS) -ldcurses -DTRACE


depend dep:
	$(CPP) -M -I$(NCURSES) $(VARS) *.c > .depend

install: mc 
	-mkdir -p $(bindir)
	-mkdir -p $(libdir)
	-mkdir -p $(mandir)
	install mc $(bindir)
	install mc.hlp $(libdir)
	install mc.1 $(mandir)
	install mc.ext $(libdir)
	install mc.menu $(libdir)

clean: 
	rm -f *.o 
	rm -f a.out core mc nc

reallyclean: clean
	rm -f .depend
	rm -f TAGS
	rm -f *~

dist: mc.hlp
	-mkdir ../mc-$(VERSION)
	cp *.c *.h README Makefile COPYING TODO mc.hlp xnc.hlp \
	INSTALL mc.1 ChangeLog NEWS mc.menu mc.ext man2hlp.pl \
	gindex.pl xnc.hlp lsm ../mc-$(VERSION)
	(cd ..; tar cvf - mc-$(VERSION) | gzip -f9 > mc-$(VERSION).tar.gz) 

mc.hlp: ync.hlp xnc.hlp gindex.pl
	cat ync.hlp xnc.hlp | ./gindex.pl > mc.hlp

ync.hlp: mc.1 man2hlp.pl
	./man2hlp.pl mc.1 | fmt -58 > ync.hlp

#
# Include dependencies.
#
# If you don't have GNU Make, then append the contents of the .depend 
# file here and comment out the following three lines.
ifeq (.depend,$(wildcard .depend))
include .depend
endif
