#
#
VERSION=0.8

#
# 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

NC_HLP=-DHELPFILE=\""$(libdir)/nc.hlp"\"
NC_PROFILE=-DPROFILE=\""$(libdir)/nc.ini"\"
NC_MENU=-DMENU=\""$(libdir)/nc.menu"\"
NC_EXT=-DEXT=\""$(libdir)/nc.ext"\"
VARS=$(NC_HLP) $(NC_PROFILE) $(NC_MENU) $(NC_EXT) -DVERSION=\""$(VERSION)"\"

#NC_HLP=-DHELPFILE=\""nc.hlp"\"

#
# 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.
#
NCURSES=/usr/local/include
#NCURSES=/usr/include/ncurses

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

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

# 
# 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 $(GNU_OBJS)

LIBS = -ltermcap -L$(LIBPATH) 
PROGS = nc

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

all: nc

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

#
# Debugging target
ncd: $(OBJS)
	$(CC) $(ALLFLAGS) $(OBJS) -o ncd $(LIBS) -ldcurses -DTRACE


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

install:
	-mkdir $(bindir)
	-mkdir $(libdir)
	-mkdir $(mandir)
	install nc $(bindir)
	install nc.hlp $(libdir)
	install nc.1 $(mandir)
	install nc.ext $(libdir)

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

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

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

nc.hlp: ync.hlp xnc.hlp gindex.pl
	cat ync.hlp xnc.hlp | gindex.pl > nc.hlp

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

caca:
#        mkdir mc-`cat nc/.version`
#	cp nc/*.c nc/*.h nc/README nc/Makefile nc/COPYING nc/TODO 
#	nc/nc nc/nc.hlp mc-`cat nc/.version`
#	tar cvf mc-`cat nc/.version
#	)

#
# 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