# Cooperative Task Switching Library Makefile for DJGPP cross-compilation
#
# Builds libtasks.lib -- the task switching module loaded by the DVX loader.

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 -Werror -Wno-type-limits -Wno-sign-compare -Wno-format-truncation -march=i486 -mtune=i586

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

SRCS   = taskswitch.c
OBJS   = $(patsubst %.c,$(OBJDIR)/%.o,$(SRCS))
TARGETDIR = $(LIBSDIR)/kpunch/libtasks
TARGET    = $(TARGETDIR)/libtasks.lib

.PHONY: all clean

all: $(TARGET)

$(TARGET): $(OBJS) | $(TARGETDIR)
	$(DXE3GEN) -o $(TARGETDIR)/libtasks.dxe -U $(OBJS)
	mv $(TARGETDIR)/libtasks.dxe $@

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

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

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

$(TARGETDIR):
	mkdir -p $(TARGETDIR)

# Dependencies
$(OBJDIR)/taskswitch.o: taskswitch.c taskSwch.h ../libdvx/thirdparty/stb_ds.h

clean:
	rm -rf $(OBJS) $(TARGET) $(TARGETDIR)
