# This Makefile is part of the CJK package for LaTeX2e.
#
# $Id: Makefile,v 1.10 1997/06/24 07:56:01 d791013 Exp $
#
# GNU Makefile for NTU2CJK v1.6 which produces CJK .pfb fonts and .tfm files
# from NTU TrueType fonts.
#
# $Log: Makefile,v $
# Revision 1.10  1997/06/24 07:56:01  d791013
# * Makefile: support for 'pmC' encoding.
#
# Revision 1.9  1997/05/12 09:41:22  d791013
# * Adaptation for capable of downloading partial Type1 fonts for
#   dvips 5.66 or higher.
#
# Revision 1.8  1997/03/05 09:13:00  d791013
# * merged from ntu2cjk in CJK-4_1.2
#
# Revision 1.7  1997/02/10 06:09:39  d791013
# * Added a new variable SRCTOPS to Makefile, which can be assigned to
#   the script generating from source font data to postscript font in
#   text format.
#
# Revision 1.6  1996/11/22 10:43:20  d791013
# * Merged in changes from CJK-4_1.0
#
# Revision 1.5  1996/10/23 03:59:39  d791013
# RCS-to-CVS check in.
#

REVISION= 1.8

SRCS	= ntu2cjk.c t1asm.c t1binary.c vmmodify.c mkmap.c \
	  chr2ps.c myopen.c myerror.c mymalloc.c \
	  chr2ps.h defines.h myopen.h myerror.h mymalloc.h
EXES	= $(SRCS:.c=.exe)
SCRIPTS = ntu2ps getafm vmusage download jack2ps
BATS	= rm.bat $(addsuffix .bat,$(SCRIPTS))
CMDS	= rm.cmd $(addsuffix .cmd,$(SCRIPTS))
PSES	= getafm.ps printafm.ps vmusage.ps exitserv.ps reset.ps kai2chr.ps
FDs	= $(wildcard C00*.fd) $(wildcard C00*.fdx)
MAKs    = fs.mak jack.mak kai.mak ming.mak yuanbold.mak \
	  hei.mak jixi.mak li.mak yuan.mak
MISC	= History Makefile README READMEb5.tex README.jac kaisu.ofs gen_map

PACKSRCS= $(SRCS) $(SCRIPTS) $(BATS) $(CMDS) $(PSES) $(FDs) $(MISC) $(MAKs)
PACKALL = $(PACKSRCS) $(EXES)

default:
	@echo "Say                                             "
	@echo "                                                "
	@echo "    make TARGET [FONTMAK] [PLANES]              "
	@echo "                                                "
	@echo "where TARGET can be one of the following:       "
	@echo "  unix unixdebug                                "
	@echo "  os2 bound bounddebug                          "
	@echo "  dos dosdebug                                  "
	@echo "  install-fonts install-maps install            "
	@echo "  clean realclean                               "
	@echo "                                                "
	@echo "FONTMAK should be assigned to a font-related    "
	@echo "  makefile. E.g. FONTMAK=kai.mak to generate    "
	@echo "  Kai fonts. If omitted, defaults to kai.mak.   "
	@echo "                                                "
	@echo "PLANES is optional and can e.g. be set as:      "
	@echo "  PLANES=\"01 02 03\"                             "
	@echo "for processing only subfonts 01, 02, 03.        "
	@echo "                                                "
	@echo "For more information see the README file.       "


# default font-related makefile
FONTMAK = kai.mak
# here we assume that the basename of the font specific makefile is the
# font family name.
FAMILY = $(basename $(notdir $(FONTMAK)))

# include font specific makefile
include $(FONTMAK)

# this error message will be printed if user-def.mak does not exist.
ifeq ($(MAKELEVEL),0)
$(FONTMAK):
	@echo "                                                          "
	@echo "!! -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= !!"
	@echo "!! Please specify a font specific makefile first.       !!"
	@echo "!! e.g. defining FONTMAK=kai.mak to generate Kai fonts. !!"
	@echo "!!             See kai.mak for an example.              !!"
	@echo "!! -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= !!"
	@echo "                                                          "
	@exit 1
