# DVX Shell Makefile for DJGPP cross-compilation
#
# Builds dvxshell.lib -- the shell 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 -I../libdvx -I../libdvx/platform -I../../../widgets/kpunch -I../libtasks -I../libdvx/thirdparty

OBJDIR    = ../../../../obj/shell
LIBSDIR   = ../../../../bin/libs
CONFIGDIR = ../../../../bin/config
THEMEDIR  = ../../../../bin/config/themes
WPAPERDIR = ../../../../bin/config/wpaper

SRCS   = shellMain.c shellApp.c shellInfo.c
OBJS   = $(patsubst %.c,$(OBJDIR)/%.o,$(SRCS))
TARGETDIR = $(LIBSDIR)/kpunch/dvxshell
TARGET    = $(TARGETDIR)/dvxshell.lib

.PHONY: all clean

THEMES = $(THEMEDIR)/geos.thm $(THEMEDIR)/win31.thm $(THEMEDIR)/cde.thm $(THEMEDIR)/hotdog.thm
WPAPERS = $(WPAPERDIR)/blueglow.jpg $(WPAPERDIR)/swoop.jpg $(WPAPERDIR)/triangle.jpg

all: $(TARGET) $(TARGETDIR)/dvxshell.dep $(CONFIGDIR)/DVX.INI $(THEMES) $(WPAPERS)

$(TARGETDIR)/dvxshell.dep: dvxshell.dep | $(TARGETDIR)
	sed 's/$$/\r/' $< > $@

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

$(CONFIGDIR)/DVX.INI: ../../../../config/dvx.ini | $(CONFIGDIR)
	sed 's/$$/\r/' $< > $@

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

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

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

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

$(CONFIGDIR):
	mkdir -p $(CONFIGDIR)

$(THEMEDIR):
	mkdir -p $(THEMEDIR)

$(THEMEDIR)/%.thm: ../../../../config/themes/%.thm | $(THEMEDIR)
	sed 's/$$/\r/' $< > $@

$(WPAPERDIR):
	mkdir -p $(WPAPERDIR)

$(WPAPERDIR)/%.jpg: ../../../../config/wpaper/%.jpg | $(WPAPERDIR)
	cp $< $@

# Dependencies
SHELL_DEPS = shellApp.h ../libdvx/dvxWgt.h ../libdvx/dvxApp.h ../libdvx/dvxTypes.h ../libdvx/platform/dvxPlat.h
$(OBJDIR)/shellMain.o:    shellMain.c $(SHELL_DEPS)
$(OBJDIR)/shellApp.o:     shellApp.c $(SHELL_DEPS)
$(OBJDIR)/shellInfo.o:    shellInfo.c shellInf.h $(SHELL_DEPS)

clean:
	rm -rf $(OBJS) $(TARGET) $(TARGETDIR)/dvxshell.dep $(TARGETDIR)
	rm -rf $(WPAPERDIR) $(THEMEDIR) $(CONFIGDIR)
