# Watcom WMAKE Makefile for PDCurses library - DOS (16 bit) or DOS/4GW Watcom C/C++ 10.6+
#
# Usage: wmake -f [path/]Makefile.wcc [DEBUG=Y] [MODEL=c|h|l|m|s|f]
#        [CROSS=Y|N] [CHTYPE=[-DCHTYPE_16|-DCHTYPE_32]] [target]
#
# where target can be any of:
# [all|demos|pdcurses.lib|testcurs.exe...]
#
# and MODEL specifies the memory model (16-bit compact/huge/large/medium/
# small, or 32-bit flat)
#
# and CROSS=Y (CROSS=N) means to assume we are (are not) cross-compiling
# (default is to auto-detect)
#
# and CHTYPE is an optional compiler flag to set the size of chtype (default
# is 64 bits)

# Change the memory MODEL here, if desired
!ifndef MODEL
MODEL      = l
!endif

!ifdef %PDCURSES_SRCDIR
PDCURSES_SRCDIR   = $(%PDCURSES_SRCDIR)
!else
PDCURSES_SRCDIR   = ..
!endif

!include $(PDCURSES_SRCDIR)/version.mif

!ifndef CROSS
!ifeq %SHELL /bin/bash
# assume we are cross-compiling
CROSS      = Y
!endif
!ifeq %SHELL /bin/sh
CROSS      = Y
!endif
!ifeq %SHELL /bin/csh
CROSS      = Y
!endif
!ifeq %SHELL /bin/dash
CROSS      = Y
!endif
!endif

osdir      = $(PDCURSES_SRCDIR)/vt
# Open Watcom README strongly recommends setting WATCOM environment variable...
!ifeq CROSS Y
!ifdef %WATCOM
watcomdir   = $(%WATCOM)
!else
watcomdir   = "`which wcc | xargs realpath | xargs dirname`"/..
!endif
!endif

!ifneq MODEL f
CC      = wcc
TARGET      = dos
!else
CC      = wcc386
TARGET      = dos4g
!endif

CFLAGS      = -bt=$(TARGET) -zq -wx -m$(MODEL) -i=$(PDCURSES_SRCDIR)
CFLAGS      += $(CHTYPE) -DDOS
# the README also recommends setting INCLUDE; if absent, we need an extra -i=
!ifndef %INCLUDE
CFLAGS      += -i=$(watcomdir)/h
!endif

!ifeq DEBUG Y
CFLAGS     += -d2 -DPDCDEBUG
LDFLAGS    = D W A op q sys $(TARGET)
!else
CFLAGS     += -oneatx
LDFLAGS      = op q sys $(TARGET)
!ifeq CROSS Y
!ifneq MODEL f
LDFLAGS      += libp $(watcomdir)/lib286/dos\;$(watcomdir)/lib286
!else
LDFLAGS      += libp $(watcomdir)/lib386/dos\;$(watcomdir)/lib386
!endif
!endif
!endif

LIBEXE      = wlib -q -n -t

!include $(PDCURSES_SRCDIR)/watcom.mif

$(LIBCURSES) : $(LIBOBJS) $(PDCOBJS)
   %write wccvt.lrf $(LIBOBJS) $(PDCOBJS)
   $(LIBEXE) $@ @wccvt.lrf
   -$(DEL) wccvt.lrf
   -$(COPY) $(LIBCURSES) panel.lib

!ifneq MODEL f
PLATFORM1   = Watcom C++ 16-bit DOS/VT
PLATFORM2   = Open Watcom 1.6 for 16-bit DOS/VT
ARCNAME      = pdc$(VER)16w
!else
PLATFORM1   = Watcom C++ 32-bit DOS/VT
PLATFORM2   = Open Watcom 1.6 for 32-bit DOS/VT
ARCNAME      = pdc$(VER)32w
!endif

!include $(PDCURSES_SRCDIR)/makedist.mif
