# Text Help Library Makefile for DJGPP cross-compilation
#
# Builds texthelp.lib -- shared text editing infrastructure
# (clipboard, multi-click, word boundaries, single-line editing engine).

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. -I../core -I../core/platform -I../tasks -I../core/thirdparty

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

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

.PHONY: all clean

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

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

$(TARGET): $(OBJS) | $(LIBSDIR)
	$(DXE3GEN) -o $(LIBSDIR)/texthelp.dxe -E _clipboard -E _clearOther -E _isWordChar -E _multiClick -E _widgetText -E _wordStart -E _wordEnd -U $(OBJS)
	mv $(LIBSDIR)/texthelp.dxe $@

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

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

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

# Dependencies
$(OBJDIR)/textHelp.o: textHelp.c textHelp.h ../core/dvxWidgetPlugin.h ../core/dvxWidget.h ../core/dvxTypes.h ../core/dvxApp.h ../core/dvxDraw.h ../core/dvxWm.h ../core/dvxVideo.h

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