# This file is part of the CJK package Version 4.1.3 (20-Jun-1997)

# GNU Makefile for ttf2pk

.PHONY: default all debug documentation clean depend \
        do_all ttflib ttflib-doc


default:
	@echo " say                                     "
	@echo ".                                        "
	@echo "     make TARGET OS=SYSTEM               "
	@echo ".                                        "
	@echo " SYSTEM can be one of the following:     "
	@echo ".                                        "
	@echo "     unix (gcc)                          "
	@echo "     os2 bound (emx)                     "
	@echo "     dos (djgpp)                         "
	@echo ".                                        "
	@echo " TARGET can be one of the following:     "
	@echo ".                                        "
	@echo "     all debug depend                    "
	@echo "     documentation (needs c2cweb package)"
	@echo "     clean                               "


ifdef OS

  # default values
  FS = UNIX
  CC = gcc -Wall -O
  O = .o
  LIB = -lm
  EXE =
  RM = rm -f
  LIBO = .a

  ifeq ($(OS),os2)
    FS = MSDOS
    CC = gcc -Wall -Zomf -Zmtd -O
    O = .obj
    LIB = ttf2pk.def
    EXE = .exe
    RM = del
    LIBO = .lib
  endif

  ifeq ($(OS),dos)
    FS = MSDOS
    CC = gcc -Wall -O
    O = .o
    LIB =
    EXE = .exe
    RM = del
    LIBO = .a
  endif

  ifeq ($(OS),bound)
    FS = MSDOS
    CC = gcc -Wall -O
    O = .o
    LIB =
    EXE = .exe
    RM = del
    LIBO = .a
  endif


  SRC = coding.h coding.c ttf2pk.c
  OBJ = coding$O ttf2pk$O


  %$O: %.c
	$(CC) $(CFLAGS) -c -D$(FS) -I./ttflib -o $@ $<

  %.dvi: %.tex
	$(TEX) $*


  all:
	$(MAKE) do_all CFLAGS=-s

  debug:
	$(MAKE) do_all CFLAGS="-Wstrict-prototypes -g -DDEBUG"

  # this builds a .dvi-file using the c2cweb package
  documentation: ttflib-doc ttf2pk.dvi

  # remove the unnecessary files.
  clean:
	$(MAKE) -C ttflib clean
	-$(RM) *$O
	-$(RM) *.cw
	-$(RM) *.hw
	-$(RM) *.tex
	-$(RM) *.scn
	-$(RM) *.toc
	-$(RM) *.idx
	-$(RM) *.log

  # Dependencies.
  depend:
	$(MAKE) -C ttflib clean
	gcc -E -M -I./ttflib *.c > dep.end


  do_all: ttflib ttf2pk$(EXE)

  ttflib:
	$(MAKE) -C ttflib ttflib

  ttf2pk$(EXE): $(OBJ) ttflib/ttflib$(LIBO)
    ifeq ($(OS),dos)
	$(CC) $(CFLAGS) -o $(basename $@) $^
	strip $(basename $@)
	coff2exe $(basename $@)
	-$(RM) $(basename $@)
    else
	$(CC) $(CFLAGS) -o $@ $^ $(LIB)
    endif

  ttflib-doc:
	$(MAKE) -C ttflib ttflib-doc

  ttf2pk.cw: $(SRC) ttf2pk.fmt
	c2cweb -b "The ttf2pk program" -l -v -f ttf2pk.fmt $(SRC)

  ttf2pk.tex: ttf2pk.cw
	$(CWEAVE) +ai $<


  ifeq (dep.end,$(wildcard dep.end))
    include dep.end
  endif

else # ifdef OS

  all debug depend documentation clean: default

endif
