#
# Makefile --
#
#      This file contains the Makefile of the PAPyRUS application.
#
# Copyright (C) 1996-1997  Carlos Nunes - loscar@mime.univ-paris8.fr
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

#
# If you change the INSTALL_LIB variable, you MUST set the PAPYRUS_DIR
# shell variable to the correct value, each time you run PAPyRUS.
#

# Directory for Papyrus libs
INSTALL_LIB = /usr/local/lib

# Directory for Papyrus binary
INSTALL_DIR = /usr/local/bin


CC  = gcc
CCC = g++
CXX = g++

#RES_FILE = Papyrus.ad.fr     # French version of the App defaults
RES_FILE = Papyrus.ad.eng     # English version of the App defaults

#
# Tcl library (7.5 or newer)
#

TCL = -ltcl
TCL_INCLUDE = /usr/include
TCL_LIB = /usr/lib/lib

#
# X11R6 library
#

X11 = -lX11
X11_INCLUDE = /usr/X11R6/include
X11_LIB = /usr/X11R6/lib

#
# Xpm library
#

XPM = -lXpm
XPM_INCLUDE = /usr/X11R6/include
XPM_LIB = /usr/X11R6/lib

#
# Motif 2.0 library
#

XM = -lXm
XM_INCLUDE = /usr/X11R6/include
XM_LIB = /usr/X11R6/lib

FLAGS = -O2 -Wall -ansi -pedantic
#FLAGS = -g -Wall -ansi -pedantic


#########################################################################################
#
# You may not have to change anything after this message.
#
#########################################################################################


CXXDEFINES =  -DHAVE_GUI -I$(TCL_INCLUDE) -I$(XPM_INCLUDE)	\
	      -I$(XM_INCLUDE) -I$(X11_INCLUDE)
CDEFINES   =  -DHAVE_GUI -I$(TCL_INCLUDE) -I$(XPM_INCLUDE)	\
	      -I$(XM_INCLUDE) -I$(X11_INCLUDE)

CXXFLAGS = $(FLAGS) $(CXXDEFINES)
CFLAGS   = $(FLAGS) $(CDEFINES)

LIBS =  -L$(XM_LIB) $(XM) -L$(X11_LIB) -L$(X11_LIB) 		\
	-lXmu -lXt -lSM -lICE -lXext 				\
	-L$(XPM_LIB) $(XPM) -lX11 -L$(TCL_LIB) $(TCL) -lm -ldl


SRCS =	gui/callbacks.c      	gui/menus.c		gui/widgets.c			\
        gui/modify_text.c    	gui/mainWin.c   	gui/dialogs.c			\
	gui/actions.c		gui/init.c		kernel/isfuncs.cc		\
	kernel/attributes.cc	kernel/main.cc		kernel/papyrus_output.cc	\
	kernel/container.cc	kernel/ps_output.cc	kernel/ascii_output.cc		\
	kernel/frame.cc		kernel/cursor.cc	kernel/display.cc		\
	kernel/events.cc   	kernel/page.cc  	kernel/paragraph.cc   		\
	kernel/document.cc   	kernel/line.cc     	kernel/word.cc			\
	kernel/wordSegment.cc	kernel/thePosition.cc	kernel/image.cc			\
	kernel/util.cc									\
	kernel/FontManager/fontManager.cc       	kernel/FontManager/fontFamily.cc\
	kernel/StyleManager/styleManager.cc		kernel/StyleManager/styleItem.cc\
	tcl/tclMain.c		tcl/tclInit.cc		tcl/tclGet.cc			\
	tcl/commandsAM.cc	tcl/commandsNZ.cc					\
	misc/shortcuts.c	misc/parseAFM.c		misc/env.c

