#
# Makefile for PriMa
#
# Change options accordng to your system
#
.EXPORT_ALL_VARIABLES:
#
### Where to install PriMa 
PREFIX	= /usr
BINDIR	= $(PREFIX)/bin/
MANDIR	= $(PREFIX)/man/man1

#
# You don't need to change anything below if you just want to install
# the precompiled statically linked binary. Following options take
# effect only at compile time. 
#

### Language: currently EN (english) and DE (german) are supported
LANGUAGE	= LANG_EN
#LANGUAGE	= LANG_DE

### Printer description files
### USER_PRINTERFILE: configuration file in users $HOME
### GLOBAL_PRINTERFILE: will be used if USER_PRINTERFILE doesn't exist
USER_PRINTERFILE	= .prima_printer
GLOBAL_PRINTERFILE	= /usr/etc/prima_printer

### Preview command, use ghostview or gv 
PREVIEW_COMMAND	= "ghostview %s"
#PREVIEW_COMMAND = "gv %s"

### TOOLTIPS: use tooltips (bubble help) for help
### You need to install the tooltips package for the xforms library,
### get it from your favourite xforms mirror   
TOOLTIPS	= 1
TT_INC		= -I/usr/local/include
TT_LIBINC	= -L/usr/local/lib
TT_LIB		= -ltooltips

### Forms library 
FORMS_INC 	= -I/usr/local/include
FORMS_LIBINC	= -L/usr/local/lib
FORMS_LIB	= -lforms

### Code optimization
#OPT	= -O
OPT	= -O2 

### Programs
CC		= gcc
INSTALL		= install
LN		= ln -sf
RM		= rm -f
MAKE		= make

########### End of user configration section ####################
INCLUDES 	= $(FORMS_INC) -I. -I/usr/include -I/usr/include/X11
LIBINC		= $(FORMS_LIBINC) -L/usr/lib -L/usr/X11/lib
LIBS		= $(FORMS_LIB) -lX11 -lm
LDFLAGS		= $(LIBINC)

### Static
XFORMS-STATIC	= /usr/local/lib/libforms.a
TT-STATIC	= /usr/local/lib/libtooltips.a
XPM-STATIC	= /usr/X11/lib/libXpm.a
LIBS-STATIC	= $(TT-STATIC) $(XFORMS-STATIC) $(XPM-STATIC) -lX11 -lm

###
OBJECTS	= main.o options.o diverses.o actions.o opt_win.o
HEADER  = main.h language.h version.h
DEFINES	= -DGLOBAL_PRINTERFILE=\"$(GLOBAL_PRINTERFILE)\" \
	-DUSER_PRINTERFILE=\"$(USER_PRINTERFILE)\" \
	-DPREVIEW_COMMAND=\"$(PREVIEW_COMMAND)\" \
	-D$(LANGUAGE)

ifeq ($(LANGUAGE),LANG_EN)
OBJECTS	+= forms_en.o
HEADER	+= forms_en.h
endif

ifeq ($(LANGUAGE),LANG_DE)
OBJECTS	+= forms_de.o
HEADER	+= forms_de.h
endif

ifeq ($(TOOLTIPS), 1)
DEFINES	+= -DTOOLTIPS
INCLUDES += $(TT_INC)
LIBINC	+= $(TT_LIBINC)
LIBS	+= $(TT_LIB)
OBJECTS += tt.o
HEADERS += tt.h
endif

CFLAGS	= $(OPT) $(DEFINES)
APPNAME	= PriMa
PRIMA_INPUT = PriMa.input

#######################################################################
all:
	$(MAKE) $(APPNAME)
	cd tools ; $(MAKE) all

$(APPNAME): $(OBJECTS)
	$(CC) $(LDFLAGS) -o $@ $(OBJECTS) $(LIBS)

.c.o:
	$(CC) -c $(CFLAGS) $(INCLUDES) $*.c

clean:
	$(RM) $(APPNAME)
	$(RM) $(OBJECTS)
	$(RM) *~ *.bak
	cd tools; $(MAKE) clean

allclean:
	$(MAKE) clean
	$(RM) $(APPNAME).static
	cd tools; $(MAKE) allclean

install: all PriMa.man
	$(INSTALL) -s $(APPNAME) $(BINDIR)
	$(INSTALL) prima_printer $(GLOBAL_PRINTERFILE)
	$(INSTALL) PriMa.man $(MANDIR)/$(APPNAME).1
	cd tools; $(MAKE) install

test:	README.ps testme
	/bin/sh ./testme $(APPNAME)

bigtest: README.ps LICENSE testme
	/bin/sh ./testme $(APPNAME) big

###########
static:
	$(MAKE) $(APPNAME).static
	cd tools ; $(MAKE) static

$(APPNAME).static: $(OBJECTS)
	$(CC) $(LDFLAGS) -o $@ $(OBJECTS) $(LIBS-STATIC)

install.static: 
	$(INSTALL) -s $(APPNAME).static $(BINDIR)/$(APPNAME)
	$(INSTALL) prima_printer $(GLOBAL_PRINTERFILE)
	$(INSTALL) PriMa.man $(MANDIR)/$(APPNAME).1
	cd tools; $(MAKE) install.static

test.static: 
	$(LN) $(APPNAME).static $(APPNAME)
	cd tools; $(LN) $(PRIMA_INPUT).static $(PRIMA_INPUT)
	$(MAKE) test
	$(RM) $(APPNAME) tools/$(PRIMA_INPUT)

bigtest.static: 
	$(LN) $(APPNAME).static $(APPNAME)
	cd tools; $(LN) $(PRIMA_INPUT).static $(PRIMA_INPUT)
	$(MAKE) bigtest
	$(RM) $(APPNAME) tools/$(PRIMA_INPUT)
