#
# GRX 2.0 Library basis Makefile for DJGPP v1 and DJGPP v2
# Needs GNU Make. Make sure your shell is command.com !
#
.PHONY : clean cleanall

INCDIR= -I. -I./include -I../include

GRX20ST    = ../lib/$(GRX_LIB_SUBDIR)/libgrx20.a
GRX20STdos = $(subst /,\,$(GRX20ST))

OX=.o
OP=

include ./stdobjs.mak

# DJGPP v1 ar fails on very long command lines.
# Keep things a little smaller when building the lib ...
STD_Oa= $(STD_1) $(STD_2)  $(STD_3)  $(STD_4) $(STD_5) $(STD_6)
STD_Ob= $(STD_7) $(STD_8) $(STD_9) $(STD_10) $(STD_11) $(STD_12)

ADDON_O=
ifdef DEBUG
 ADDON_O += utils/dbgprint.o
endif

ifeq ($(HAVE_LIBTIFF),y)
  ADDON_O += ../addons/ctx2tiff.o
endif

ifeq ($(HAVE_LIBJPEG),y)
  ADDON_O += ../addons/ctx2jpeg.o
endif

ifeq ($(INCLUDE_PRINTING_CODE),y)
  ADDON_O += ../addons/print/grxprint.o \
	     ../addons/print/prndata.o
  INCDIR += -I../addons/print
endif

ifeq ($(INCLUDE_BMP_CODE),y)
  ADDON_O += ../addons/bmp/bmp.o
  INCDIR  += -I../addons/bmp
endif

DJ_O=   $(ADDON_O)              \
	fdrivers/egavga1.o      \
	fdrivers/ega4.o         \
	fdrivers/herc1.o        \
	fdrivers/lfb16.o        \
	fdrivers/lfb24.o        \
	fdrivers/lfb32h.o       \
	fdrivers/lfb32l.o       \
	fdrivers/lfb8.o         \
	fdrivers/lfbbltrv.o     \
	fdrivers/lfbbltvr.o     \
	fdrivers/lfbbltvv.o     \
	fdrivers/ram24.o        \
	fdrivers/ram32l.o       \
	fdrivers/ram32h.o       \
	fdrivers/svga16.o       \
	fdrivers/svga24.o       \
	fdrivers/svga32h.o      \
	fdrivers/svga32l.o      \
	fdrivers/svga4.o        \
	fdrivers/svga8.o        \
	fdrivers/vga8x.o        \
	mouse/dosinput.o        \
	mouse/doskeys.o         \
	vdrivers/ati28800.o     \
	vdrivers/cl5426.o       \
	vdrivers/et4000.o       \
	vdrivers/herc.o         \
	vdrivers/mach64.o       \
	vdrivers/s3.o           \
	vdrivers/stdega.o       \
	vdrivers/stdvga.o       \
	vdrivers/u_egavga.o     \
	vdrivers/u_vesa.o       \
	vdrivers/u_vsvirt.o     \
	vdrivers/vesa.o

ALL_O = $(STD_Oa) $(STD_Ob) $(DJ_O)

all:    $(GRX20ST) ../bin/vesainfo.exe

clean:
	if exist draw\*.o     del draw\*.o
	if exist fdrivers\*.o del fdrivers\*.o
	if exist fonts\*.o    del fonts\*.o
	if exist image\*.o    del image\*.o
	if exist mouse\*.o    del mouse\*.o
	if exist pattern\*.o  del pattern\*.o
	if exist setup\*.o    del setup\*.o
	if exist shape\*.o    del shape\*.o
	if exist text\*.o     del text\*.o
	if exist user\*.o     del user\*.o
	if exist utils\*.o    del utils\*.o
	if exist vdrivers\*.o del vdrivers\*.o
	if exist wideline\*.o del wideline\*.o
	if exist ..\addons\*.o       del ..\addons\*.o
	if exist ..\addons\print\*.o del ..\addons\print\*.o
	if exist ..\addons\bmp\*.o   del ..\addons\bmp\*.o
	if exist ..\bin\vesainfo.exe del ..\bin\vesainfo.exe
	if exist $(TAG)       del $(TAG)

cleanall: clean
	if exist $(GRX20STdos) del $(GRX20STdos)

dep:
	if exist depend.tmp del depend.tmp
	gcc -MM $(CCOPT) $(INCDIR) $(ALL_O:.o=.c) >depend.tmp
	sed 's#^.*: \(.*\)\.c#\1.o: \1.c#g'   <depend.tmp >depend.dj2
	if exist depend.tmp del depend.tmp

depend.b: depend.new
	sed "s#\.o:#.obj:#g" <depend.new >depend.b
	sed "s#\.o:#.asm:#g" <depend.new >>depend.b

$(GRX20ST): $(TAG) $(ALL_O)
	if exist $(GRX20STdos) del $(GRX20STdos)
	$(AR) -rv $(GRX20ST) $(STD_Oa)
	$(AR) -rv $(GRX20ST) $(STD_Ob)
	$(AR) -rv $(GRX20ST) $(DJ_O)
	$(RANLIB) $(GRX20ST)

../bin/vesainfo.exe: vdrivers/vesainfo.o $(GRX20ST)
	$(CC) -s -o ../bin/vesainfo.exe vdrivers/vesainfo.o $(GRX20ST)
	$(EXE_COMPRESS) ../bin/vesainfo.exe

$(DOS_DJGPP_V1):
	$(MAKE) -f makefile.dj1 clean
	if not exist $(DOS_DJGPP_V1) del $(SYSTEM_TAG_PREFIX).*
	echo DOS_DJGPP_V1_TARGET > $(DOS_DJGPP_V1)

$(DOS_DJGPP_V2):
	$(MAKE) -f makefile.dj2 clean
	if not exist $(DOS_DJGPP_V2) del $(SYSTEM_TAG_PREFIX).*
	echo DOS_DJGPP_V2_TARGET > $(DOS_DJGPP_V2)

$(ALL_O): $(TAG)

$(ALL_O:.o=.i) : %.i : %.c
	$(CC) -E $(CCOPT) $(INCDIR) $*.c > $*.i

$(ALL_O:.o=.dm) : %.dm : %.c
	$(CC) -dM -E $(CCOPT) $(INCDIR) $*.c > $*.dm

.c.s:
	$(CC) -S $(CCOPT) $(INCDIR) $*.c -o $*.s

.c.o:
	$(CC) -c $(CCOPT) $(INCDIR) $*.c -o $*.o

include depend.dj2