OBJS =	gui/callbacks.o      	gui/menus.o		gui/widgets.o			\
        gui/modify_text.o    	gui/mainWin.o   	gui/dialogs.o			\
	gui/actions.o		gui/init.o		kernel/isfuncs.o		\
	kernel/attributes.o	kernel/main.o		kernel/papyrus_output.o		\
	kernel/container.o	kernel/ps_output.o	kernel/ascii_output.o		\
	kernel/frame.o		kernel/cursor.o		kernel/display.o		\
	kernel/events.o   	kernel/page.o  		kernel/paragraph.o   		\
	kernel/document.o   	kernel/line.o     	kernel/word.o			\
	kernel/wordSegment.o	kernel/thePosition.o	kernel/image.o			\
	kernel/util.o									\
	kernel/FontManager/fontManager.o 	      	kernel/FontManager/fontFamily.o \
	kernel/StyleManager/styleManager.o		kernel/StyleManager/styleItem.o \
	tcl/tclMain.o		tcl/tclInit.o		tcl/tclGet.o			\
	tcl/commandsAM.o	tcl/commandsNZ.o					\
	misc/shortcuts.o	misc/parseAFM.o		misc/env.o

INCS =  gui/actions.h		gui/callbacks.h		gui/dialogs.h			\
	gui/globals.h		gui/mainWin.h		gui/menus.h			\
	gui/widgets.h		gui/init.h		gui/modify_text.h		\
	kernel/container.h	kernel/events.h		kernel/marker.h			\
	kernel/line.h		kernel/attributes.h					\
	kernel/cursor.h		kernel/frame.h		kernel/page.h			\
	kernel/word.h		kernel/display.h	kernel/papyrus.h		\
	kernel/globals.h	kernel/paragraph.h	kernel/margin.h			\
	kernel/wordSegment.h	kernel/shape.h		kernel/document.h		\
	kernel/isfuncs.h	kernel/thePosition.h	kernel/image.h			\
	kernel/util.h		kernel/output.h		kernel/FontManager/fontFamily.h	\
	kernel/FontManager/fontManager.h		kernel/StyleManager/styleItem.h	\
	kernel/StyleManager/styleManager.h						\
	tcl/mytcl.h		tcl/tclGet.h		tcl/commands.h			\
	misc/shortcuts.h	misc/parseAFM.h		misc/env.h


all:	bin/papyrus


bin/papyrus: $(OBJS)
	$(CC) -o $@ $+ $(LIBS)

clean:
	\rm -f $(OBJS) *~ *.bak *.BAK bin/papyrus *.ps

install: uninstall bin/papyrus
	mkdir -p -m 755 $(INSTALL_LIB)/Papyrus/examples
	install -m 644 lib/examples/* $(INSTALL_LIB)/Papyrus/examples

	mkdir -p -m 755 $(INSTALL_LIB)/Papyrus/scripts
	install -m 644 lib/scripts/* $(INSTALL_LIB)/Papyrus/scripts

	mkdir -p -m 755 $(INSTALL_LIB)/Papyrus/fonts/afm
	install -m 644 lib/fonts/afm/* $(INSTALL_LIB)/Papyrus/fonts/afm
	mkdir -m 755 $(INSTALL_LIB)/Papyrus/fonts/ps

	mkdir -m 755 $(INSTALL_LIB)/Papyrus/ps
	install -m 644 lib/ps/* $(INSTALL_LIB)/Papyrus/ps

	install -s -m 755 bin/papyrus $(INSTALL_DIR)
	install -m 644 bin/Papyrus.ad.common /usr/X11R6/lib/X11/app-defaults/Papyrus
	cat bin/$(RES_FILE) >> /usr/X11R6/lib/X11/app-defaults/Papyrus

	sed s/auto_mkindex/#auto_mkindex/ $(INSTALL_LIB)/Papyrus/scripts/papyrus-init.tcl \
		> $(INSTALL_LIB)/Papyrus/scripts/papyrus-init.tcl.new
	mv -f $(INSTALL_LIB)/Papyrus/scripts/papyrus-init.tcl.new \
		$(INSTALL_LIB)/Papyrus/scripts/papyrus-init.tcl

	mkdir -m 755 $(INSTALL_LIB)/Papyrus/doc
	install -m644 doc/* $(INSTALL_LIB)/Papyrus/doc


uninstall:
	@\rm -rf $(INSTALL_LIB)/Papyrus
	@\rm -f $(INSTALL_DIR)/papyrus


depend:	
	cp Makefile Makefile.bak
	sed '/^#----- dependences -----/q' Makefile.bak >Makefile
	echo >>Makefile
	$(CXX) $(CXXFLAGS) -M $(SRCS) >>Makefile


#----- dependences -----
