# GNU Makefile for PDCurses - DOS
#
# Usage: make [-f path\Makefile] [DEBUG=Y] [target]
#
# where target can be any of:
# [all|libs|demos|manual|dist|install|libpdcurses.a|testcurs.exe...]
#
# Target `install' will install the products in the standard places
# for a stock DJGPP installation given by the value of the environment
# variable DJDIR.
# If the user prefers to install in some other directory, he must
# supply a new value for the prefix variable at the command line
# like this:
#   make [-f path\Makefile] install prefix=/some/other/dir

O = o
E = .exe

ifndef PDCURSES_SRCDIR
	PDCURSES_SRCDIR = ..
endif

include $(PDCURSES_SRCDIR)/common/libobjs.mif

osdir		= $(PDCURSES_SRCDIR)/dos

PDCURSES_DOS_H	= $(osdir)/pdcdos.h

prefix		= /dev/env/DJDIR
includedir	= $(prefix)/include
libdir		= $(prefix)/lib
docdir		= $(prefix)/contrib/PDCurses.39
gnudocsdir	= $(prefix)/share/doc/PDCurses.39

CC		= gcc

ifeq ($(DEBUG),Y)
	CFLAGS  = -g -O0 -Wall -DPDCDEBUG
	LDFLAGS = -g
else
	CFLAGS  = -O2 -Wall
	LDFLAGS =
endif

CFLAGS += -I$(PDCURSES_SRCDIR)

LINK		= gcc

LIBEXE		= ar
LIBFLAGS	= rcv

LIBCURSES	= libpdcurses.a
LIBPANEL	= libpanel.a

CP		= /dev/env/DJDIR/bin/cp
RM		= /dev/env/DJDIR/bin/rm
STRIP		= /dev/env/DJDIR/bin/strip
INSTALL		= /dev/env/DJDIR/bin/ginstall

.PHONY: all libs clean demos dist install

all:	libs

libs:	$(LIBCURSES)

clean:
	-$(RM) *.o
	-$(RM) *.a
	-$(RM) *.exe

demos:	$(DEMOS)
ifneq ($(DEBUG),Y)
	strip *.exe
endif

install: $(LIBCURSES)
	$(INSTALL) -d $(includedir)
	$(INSTALL) -d $(libdir)
	$(INSTALL) -d $(docdir)
	$(INSTALL) -d $(docdir)/dos
	$(INSTALL) -d $(gnudocsdir)
	$(INSTALL) $(PDCURSES_SRCDIR)/curses.h $(includedir)
	$(INSTALL) $(PDCURSES_SRCDIR)/panel.h $(includedir)
	$(INSTALL) $(LIBCURSES) $(libdir)
	$(INSTALL) $(LIBPANEL) $(libdir)
	$(INSTALL) $(PDCURSES_SRCDIR)/README.md $(docdir)/README
	$(INSTALL) $(PDCURSES_SRCDIR)/dos/README.md $(docdir)/dos/README
	$(INSTALL) $(PDCURSES_SRCDIR)/docs/HISTORY.md $(docdir)/HISTORY
	$(INSTALL) $(PDCURSES_SRCDIR)/docs/IMPLEMNT.md $(docdir)/IMPLEMNT
	$(INSTALL) $(PDCURSES_SRCDIR)/docs/MANUAL.md $(gnudocsdir)/manual.txt
	$(INSTALL) $(PDCURSES_SRCDIR)/docs/USERS.md $(gnudocsdir)/users.txt

$(LIBCURSES) : $(LIBOBJS) $(PDCOBJS)
	$(LIBEXE) $(LIBFLAGS) $@ $?
	-$(CP) $(LIBCURSES) $(LIBPANEL)

$(LIBOBJS) $(PDCOBJS) : $(PDCURSES_HEADERS)
$(PDCOBJS) : $(PDCURSES_DOS_H)
$(DEMOS) : $(PDCURSES_CURSES_H) $(LIBCURSES)
panel.o : $(PANEL_HEADER)

$(LIBOBJS) : %.o: $(srcdir)/%.c
	$(CC) -c $(CFLAGS) $<

$(PDCOBJS) : %.o: $(osdir)/%.c
	$(CC) -c $(CFLAGS) $<

firework.exe ozdemo.exe rain.exe testcurs.exe worm.exe xmas.exe \
ptest.exe: %.exe: $(demodir)/%.c
	$(CC) $(CFLAGS) -o$@ $< $(LIBCURSES)

tuidemo.exe: tuidemo.o tui.o
	$(LINK) $(LDFLAGS) -o$@ tuidemo.o tui.o $(LIBCURSES)

tui.o: $(demodir)/tui.c $(demodir)/tui.h $(PDCURSES_CURSES_H)
	$(CC) -c $(CFLAGS) -I$(demodir) -o$@ $<

tuidemo.o: $(demodir)/tuidemo.c $(PDCURSES_CURSES_H)
	$(CC) -c $(CFLAGS) -I$(demodir) -o$@ $<
