#############################################################################
# mined text editor makefile	- djgpp with curses (no mouse)


#############################################################################
# Where and how to install
# installation root, usually empty
root	= $(INSTALLROOT)

# directories for target "make install"
prefix	= $(root)
bindir	= $(prefix)/bin
hlpdir	= $(prefix)/bin
mandir	= $(prefix)/bin

# directories for target "make localinstall"
lprefix	= $(root)
lbindir	= $(lprefix)/bin
lhlpdir	= $(lprefix)/bin
lmandir	= $(lprefix)/bin

INSTALL = install
#INSTALL = /bin/cp -p


#############################################################################
# compilation target options

# terminal handling mode 1: termio
#SCREEN	= -DTERMIO
# link termcap functions:
#SLIB	= -ltermcap	# usual termcap library
#SLIB	= -L/usr/lib/termcap -ltermcap	# if deprecated (Linux)
#SLIB	= -lcurses	# may work on System V Unix too (Solaris)
#SLIB	= -lncurses	# includes termcap library (Linux)

# terminal handling mode 2: sgtty (old, BSD)
#SCREEN	= -DSGTTY
#SLIB	= -ltermcap

# terminal handling mode 3: curses
# Choose curses only if other options don't work 
# (see doc/compilation for discussion).
# Use target "make minced" to use UTF-8 enabled ncurses (>= 5.4), 
# or try of these experiments for curses with djgpp.
SCREEN	= -DCURSES
##SLIB	= -lcurses -ltermcap	# sometimes both were needed
##SLIB	= -lncurses
#SLIB	= -lpdcur
#SLIB	= -lcurso # -lpano
#SCREEN	= -DCURSES
SLIB	= -lpdcurses	# library should be called "libpdcur.a" on DOS


# select operating system flavour (define sysV if on System V flavour)
#SYSTEM	= -Dunix -DsysV
#SYSTEM	= -Dunix -DsysV -DFDSET
#SYSTEM	= -Dunix
SYSTEM	=

# select operating system environment
#DEFS	= -Dunix
DEFS	= -DFORK


# collection of system parameters for compilation
SYSFLAGS	= $(SCREEN) $(SYSTEM) $(DEFS)


#############################################################################
# link options

# link dynamically
LDOPTS=-d y	# -d n links statically
GLDOPTS=	# -static links statically


#############################################################################
# compiler selection and compiler-specific options
# (source warnings, optimisation and debug)

CC=gcc
include mkinclud.$(CC)

# Redefine CFLAGS to leave out $(GFLAGS) to omit -ansi
# (and the warnings, but this is not the development version anyway)
# Collection of compilation parameters:
CFLAGS	= $(SYSFLAGS) $(OPT) $(DEBUG)


#############################################################################
# make actions

DJDIR=$(dir $(DJGPP))
DJPMODE=$(DJDIR)BIN\PMODSTUB.EXE
PMODE=PMODSTUB.EXE

# default target:
# generate DOS stand-alone version with pmode DPMI module
mined.exe:	mined # $(PMODE)
	echo !!! Check if copy combines $(PMODE) and mined to mined.exe
	echo !!! Otherwise, try "make pmode" or "make pmodecopy" first
	$(COMSPEC) /C copy /B $(PMODE) + mined mined.exe

SCREENOBJ=iocurses.o keycurs.o
MOUSELIB=dosmouse.c
KEYMAPSDEP=
CHARMAPS:=
KEYMAPS:=
include mkinclud.mak


# copy pmode DPMI module from DJGPP directory
pmodecopy:
	$(COMSPEC) /C copy $(DJPMODE) $(PMODE)


# retrieve and unpack pmode package
pmode:	pmode13b.zip
	unzip -jo pmode13b.zip BIN/PMODSTUB.EXE

# retrieve pmode archive
pmode13b.zip:
	wget -N http://www.delorie.com/pub/djgpp/current/v2misc/pmode13b.zip


#############################################################################
# end
