###############################################################################
# libbrlapi - A library providing access to braille terminals for applications.
#
# Copyright (C) 2006-2024 by Dave Mielke <dave@mielke.cc>
#
# libbrlapi comes with ABSOLUTELY NO WARRANTY.
#
# This is free software, placed under the terms of the
# GNU Lesser General Public License, as published by the Free Software
# Foundation; either version 2.1 of the License, or (at your option) any
# later version. Please see the file LICENSE-LGPL for details.
#
# Web Page: http://brltty.app/
#
# This software is maintained by Dave Mielke <dave@mielke.cc>.
###############################################################################

include $(SRC_TOP)bindings.mk

TCLSH = @TCLSH@
TCL_OK = @TCL_OK@
TCL_CPPFLAGS = @TCL_CPPFLAGS@
TCL_LIBS = @TCL_LIBS@
TCL_DIR = @TCL_DIR@

TCL_API_DIR = $(INSTALL_ROOT)$(TCL_DIR)/$(API_NAME)-$(API_RELEASE)
TCL_API_LIB = $(LIB_PFX)$(API_NAME)_tcl.$(LIB_EXT)
TCL_INDEX_SCRIPT = mkindex

all: $(TCL_API_LIB) | make-index-script

$(TCL_API_LIB): bindings.$O | $(API_NAME)
	$(MKLIB:<name>=$(TCL_API_LIB).$(API_VERSION)) $@ bindings.$O $(TCL_LIBS) $(API_LDFLAGS)

PARAMETERS_HEADER = parameters.auto.h
CONSTANTS_HEADERS = $(PARAMETERS_HEADER)

$(CONSTANTS_HEADERS): $(CONSTANTS_DEPENDENCIES)
	$(AWK) -v parametersHeader=$(PARAMETERS_HEADER) $(CONSTANTS_ARGUMENTS)

bindings.$O:
	$(CC) $(TCL_CPPFLAGS) $(LIBCFLAGS) -o $@ -c $(SRC_DIR)/bindings.c

make-index-script:
	echo >$(TCL_INDEX_SCRIPT) 'pkg_mkIndex $(TCL_API_DIR) $(TCL_API_LIB)'

clean::
	-rm -f -- $(TCL_API_LIB) $(TCL_INDEX_SCRIPT)
	-rm -f -- $(CONSTANTS_HEADERS)

install: all
	$(INSTALL_DIRECTORY) $(TCL_API_DIR)
	$(INSTALL_PROGRAM) $(TCL_API_LIB) $(TCL_API_DIR)
	$(TCLSH) ./$(TCL_INDEX_SCRIPT)

uninstall:
	-rm -f $(TCL_API_DIR)/$(TCL_API_LIB)
	-rm -f $(TCL_API_DIR)/pkgIndex.tcl
	-[ -d $(TCL_API_DIR) ] && rmdir $(TCL_API_DIR)

