#############################################################################
# mined text editor makefile	- Mac OS X


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

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

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

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


#############################################################################
# system environment adaption

# select library directory
LIBDIR	= /usr/lib${LIB}

# find library with termcap API
# prefer static linking which yields a more portable program in 
# a non-uniform network installation
liblist	= \
	ls /sw/lib/libtermcap.a; \
	ls /sw/lib/libncurses.a; \
	ls $(LIBDIR)/libtermcap.a; \
	ls $(LIBDIR)/libncurses.a; \
	ls $(LIBDIR)/libtermcap.dylib; \
	ls $(LIBDIR)/libncurses.dylib; \


# select first library found from list, replace with -l... if static
firstlib = sed -e "s,\($(LIBDIR).*\)/lib\([^/]*\)\.a,-L\1 -l\2," -e "1 p" -e d
termcap = $(shell ( $(liblist) ) 2> /dev/null | $(firstlib) )

# libtest: target at bottom (must not be first target)


#############################################################################
# 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)
# newer Linux includes the termcap API in the ncurses library:
#SLIB	= -lncurses
SLIB	= $(termcap)

# terminal handling mode 2: sgtty (old, BSD)
#SCREEN	= -DSGTTY
#SLIB	= -ltermcap
# the following was reported to compile better on some BSD system:
#SLIB	= -L/usr/local/lib -lncurses	# includes termcap library

# 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 see separate makefile.curses for options with legacy curses.


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

# select operating system environment
DEFS	= -Dunix -D__USE_BSD


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


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

SCREENOBJ=io.o keyboard.o
MOUSELIB=
KEYMAPSDEP=keymaps/_keymaps.h
include mkinclud.mak


#############################################################################
# test targets

libtest:
	( $(liblist) ) | cat
	echo $(termcap)


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