# Makefile for PDCurses library for SDL for MinGW
#
# Usage: [g]make -f Makefile.mng [DEBUG=Y] [WIDE=Y] [UTF8=Y] [target]
#
# where target can be any of:
# [all|demos|libpdcurses.a|testcurs]...

O = o
RM = rm

ifndef PDCURSES_SRCDIR
	PDCURSES_SRCDIR	= ..
endif

include $(PDCURSES_SRCDIR)/libobjs.mif

osdir		= $(PDCURSES_SRCDIR)/sdl1

PDCURSES_SDL_H	= $(osdir)/pdcsdl.h

SLIBS		= -lSDL

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

ifeq ($(WIDE),Y)
        CFLAGS  += -DPDC_WIDE
        SLIBS   += -lSDL_ttf
endif

ifeq ($(UTF8),Y)
        CFLAGS  += -DPDC_FORCE_UTF8
endif

ifdef CHTYPE_32
	CFLAGS += -DCHTYPE_32
endif

ifdef CHTYPE_16
	CFLAGS += -DCHTYPE_16
endif

CC		= gcc
BUILD		= $(CC) $(CFLAGS) -I$(PDCURSES_SRCDIR)
LDFLAGS		= -mwindows $(LIBCURSES)

ifeq ($(DLL),Y)
	BUILD += -DPDC_DLL_BUILD
	LIBFLAGS = -Wl,--out-implib,libpdcurses.a -shared -o
	LIBCURSES = pdcurses.dll
	CLEAN = $(LIBCURSES) *.a
	POST = $(SLIBS)
else
	LIBEXE = ar
	LIBFLAGS = rcv
	LIBCURSES = libpdcurses.a
	CLEAN = *.a
	LDFLAGS += $(SLIBS)
endif

DEMOS += sdltest.exe

.PHONY: all libs clean demos

all:	libs demos

libs:	$(LIBCURSES)

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

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

$(LIBCURSES) : $(LIBOBJS) $(PDCOBJS)
	$(LIBEXE) $(LIBFLAGS) $@ $? $(POST)

$(LIBOBJS) $(PDCOBJS) : $(PDCURSES_HEADERS)
$(PDCOBJS) : $(PDCURSES_SDL_H)
$(DEMOS) : $(PDCURSES_CURSES_H) $(LIBCURSES)
tui.o tuidemo.o : $(PDCURSES_CURSES_H)
terminfo.o: $(TERM_HEADER)
panel.o ptest.exe: $(PANEL_HEADER)

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

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

firework.exe ozdemo.exe newtest.exe rain.exe testcurs.exe worm.exe xmas.exe \
ptest.exe: %.exe: $(demodir)/%.c
	$(BUILD) -o $@ $< $(LDFLAGS)

sdltest.exe: $(osdir)/sdltest.c
	$(BUILD) -o $@ $< -mwindows $(LIBCURSES) -lmingw32 -lSDLmain -lSDL

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

tui.o: $(demodir)/tui.c $(demodir)/tui.h
	$(BUILD) -c $<

tuidemo.o: $(demodir)/tuidemo.c $(demodir)/tui.h
	$(BUILD) -c $<