endif

.SUFFIXES:
.PHONY: default all install install-fonts install-maps clean \
	unix unixdebug os2 bound bounddebug dos dosdebug \
	realclean allclean \
	chk_fontmaps generate_maps


# Font maps:
#   GS Fontmap
GSFONTMAP = Fontmap

#   DVIPS fontmap. This fontmap contains only CJK PS fonts. This Makefile 
#   will create a file named config.CJK which contains the line 
#   "p +$(PSFONTMAP)" only (the variable must be replaced with your input)
#   and when installed it will be placed into the same directory where
#   config.ps resides. You should add the command line option "-P CJK" 
#   when running the dvips.
#   You could also insert that line to config.ps . 
PSFONTMAP = CJK.map

CJKFONTS     = $(addprefix $(FONTFL),$(PLANES))
PSFONTS      = $(addsuffix .ps,$(CJKFONTS))
PFBS	     = $(addsuffix .pfb,$(CJKFONTS))
PFAS	     = $(addsuffix .pfa,$(CJKFONTS))
AFMS	     = $(addsuffix .afm,$(CJKFONTS))
TFMS	     = $(addsuffix .tfm,$(CJKFONTS))
ifeq ($(EXTENDED_FONTS),YES)
xTFMS	     = $(addsuffix .tfm,$(addprefix $(FONTxFL),$(PLANES)))
endif

FONTF	     = $(basename $@)
PLANE	     = $(subst $(FONTFL),,$(FONTF))
FONTFILE     = $(FONTFL)$(PLANE)
ifeq ($(EXTENDED_FONTS),YES)
FONTxFILE    = $(FONTxFL)$(PLANE)
endif
CJKFONTNAME  = $(FONTNAME)$(PLANE)


# for UNIX systems
unix:
	$(MAKE) all CC='gcc -Wall -O -s' O=.o FS=UNIX

# for UNIX debugging
unixdebug:
	$(MAKE) all CC='gcc -Wall -O -g' O=.o FS=UNIX

# for OS/2 only (using emx-gcc)
os2:
	$(MAKE) all CC='gcc -Wall -Zomf -Zmtd -O -s' \
		    O=.obj EXE=.exe FS=MSDOS LIB=librx.a

# for OS/2 and DOS (using emx-gcc)
bound:
	$(MAKE) all CC='gcc -Wall -O -s' \
		    O=.o EXE=.exe FS=MSDOS LIB=librx.a

# for OS/2 and DOS debugging (using emx-gcc)
bounddebug:
	$(MAKE) all CC='gcc -Wall -O -g' \
		    O=.o EXE=.exe FS=MSDOS LIB=librx.a

# for DOS (using djgpp)
dos:
	$(MAKE) all CC='gcc -Wall -O -s' O=.ooo EXE=.exe FS=MSDOS

# for DOS debugging (using djgpp)
dosdebug:
	$(MAKE) all CC='gcc -Wall -O -g' O=.ooo EXE=.exe FS=MSDOS


all: chk_fontmaps $(TFMS)


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

%.exe: %.ooo
	$(CC) $(CFLAGS) -o $* $^ $(LIB)
	strip $*
	coff2exe $*
	-del $*

%.exe: %.obj
	$(CC) $(CFLAGS) -o $@ $^ $(LIB)

%$(EXE): %.o
	$(CC) $(CFLAGS) -o $@ $^ $(LIB)


chk_fontmaps: $(GSFONTMAP) $(PSFONTMAP) config.CJK generate_maps 

$(GSFONTMAP):
	-$(CP) $(GSMAPDIR)/$(GSFONTMAP) .

$(PSFONTMAP):
	-$(CP) $(PSMAPDIR)/$(PSFONTMAP) .

