#  -*- makefile -*-
# makefile for easy build-tree manipulation
#

### paths

TEXDIR = /mit/tex
SRC = $(TEXDIR)/src
BLD = $(TEXDIR)/.build.
SYSBLD = $(TEXDIR)/build

WEB = web2c-5.851d
WEB_TARGET =

DVIPS = dvips
DVIPS_TARGET =

### random programs

RM = rm -f
RM_RF = rm -rf
MKDIR = mkdir
SYNCTREE = /usr/athena/etc/synctree
MAKE = make
CP = cp
CONFIGURE = ./configure --prefix=$(TEXDIR)
SYS = fs sys | sed -e "s/^[^']*'//;s/'//g"

### system-dependent details

SUN=sun4m_51
DEC=pmax_ul4
IBM=rs_aix32

SUN_CC = /mit/sunsoft/sun4bin/cc
SUN_CFLAGS = "-Xc -g -O -Bdynamic"
DEC_CC = cc
DEC_CFLAGS = "-g3 -O1"
IBM_CC = gcc
IBM_CFLAGS = "-Wall -g -O2"

SUN_DOPTS= CC=/mit/sunsoft/sun4bin/cc OPT="-Xc -g -O -Bdynamic" \
  SYS="-DSYSV -DHAVE_GETCWD"
IBM_DOPTS= SYS=-DIBM6000
DEC_DOPTS= OPT=-O2

### default

DONTUSE:
	echo Please specify a real target name.

### build tree management

$(SUN).prune:
	$(RM_RF) $(BLD)$(SUN)
	$(MKDIR) $(BLD)$(SUN)
$(DEC).prune:
	$(RM_RF) $(BLD)$(DEC)
	$(MKDIR) $(BLD)$(DEC)
$(IBM).prune:
	$(RM_RF) $(BLD)$(IBM)
	$(MKDIR) $(BLD)$(IBM)
prune: DONTUSE

$(SUN).sync:
	$(SYNCTREE) -s $(SRC) -d $(BLD)$(SUN)
$(DEC).sync:
	$(SYNCTREE) -s $(SRC) -d $(BLD)$(DEC)
$(IBM).sync:
	$(SYNCTREE) -s $(SRC) -d $(BLD)$(IBM)
	$(CP) $(SRC)/random/math.h.rsaix $(BLD)$(IBM)/$(WEB)/lib/math.h
sync:
	make `$(SYS)`.sync

$(SUN).new-tree:  $(SUN).prune $(SUN).sync
$(DEC).new-tree:  $(DEC).prune $(DEC).sync
$(IBM).new-tree:  $(IBM).prune $(IBM).sync
new-tree: DONTUSE

### building WEB stuff (TeX, MF, etc.)

$(SUN).web.conf:
	CC=$(SUN_CC); export CC; CFLAGS=$(SUN_CFLAGS); export CFLAGS; \
	cd $(BLD)$(SUN)/$(WEB); $(CONFIGURE)
$(DEC).web.conf:
	CC=$(DEC_CC); export CC; CFLAGS=$(DEC_CFLAGS); export CFLAGS; \
	cd $(BLD)$(DEC)/$(WEB); $(CONFIGURE)
$(IBM).web.conf:
	CC=$(IBM_CC); export CC; CFLAGS=$(IBM_CFLAGS); export CFLAGS; \
	cd $(BLD)$(IBM)/$(WEB); $(CONFIGURE)
web.conf:
	make `$(SYS)`.web.conf

web.make:
	cd $(SYSBLD)/$(WEB); $(MAKE) $(WEB_TARGET)
web.build:  web.conf web.make

### dvips and related stuff

$(SUN).dvips.build:
	cd $(SYSBLD)/$(DVIPS); $(MAKE) $(DVIPS_TARGET) $(SUN_DOPTS)
$(IBM).dvips.build:
	cd $(SYSBLD)/$(DVIPS); $(MAKE) $(DVIPS_TARGET) $(IBM_DOPTS)
$(DEC).dvips.build:
	cd $(SYSBLD)/$(DVIPS); $(MAKE) $(DVIPS_TARGET) $(DEC_DOPTS)
dvips.build:
	make `$(SYS)`.dvips.build

### installing dvips TFM and VF files for PostScript fonts

dvips.fonts.install:
	cp /mit/tex/src/PStfms/* /mit/tex/lib/tex/fonts/tfm
	cp /mit/tex/src/PSvfs/* /mit/tex/lib/tex/fonts/vf
