# Copyright (C) 2007-2008, Gabriel Dos Reis.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
#     - Redistributions of source code must retain the above copyright
#       notice, this list of conditions and the following disclaimer.
#
#     - Redistributions in binary form must reproduce the above copyright
#       notice, this list of conditions and the following disclaimer in
#       the documentation and/or other materials provided with the
#       distribution.
#
#     - Neither the name of The Numerical Algorithms Group Ltd. nor the
#       names of its contributors may be used to endorse or promote products
#       derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


bin_PROGRAMS = htadd$(EXEEXT) hthits$(EXEEXT) ex2ht$(EXEEXT)
ifeq ($(strip $(axiom_use_x)),yes)
bin_PROGRAMS += hypertex$(EXEEXT) spadbuf$(EXEEXT)
endif

# this is where to put the various commands
OUTLIB=	$(axiom_target_libdir)

# this is where the include files live
INC=    $(axiom_src_srcdir)/include

# this is where the hypertex documentation files are
HYPER=$(axiom_target_datadir)/hypertex

HTADD=$(OUTLIB)/htadd

BITMAPS = mouse11.bitmap mouse11.mask sdown3d.bitmap sdown3dpr.bitmap \
	sdown.bitmap sup3d.bitmap sup3dpr.bitmap sup.bitmap ht_icon

SCRIPTS=${OUTLIB}/htsearch ${OUTLIB}/presea

BINFILES= $(addprefix $(OUTLIB)/,$(bin_PROGRAMS))

HEADERS = addfile.h display.h event.h extent.h \
	group.h hterror.h hyper.h initx.h keyin.h lex.h \
	parse.h parse-paste.h parse-types.h scrollbar.h \
	titlebar.h token.h $(axiom_c_macros_h)


build_libdir = $(abs_top_builddir)/src/lib

hypertex_SOURCES = addfile.c cond.c dialog.c display.c event.c extent1.c \
		extent2.c form-ext.c group.c halloc.c hash.c hterror.c \
		htinp.c hyper.c initx.c input.c item.c keyin.c lex.c \
		macro.c mem.c parse.c parse-aux.c parse-input.c \
		parse-paste.c parse-types.c ReadBitmap.c scrollbar.c \
		show-types.c spadint.c titlebar.c

libspad_la = $(axiom_target_libdir)/libspad.la

hypertex_objects = $(hypertex_SOURCES:.c=.lo)
hypertex_LDADD = $(libspad_la)
hypertex_DEPENDENCIES =

htadd_SOURCES = addfile.c halloc.c hash.c htadd.c hterror.c lex.c
htadd_objects = $(htadd_SOURCES:.c=.lo)
htadd_LDADD = $(libspad_la)
htadd_DEPENDENCIES =

spadbuf_SOURCES = spadbuf.c
spadbuf_objects = $(spadbuf_SOURCES:.c=.lo)
spadbuf_LDADD = $(libspad_la)
spadbuf_DEPENDENCIES =

hthits_SOURCES = hthits.c
hthits_objects = $(hthits_SOURCES:.c=.lo)
hthits_LDADD = $(libspad_la)
hthits_DEPENDENCIES =

ex2ht_SOURCES = ex2ht.c
ex2ht_objects = $(ex2ht_SOURCES:.c=.lo)
ex2ht_LDADD = $(libspad_la)
ex2ht_DEPENDENCIES =

subdir = src/hyper/

.PHONY: all all-hyper
.SUFFIXES:
.SUFFIXES: .c .o .h

all: all-ax

all-ax all-hyper: stamp
	@ echo finished $(builddir)

stamp: $(HEADERS) ${BITMAPS} ${SCRIPTS} ${BINFILES} ${HYPER}/pages/ht.db  
	-rm -f stamp
	$(STAMP) stamp

mostclean-local:

clean-local: mostclean-local
	-rm -f $(objects)
	-rm -f $(BINFILES)

distclean-local: clean-local

.PRECIOUS: %.lo %.$(OBJEXT)

%.lo: %.c $(HEADERS)
	$(COMPILE) -o $@ $(CFLAGS) ${CCF} $(axiom_includes) $(AXIOM_X11_CFLAGS) -I. $<

${HYPER}/pages/ht.db: $(HTADD) $(srcdir)/pages/*.ht $(srcdir)/pages/*.pht
	@echo making ${HYPER}/pages from $(axiom_src_srcdir)/pages directory
	@ mkdir -p ${HYPER}/pages
	@ cp -pr $(srcdir)/pages/*.ht ${HYPER}/pages
	@ for A in `ls $(srcdir)/pages/*.pht`; do \
	     sed 's,/doc/viewports/,/share/viewports/,g' $$A \
			> ${HYPER}/pages/`basename $$A`; \
	     done
	@ rm -f ${HYPER}/pages/ht.db ; \
          rm -f ${HYPER}/pages/*~ ; AXIOM=$(AXIOM) \
	  ${HTADD} -s ${HYPER}/pages/*.ht ${HYPER}/pages/*.pht
	@ cp -pr $(srcdir)/bitmaps ${HYPER}
	@ cp -pr $(srcdir)/viewports $(axiom_target_datadir)


${OUTLIB}/htsearch: htsearch
	$(INSTALL_PROGRAM) $< $@

${OUTLIB}/presea: presea
	$(INSTALL_PROGRAM) $< $@

${OUTLIB}/ex2ht$(EXEEXT): $(ex2ht_objects) $(ex2ht_DEPENDENCIES)
	${LINK} -o $@ $(ex2ht_objects) $(ex2ht_LDADD) $(AXIOM_X11_LDFLAGS) -lm

$(OUTLIB)/htadd$(EXEEXT): $(htadd_objects) $(htadd_DEPENDENCIES)
	${LINK} -o $@ $(htadd_objects) $(htadd_LDADD) $(AXIOM_X11_LDFLAGS) -lm

${OUTLIB}/hthits$(EXEEXT): $(hthits_objects) $(hthits_DEPENDENCIES)
	${LINK} -o $@ $(hthits_objects) $(hthits_LDADD) $(AXIOM_X11_LDFLAGS) -lm


$(OUTLIB)/hypertex$(EXEEXT): $(hypertex_objects) $(hypertex_DEPENDENCIES)
	 ${LINK} -o $@ $(hypertex_objects) $(hypertex_LDADD) \
		$(AXIOM_X11_LDFLAGS) -lm

${OUTLIB}/spadbuf$(EXEEXT): $(spadbuf_objects) $(spadbuf_DEPENDENCIES)
	${LINK} -o $@ $(spadbuf_objects) $(spadbuf_LDADD) \
		$(AXIOM_X11_LDFLAGS) -lm