config.CJK:
	@echo p +$(PSFONTMAP) > config.CJK

generate_maps: mkmap$(EXE)
	./mkmap $(PMC) $(DOWNLOAD) -F $(FONTNAME) -f $(FONTFL) \
		-m $(PSFONTMAP) -M $(GSFONTMAP) 
  ifeq ($(EXTENDED_FONTS),YES)
	./mkmap $(PMC) $(DOWNLOAD) -x $(FONTxFL) -F $(FONTNAME) \
		-f $(FONTFL) -m $(PSFONTMAP) 
  endif

chr2ps$(EXE): chr2ps$O myerror$O myopen$O mymalloc$O

$(PSFONTS): chr2ps$(EXE) ntu2cjk$(EXE) t1asm$(EXE) t1binary$(EXE) vmmodify$(EXE)
	-@echo ----------------- Building $(FONTFILE) -------------------
	./$(SRCTOPS) $(FONTSRC) $(PLANE) $(FONTNAME) $(FONTUID) $@

$(PFAS): %.pfa : %.ps vmusage.ps
	./t1asm $< $@
  ifeq ($(VM_MODIFY),YES)
	./vmusage $@
  endif

$(PFBS): %.pfb : %.pfa 
	./t1binary $< $@

$(AFMS): %.afm : %.pfb printafm.ps 
	./getafm $(CJKFONTNAME) $(FONTFILE)

$(TFMS): %.tfm : %.afm
	afm2tfm $<
  ifeq ($(EXTENDED_FONTS),YES)
	afm2tfm $< -e 1.2 $(FONTxFILE)
  endif

# If you have changed some entries in Fontmap by renaming .pfb to .pfa,
# you should install the corresponding .pfa fonts to $(GSFONTDIR) manually.

install: install-fonts install-maps

install-fonts: # $(TFMS) $(PFBS)
	-$(INSTALL) $(FONTFL)??.tfm $(TFMDIR)
	-$(INSTALL) $(FONTFL)??.pfb $(GSFONTDIR)
  ifeq ($(EXTENDED_FONTS),YES)
	-$(INSTALL) $(FONTxFL)??.tfm $(TFMDIR)
	-@echo ""
	-@echo "Don't forget to rename C00$(FAMILY).fdx to C00$(FAMILY).fd and to install it"
	-@echo "the C00$(FAMILY).fd after modification."
  else
	-@echo "Don't forget to install C00$(FAMILY).fd after modification."
  endif

install-maps: $(GSFONTMAP) $(PSFONTMAP)
	-$(INSTALL) $(GSFONTMAP) $(GSMAPDIR)
	-$(INSTALL) $(PSFONTMAP) $(PSMAPDIR)
	-$(INSTALL) config.CJK $(PSMAPDIR)
	-@echo ""
	-@echo "You should add the command line option \"-P CJK\" when running dvips".
	-@echo "You could also insert the file config.CJK to config.ps ." 
	-@echo ""

# Cleaning all produced files except executables.

clean:
	-$(RM) $(FONTFL)??.ps
	-$(RM) $(FONTFL)??.pfa
	-$(RM) $(FONTFL)??.pfb
	-$(RM) $(FONTFL)??.afm
	-$(RM) $(FONTFL)??.tfm
  ifeq ($(EXTENDED_FONTS),YES)
	-$(RM) $(FONTxFL)??.tfm
  endif

# Clean all.

allclean realclean: clean
	-$(RM) *.o *.obj *.ooo *.exe
	-$(RM) ntu2cjk t1asm t1binary vmmodify chr2ps
	-$(RM) $(GSFONTMAP) $(PSFONTMAP) config.CJK

# Packing ntu2cjk as a tar file.

pack: $(PACKSRCS)
	tar -cvf ntu2cjk-$(REVISION).tar $(PACKSRCS)
	gzip -9 ntu2cjk-$(REVISION).tar

### Local Variables:
### mode: makefile
### End:
