# DVX Core Library Makefile for DJGPP cross-compilation
#
# Builds libdvx.lib -- core GUI infrastructure (draw, compositor,
# window manager, event dispatch, layout engine, widget infrastructure).
# Zero widget implementations -- those are in ../widgets/ as .wgt modules.

DJGPP_PREFIX  = $(HOME)/djgpp/djgpp
CC            = $(DJGPP_PREFIX)/bin/i586-pc-msdosdjgpp-gcc
DXE3GEN       = PATH=$(DJGPP_PREFIX)/bin:$(PATH) DJDIR=$(DJGPP_PREFIX)/i586-pc-msdosdjgpp $(DJGPP_PREFIX)/i586-pc-msdosdjgpp/bin/dxe3gen
CFLAGS        = -O2 -Wall -Wextra -Wno-type-limits -Wno-sign-compare -march=i486 -mtune=i586 -I. -Iplatform -I../tasks -Ithirdparty

OBJDIR  = ../obj/core
LIBSDIR = ../bin/libs

# Core sources
SRCS = dvxVideo.c dvxDraw.c dvxComp.c dvxWm.c dvxImage.c dvxImageWrite.c \
       dvxApp.c dvxDialog.c dvxPrefs.c dvxResource.c \
       widgetClass.c widgetCore.c widgetScrollbar.c \
       widgetLayout.c widgetEvent.c widgetOps.c

OBJS   = $(patsubst %.c,$(OBJDIR)/%.o,$(SRCS))
TARGET = $(LIBSDIR)/libdvx.lib

# libdvx.lib export prefixes
DVX_EXPORTS = -E _dvx -E _wgt -E _wm -E _prefs -E _rect -E _draw -E _pack -E _text \
              -E _setClip -E _resetClip -E _stbi_ -E _stbi_write -E _dirtyList \
              -E _widget \
              -E _sCursor -E _sDbl -E _sDebug -E _sClosed -E _sFocused -E _sKey \
              -E _sOpen -E _sPressed -E _sDrag -E _sDrawing -E _sResize \
              -E _sListView -E _sSplitter -E _sTreeView \
              -E _accelParse -E _clipboard -E _multiClick

.PHONY: all clean

all: $(TARGET) $(LIBSDIR)/libdvx.dep

$(LIBSDIR)/libdvx.dep: ../config/libdvx.dep | $(LIBSDIR)
	sed 's/$$/\r/' $< > $@

$(TARGET): $(OBJS) | $(LIBSDIR)
	$(DXE3GEN) -o $(LIBSDIR)/libdvx.dxe $(DVX_EXPORTS) -U $(OBJS)
	mv $(LIBSDIR)/libdvx.dxe $@

$(OBJDIR)/%.o: %.c | $(OBJDIR)
	$(CC) $(CFLAGS) -c -o $@ $<

$(OBJDIR):
	mkdir -p $(OBJDIR)

$(LIBSDIR):
	mkdir -p $(LIBSDIR)

# Dependencies
CORE_HDRS = dvxTypes.h dvxApp.h dvxDraw.h dvxWm.h dvxVideo.h dvxWidget.h platform/dvxPlatform.h
$(OBJDIR)/dvxVideo.o:      dvxVideo.c dvxVideo.h platform/dvxPlatform.h dvxTypes.h dvxPalette.h
$(OBJDIR)/dvxDraw.o:       dvxDraw.c dvxDraw.h platform/dvxPlatform.h dvxTypes.h
$(OBJDIR)/dvxComp.o:       dvxComp.c dvxComp.h platform/dvxPlatform.h dvxTypes.h
$(OBJDIR)/dvxWm.o:         dvxWm.c dvxWm.h dvxTypes.h dvxDraw.h dvxComp.h dvxVideo.h dvxWidget.h platform/dvxPlatform.h thirdparty/stb_image.h
$(OBJDIR)/dvxImage.o:       dvxImage.c thirdparty/stb_image.h
$(OBJDIR)/dvxImageWrite.o: dvxImageWrite.c thirdparty/stb_image_write.h
$(OBJDIR)/dvxApp.o:        dvxApp.c dvxApp.h platform/dvxPlatform.h dvxTypes.h dvxVideo.h dvxDraw.h dvxComp.h dvxWm.h dvxFont.h dvxCursor.h
$(OBJDIR)/dvxDialog.o:     dvxDialog.c dvxDialog.h platform/dvxPlatform.h dvxApp.h dvxWidget.h dvxWidgetPlugin.h dvxTypes.h dvxDraw.h
$(OBJDIR)/dvxPrefs.o:      dvxPrefs.c dvxPrefs.h

WIDGET_DEPS = dvxWidgetPlugin.h dvxWidget.h dvxTypes.h dvxApp.h dvxDraw.h dvxWm.h dvxVideo.h platform/dvxPlatform.h
$(OBJDIR)/widgetClass.o:     widgetClass.c $(WIDGET_DEPS)
$(OBJDIR)/widgetCore.o:      widgetCore.c $(WIDGET_DEPS)
$(OBJDIR)/widgetScrollbar.o: widgetScrollbar.c $(WIDGET_DEPS)
$(OBJDIR)/widgetLayout.o:    widgetLayout.c $(WIDGET_DEPS)
$(OBJDIR)/widgetEvent.o:     widgetEvent.c $(WIDGET_DEPS)
$(OBJDIR)/widgetOps.o:       widgetOps.c $(WIDGET_DEPS)

clean:
	rm -f $(OBJS) $(TARGET) $(LIBSDIR)/libdvx.dep
