# DVX Shell Applications Makefile  -- builds DXE3 modules

DJGPP_PREFIX  = $(HOME)/djgpp/djgpp
DJGPP_LIBPATH = $(HOME)/claude/windriver/tools/lib
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../core -I../core/platform -I../core/thirdparty -I../widgets -I../tasks -I../core/thirdparty -I../shell

OBJDIR = ../obj/apps
BINDIR = ../bin/apps
DVXRES = ../bin/dvxres

# App definitions: each is a subdir with a single .c file
APPS = progman notepad clock dvxdemo cpanel imgview

.PHONY: all clean $(APPS) dvxbasic

all: $(APPS) dvxbasic

dvxbasic:
	$(MAKE) -C dvxbasic

cpanel: $(BINDIR)/cpanel/cpanel.app
imgview: $(BINDIR)/imgview/imgview.app
progman: $(BINDIR)/progman/progman.app
notepad: $(BINDIR)/notepad/notepad.app
clock: $(BINDIR)/clock/clock.app
dvxdemo: $(BINDIR)/dvxdemo/dvxdemo.app

$(BINDIR)/cpanel/cpanel.app: $(OBJDIR)/cpanel.o cpanel/cpanel.res cpanel/icon32.bmp | $(BINDIR)/cpanel
	$(DXE3GEN) -o $@ -E _appDescriptor -E _appMain -U $<
	$(DVXRES) build $@ cpanel/cpanel.res

$(BINDIR)/imgview/imgview.app: $(OBJDIR)/imgview.o imgview/imgview.res imgview/icon32.bmp | $(BINDIR)/imgview
	$(DXE3GEN) -o $@ -E _appDescriptor -E _appMain -U $<
	$(DVXRES) build $@ imgview/imgview.res

$(BINDIR)/progman/progman.app: $(OBJDIR)/progman.o | $(BINDIR)/progman
	$(DXE3GEN) -o $@ -E _appDescriptor -E _appMain -U $<

$(BINDIR)/notepad/notepad.app: $(OBJDIR)/notepad.o notepad/notepad.res notepad/icon32.bmp | $(BINDIR)/notepad
	$(DXE3GEN) -o $@ -E _appDescriptor -E _appMain -U $<
	$(DVXRES) build $@ notepad/notepad.res

$(BINDIR)/clock/clock.app: $(OBJDIR)/clock.o clock/clock.res clock/icon32.bmp | $(BINDIR)/clock
	$(DXE3GEN) -o $@ -E _appDescriptor -E _appMain -E _appShutdown -U $<
	$(DVXRES) build $@ clock/clock.res

DVXDEMO_BMPS = logo.bmp new.bmp open.bmp sample.bmp save.bmp

$(BINDIR)/dvxdemo/dvxdemo.app: $(OBJDIR)/dvxdemo.o $(addprefix dvxdemo/,$(DVXDEMO_BMPS)) dvxdemo/dvxdemo.res dvxdemo/icon32.bmp | $(BINDIR)/dvxdemo
	$(DXE3GEN) -o $@ -E _appDescriptor -E _appMain -U $<
	$(DVXRES) build $@ dvxdemo/dvxdemo.res
	cp $(addprefix dvxdemo/,$(DVXDEMO_BMPS)) $(BINDIR)/dvxdemo/

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

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

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

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

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

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

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

$(BINDIR)/cpanel:
	mkdir -p $(BINDIR)/cpanel

$(BINDIR)/imgview:
	mkdir -p $(BINDIR)/imgview

$(BINDIR)/progman:
	mkdir -p $(BINDIR)/progman

$(BINDIR)/notepad:
	mkdir -p $(BINDIR)/notepad

$(BINDIR)/clock:
	mkdir -p $(BINDIR)/clock

$(BINDIR)/dvxdemo:
	mkdir -p $(BINDIR)/dvxdemo

# Dependencies
$(OBJDIR)/imgview.o: imgview/imgview.c ../core/dvxApp.h ../core/dvxDialog.h ../core/dvxWidget.h ../core/dvxWm.h ../core/dvxVideo.h ../shell/shellApp.h
$(OBJDIR)/cpanel.o: cpanel/cpanel.c ../core/dvxApp.h ../core/dvxDialog.h ../core/dvxPrefs.h ../core/dvxWidget.h ../core/dvxWm.h ../core/platform/dvxPlatform.h ../shell/shellApp.h
$(OBJDIR)/progman.o: progman/progman.c ../core/dvxApp.h ../core/dvxDialog.h ../core/dvxWidget.h ../core/dvxWm.h ../shell/shellApp.h ../shell/shellInfo.h
$(OBJDIR)/notepad.o: notepad/notepad.c ../core/dvxApp.h ../core/dvxDialog.h ../core/dvxWidget.h ../core/dvxWm.h ../shell/shellApp.h
$(OBJDIR)/clock.o:   clock/clock.c ../core/dvxApp.h ../core/dvxWidget.h ../core/dvxDraw.h ../core/dvxVideo.h ../shell/shellApp.h ../tasks/taskswitch.h
$(OBJDIR)/dvxdemo.o: dvxdemo/dvxdemo.c ../core/dvxApp.h ../core/dvxDialog.h ../core/dvxWidget.h ../core/dvxWm.h ../core/dvxVideo.h ../shell/shellApp.h

clean:
	rm -f $(OBJDIR)/cpanel.o $(OBJDIR)/imgview.o $(OBJDIR)/progman.o $(OBJDIR)/notepad.o $(OBJDIR)/clock.o $(OBJDIR)/dvxdemo.o
	rm -f $(BINDIR)/cpanel/cpanel.app
	rm -f $(BINDIR)/imgview/imgview.app
	rm -f $(BINDIR)/progman/progman.app
	rm -f $(BINDIR)/notepad/notepad.app
	rm -f $(BINDIR)/clock/clock.app
	rm -f $(BINDIR)/dvxdemo/dvxdemo.app $(addprefix $(BINDIR)/dvxdemo/,$(DVXDEMO_BMPS))
	$(MAKE) -C dvxbasic clean
