# makefile for wp2latex for EMX (gcc)
# runs under DOS, linux, solaris and perhaps OS/2
#

ifeq ($(MAKE),)
MAKE=make
endif


FLAGS=-Wall -I../atoms/include/ -DERROR_HANDLER
CFLAGS= -g -O2 -D_REENTRANT -O2 $(FLAGS)
CXXFLAGS= -g -O2 -fno-rtti -fno-exceptions -D_REENTRANT -DPOINTER_SIZE=32 -O2 $(FLAGS)
LDFLAGS=


OBJ=.o


#### OS autodetection part of makefile ####

ifeq ($(GETTEXT),-D__gettext__)
ifeq ($(OSTYPE),)		#-lintl is no longer needed under linux
LIBS=-lintl
endif 
IGETTEXTOBJ=igettext$(OBJ)
endif

# for Linux - debian
#ifeq ($(OSTYPE),linux-gnu)
#endif

# for Linux - slakware
ifeq ($(OSTYPE),linux)
LIBS+= -lstdc++
endif

# for Linux - Red Hat
ifeq ($(OSTYPE),Linux)
LIBS+= -lstdc++
endif
#end of Linux

# for sun
ifeq ($(OSTYPE),solaris)
LIBS=-lm
endif

ifeq ($(OSTYPE),sunos4)
TARGET_DIR = ../sun/
LIBS=-lm -lstdc++
endif
#end of sun

#for OS/2
ifneq "$(OS2_SHELL)" ""
TARGET_NAME = cpbldr.exe
OSTYPE = os2
LIBS=-s -lstdcpp
endif

#Nothing is an indentifier for DOS? Too bad.
ifeq ($(OSTYPE),)
ifeq ($(HOSTTYPE),iris4d)
OSTYPE = iris4d
LIBS=-lm
else
TARGET_NAME = cpbldr.exe
OSTYPE = dos
endif
endif

# for aix
ifeq ($(OSTYPE),aix)
LIBS=-lm
endif
#end of aix


# Uncomment next line for compile a debugging version of WP2LaTeX
#DEBUG=-DDEBUG -g

CODEPAGES=wp4a.enc wp5.enc wp5_cz.enc wp6.enc 
CODEPAGES+=unicode.enc kam.enc koi8cs.enc
CODEPAGES+=is8859_1.enc is8859_2.enc is8859_3.enc is8859_4.enc is8859_5.enc
CODEPAGES+=cp852.enc cp1250.enc cp1251.enc cp1252.enc cp1253.enc cp1254.enc cp1255.enc
CODEPAGES+=mac_roma.enc

OUTPUTS=charactr.cc_ out_dir/macroman.trn out_dir/mtef.trn out_dir/html.trn out_dir/trn.trn out_dir/cpg.trn


.SUFFIXES: .cc $(OBJ) .exe
.PHONY: all default distclean generic clean


SOURCES=cpbldr$(OBJ) cplib$(OBJ)


######### End of definitions starting compile rules ###########

default: out_dir/trn.trn
#

out_dir:
	mkdir -p $@

.cc$(OBJ):  *.h $(MAKEFILE_LIST)
	g++ $(CXXFLAGS) $(DEBUG) -c $*.cc $(ERROR) -o $*$(OBJ) $(GETTEXT)

$(OBJ).exe: $(MAKEFILE_LIST)
	g++ $(FLAGS) $*$(OBJ) $(LDFLAGS) $(LIBS) $(ERROR)

cpbldr: $(SOURCES) ../atoms/libatoms.a $(MAKEFILE_LIST)
	g++ -o cpbldr $(SOURCES) $(LDFLAGS) ../atoms/libatoms.a

$(OUTPUTS): cpbldr $(CODEPAGES) chars.inf | out_dir
	./cpbldr -dir out_dir

all:     $(OUTPUTS)
#	$(TARGET_NAME) -i test/charactr.wp


clean:
	@echo Operating system is $(OSTYPE)
	rm -f *.exe *$(OBJ) *.o *.obj *.bak *.bkp core cplib cpbldr

distclean: clean
	rm -f *.trn
	rm -f internal.enc
	rm -f charactr.cc_
	rm -f out_dir/*.trn out_dir/*.enc
	cp makefile.gen makefile

generic:
	rm makefile
	cp makefile.gen makefile

../atoms/libatoms.a: ../atoms/*.cc
	$(MAKE) -C ../atoms libatoms.a

cpbldr$(OBJ): cpbldr.cc cplib.cc *.h


