# This file is part of the FreeType project.
#
# It builds the library and test programs for Turbo C under MSDOS, large model.
#
# You will need Borland MAKE.
# Tested with Turbo C v.1.5, v.2.0,  Turbo C++ v.1.0
# Turbo C v.1.0 (May '87) is too old (lack of structure assignment)
#     to compile FreeType.  Update your compiler. ;-)
#
#
# Use this file while in the 'test' directory with the following statement:
#
#   make -farch\msdos\Makefile.TC
#
#
# Debug versions can be obtained (except for TC 1.5) with
#
#   make -DDEBUG -farch\msdos\Makefile.TC

ARCH = arch\msdos
FT_MAKEFILE = $(ARCH)\Makefile.TC

CC = tcc

LIBDIR = ..\lib
INCDIRS = -I$(LIBDIR);$(LIBDIR)\$(ARCH);.;$(LIBDIR)\extend

!if ! $d(DEBUG)
CFLAGS = -ml -A -O -Z -G -a -w-stv -w-sig $(INCDIRS)
LDFLAGS = -ml
!else
# For Turbo C v.1.5, replace the -v option below by -y.
CFLAGS = -v -N -ml -A -w-par -w-use -w-aus -w-stu -w-stv -w-cln -w-sig $(INCDIRS)
LDFLAGS = -v -ml
!endif


# full-screen MSDOS driver
GDRIVER = $(ARCH)\.\gfs_dos.obj

# the line below does not work with these old versions of make...
# GOBJ = $(GSRC:.c=.o)

DISPLAY = display.obj

G1OBJ = gmain.obj blitter.obj $(GDRIVER)
GOBJ = $(DISPLAY) $(G1OBJ)


SRC = arabic.c \
      common.c \
      ftdump.c \
      fterror.c \
      ftlint.c \
      ftmetric.c \
      ftsbit.c \
      ftstring.c \
      ftstrpnm.c \
      ftstrtto.c \
      fttimer.c \
      ftview.c \
      ftzoom.c

OBJ = arabic.obj \
      common.obj \
      ftdump.obj \
      fterror.obj \
      ftlint.obj \
      ftmetric.obj \
      ftsbit.obj \
      ftstring.obj \
      ftstrpnm.obj \
      ftstrtto.obj \
      fttimer.obj \
      ftview.obj \
      ftzoom.obj


.c.obj:
	$(CC) $(CFLAGS) -c -o$* $<


EXEFILES = ftdump.exe \
           fterror.exe \
           ftlint.exe \
           ftmetric.exe \
           ftsbit.exe \
           ftstring.exe \
           ftstrpnm.exe \
           ftstrtto.exe \
           fttimer.exe \
           ftview.exe \
           ftzoom.exe


!if !$d(DEBUG)
# Skipped if DEBUG build
all: freetype $(EXEFILES)

!endif

debug: freetype_debug $(EXEFILES)

freetype:
	cd $(LIBDIR)
	make -f$(FT_MAKEFILE) all
	cd ..\test

freetype_debug:
	cd $(LIBDIR)
	make -f$(FT_MAKEFILE) -DDEBUG debug
	cd ..\test


# Borland C compilers are unable to include <dos.h> in ANSI mode.
# So we have a special rule for this file, to build it outside ANSI.
$(GDRIVER):
	$(CC) $(CFLAGS) -A- -c -o$* $*.c

!if $(__MAKE__) < 0x0300
# Also, Turbo C v.1.5 and v.2.0 are not fully ANSI compliant with regard to
# <time.h>, particularly the clock() function.
# So we use an ugly hack here: a modified version of time.h, with the
# necessary machinery, is included in the arch\msdos directory.
time.h: $(ARCH)\time_tc.h
	copy $(ARCH)\time_tc.h time.h

# Below is the special rule for forcing recompilation of fttimer.obj
# using our <time.h>, without using the rule that is pulled in by
# !include "$(ARCH)\depend.dos" at the end of the Makefile...
fttimer.exe: $(G1OBJ) fttimer.c time.h common.obj $(LIBDIR)\libttf.lib
	$(CC) $(CFLAGS) -c -o$* $*.c
	$(CC) $(LDFLAGS) fttimer.obj $(G1OBJ) common.obj $(LIBDIR)\libttf.lib

!else
# Normal behaviour
fttimer.exe: $(G1OBJ) fttimer.obj common.obj $(LIBDIR)\libttf.lib
	$(CC) $(LDFLAGS) fttimer.obj $(G1OBJ) common.obj $(LIBDIR)\libttf.lib
!endif


# This old gr... make is unable to have a $ variable to name all the
# dependencies. :-(  So the job have to be done by hand...
ftzoom.exe: $(G1OBJ) ftzoom.obj common.obj $(LIBDIR)\libttf.lib
	$(CC) $(LDFLAGS) ftzoom.obj $(G1OBJ) common.obj $(LIBDIR)\libttf.lib

ftview.exe: $(GOBJ) ftview.obj common.obj $(LIBDIR)\libttf.lib
	$(CC) $(LDFLAGS) ftview.obj $(GOBJ) common.obj $(LIBDIR)\libttf.lib

ftstring.exe: $(GOBJ) ftstring.obj common.obj $(LIBDIR)\libttf.lib
	$(CC) $(LDFLAGS) ftstring.obj $(GOBJ) common.obj $(LIBDIR)\libttf.lib

ftstrtto.exe: $(GOBJ) ftstrtto.obj common.obj arabic.obj $(LIBDIR)\libttf.lib
	$(CC) $(LDFLAGS) ftstrtto.obj $(GOBJ) common.obj \
			  arabic.obj $(LIBDIR)\libttf.lib

# fttimer.exe is handled above (because of <time.h> hack)

ftlint.exe: ftlint.obj common.obj $(LIBDIR)\libttf.lib
	$(CC) $(LDFLAGS) ftlint.obj common.obj $(LIBDIR)\libttf.lib

ftdump.exe: ftdump.obj common.obj $(LIBDIR)\libttf.lib
	$(CC) $(LDFLAGS) ftdump.obj common.obj $(LIBDIR)\libttf.lib

ftstrpnm.exe: ftstrpnm.obj common.obj $(LIBDIR)\libttf.lib
	$(CC) $(LDFLAGS) ftstrpnm.obj common.obj $(LIBDIR)\libttf.lib

ftsbit.exe: ftsbit.obj common.obj $(LIBDIR)\libttf.lib
	$(CC) $(LDFLAGS) ftsbit.obj common.obj $(LIBDIR)\libttf.lib

ftmetric.exe: ftmetric.obj common.obj $(LIBDIR)\libttf.lib
	$(CC) $(LDFLAGS) ftmetric.obj common.obj $(LIBDIR)\libttf.lib

fterror.exe: fterror.obj common.obj $(LIBDIR)\libttf.lib
	$(CC) $(LDFLAGS) fterror.obj common.obj $(LIBDIR)\libttf.lib


clean: do_clean
	cd $(LIBDIR)
	make -f$(FT_MAKEFILE) clean
	cd ..\test

distclean: do_clean
	cd $(LIBDIR)
	make -f$(FT_MAKEFILE) distclean
	cd ..\test
	-del *.exe

do_clean:
	-del *.obj
	-del $(ARCH)\*.obj
	del time.h		# clean the ugly hack for Turbo C...

!include "$(ARCH)\depend.dos"

# end of Makefile
