OpenWrt Forum Archive

Topic: build Makefile for package anyterm C++ cross browser ajax web terminal

The content of this topic has been archived on 18 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Anyterm is a web-based terminal emulator written in C++:

DESCRIPTION:
The module uses a pseudo-terminal to communicate with a shell or other application,
and includes terminal emulation.

It communicates over http channel with an ajax XmlHttpRequest script in the webbrowser to display a fully functional terminal (ncurses etc).

REQUIREMENTS:
It uses ROTE (a simple C library for VT102 terminal emulation)
the usual libpthread and libiconv.

It also uses some of the Boost C++ libraries (1.34.1), but it currently only needs their header files at compile time and doesn't actually link with any of the libraries at run-time.

FEATURES:
Performance is quite reasonable and SSL can be used to secure the connection.
Only requirement (on client side) for a terminal over web anywhere is a javascript enabled webbrowser.

See running nano in a demo.

I think this would be a great utility to improve the web user interface.

CHANGES:

I created some rudimentary Makefiles to get it ported to Openwrt 8.09:

I) First we need a ROTE VT102 terminal emulation library Makefile:

# 
# Copyright (C) 2006 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
# $Id$


include $(TOPDIR)/rules.mk


PKG_NAME:=rote
PKG_VERSION:=0.2.8
PKG_RELEASE:=1

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=@SF/$(PKG_NAME)
PKG_MD5SUM:=9e5901267d9ed239343f55a54d76e48e


include $(INCLUDE_DIR)/package.mk


define Package/librote
  SECTION:=libs
  CATEGORY:=Libraries
  TITLE:=libROTE VT102 terminal emulation
  DEPENDS:=+uclibc +libncurses
  URL:=http://rote.sourceforge.net/
endef


define Package/librote/description
    ROTE - Our Own Terminal Emulation library:
    ROTE is a simple C library for VT102 terminal emulation. It allows the
    programmer to set up virtual 'screens' and send them data. The virtual
    screens will emulate the behavior of a VT102 terminal, interpreting
    escape sequences, control characters and such. The library supports
    ncurses as well so that you may render the virtual screen to the real
    screen when you need to.
endef


CONFIGURE_ARGS += \
    --sharedstatedir=/var \
    --libdir=/usr/lib \
    --includedir="$(STAGING_DIR)/usr/include" \
    --oldincludedir="$(STAGING_DIR)/usr/include" \


#librote.so.$(ROTE_VERSION): $(OBJECTS)
#        $(CC) $(CFLAGS) -shared -o $@ -Wl,-soname=$(ROTE_SONAME) $(OBJECTS) $(LDFLAGS) $(LIBS)

define Build/Compile
    $(MAKE) -C $(PKG_BUILD_DIR) \
        $(TARGET_CONFIGURE_OPTS) \
        DESTDIR="$(PKG_INSTALL_DIR)" \
        CFLAGS="-g -O2 -Wall -fPIC $(TARGET_CFLAGS)" \
        LDFLAGS="-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib -lutil -lncurses" \
        CPP="$(TARGET_CC)" \
        CPPFLAGS="-I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include"
endef


define Build/InstallDev
    mkdir -p $(1)/usr/include/rote
    rm -f $(1)/usr/include/rote/*.h
    $(CP) $(PKG_BUILD_DIR)/rote.h $(1)/usr/include/rote/
    mkdir -p $(1)/usr/lib
    $(CP) $(PKG_BUILD_DIR)/librote.so.$(PKG_VERSION) $(1)/usr/lib/
    cd $(1)/usr/lib && ln -sf librote.so.$(PKG_VERSION) librote.so
    cd $(1)/usr/lib && ln -sf librote.so.$(PKG_VERSION) librote.so.0
    chmod 755 $(PKG_BUILD_DIR)/rote-config
    mkdir -p $(1)/usr/bin
    cp -p $(PKG_BUILD_DIR)/rote-config $(1)/usr/bin
endef


define Package/librote/install
    $(INSTALL_DIR) $(1)/usr
    $(INSTALL_DIR) $(1)/usr/lib
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/librote.so.$(PKG_VERSION) $(1)/usr/lib/
    cd $(1)/usr/lib && ln -sf librote.so.$(PKG_VERSION) librote.so
    cd $(1)/usr/lib && ln -sf librote.so.$(PKG_VERSION) librote.so.0
endef


$(eval $(call BuildPackage,librote))

II)... next we need the BOOST C++ libraries (1.34.1) header files Makefile for including:

#
# Copyright (C) 2007 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
# $Id$

include $(TOPDIR)/rules.mk

PKG_NAME:=boost
PKG_VERSION:=1_34_1
PKG_RELEASE:=1

PKG_SOURCE:=$(PKG_NAME)_$(PKG_VERSION).tar.bz2
PKG_SOURCE_URL:=@SF/$(PKG_NAME)
PKG_MD5SUM:=2d938467e8a448a2c9763e0a9f8ca7e5

PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)_$(PKG_VERSION)

include $(INCLUDE_DIR)/package.mk

define Package/boost
  SECTION:=libs
  CATEGORY:=Libraries
  TITLE:=BOOST Regular expression library for C++
  URL:=http://www.boost.org/libs/regex/doc/index.html
  DEPENDS:=+uclibcxx
endef

define Package/boost/description
    Part of the Boost C++ Libraries collection.
endef

CONFIGURE_ARGS = \
       --with-libraries=regex \

define Build/Compile
    $(MAKE) -C $(PKG_BUILD_DIR)/libs/regex/build/ \
        -f $(PKG_BUILD_DIR)/libs/regex/build/gcc-shared.mak \
        $(TARGET_CONFIGURE_OPTS) \
        CXX="g++-uc+std" \
        CXXFLAGS="$$$$CXXFLAGS"  \
        LINKER="g++-uc+std -shared"
endef

define Build/InstallDev
    mkdir -p $(1)/usr/include/boost
    rm -rf $(1)/usr/include/boost/*
    $(CP) $(PKG_BUILD_DIR)/boost/* $(1)/usr/include/boost/
endef

define Package/boost/install
    $(INSTALL_DIR) $(1)/usr/lib/
    $(CP) $(PKG_BUILD_DIR)/libs/regex/build/gcc/libboost*.so $(1)/usr/lib
endef

$(eval $(call BuildPackage,boost))

III) ... and finally we could build a Makefile for anyterm:

# 
# Copyright (C) 2006 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
# $Id: $

include $(TOPDIR)/rules.mk

PKG_NAME:=anyterm
PKG_VERSION:=1.1.28
PKG_RELEASE:=1

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tbz2
PKG_SOURCE_URL:=http://anyterm.org/download
PKG_MD5SUM:=552e19a35fbc5123b3ae218533a47d22

include $(INCLUDE_DIR)/package.mk

#  DEPENDS:=+boost  # only headers for compilation no linking

define Package/anyterm
  SECTION:=utils
  CATEGORY:=Utilities
  TITLE:=anyterm: cross browser ajax web terminal anywhere
  DEPENDS:=+librote +libiconv +libpthread +libncurses
  URL:=http://anyterm.org
endef


define Package/anyterm/description
    Anyterm is a web-based terminal emulator.
    Anyterm consists of some Javascript on a web page, 
    an XmlHttpRequest channel on standard ports back to the server,
    and an Apache module. 
    The module uses a pseudo-terminal to communicate with a shell or other application, 
    and includes terminal emulation. Key presses are picked up by the Javscript
    which sends them to the Apache module; changes to the emulated screen are sent 
    from the module to the Javascript which updates its display. 
    Performance is quite reasonable and SSL can be used to secure the connection.
endef


TARGET_CFLAGS += \
    $(rote-config --cflags) \
    -DDISABLE_POSTGRESQL=1 -DDISABLE_IMAGEMAGICK=1 -DDISABLE_RECODE=1

TARGET_CPPFLAGS += \
    -I$(STAGING_DIR)/usr/lib/libiconv/include \
    -I$(STAGING_DIR)/usr/include/rote \
    -I$(STAGING_DIR)/usr/include \
    -I$(STAGING_DIR)/include

TARGET_LDFLAGS += \
    -L$(STAGING_DIR)/usr/lib/libiconv/lib \
    -L$(STAGING_DIR)/usr/lib \
    -L$(STAGING_DIR)/lib -lrote -liconv -lncurses

CPP:="$(TARGET_CC)"


define Build/Compile
    $(MAKE) -C $(PKG_BUILD_DIR)/build anytermd \
        $(TARGET_CONFIGURE_OPTS) \
        CFLAGS="$(TARGET_CFLAGS)" \
        CPPFLAGS="$(TARGET_CPPFLAGS)" \
        LDFLAGS="$(TARGET_LDFLAGS)" \
        DESTDIR="$(PKG_INSTALL_DIR)" \
        CPP="$(TARGET_CC)" \
        ROTE_CONFIG="$(PKG_BUILD_DIR)/usr/bin/rote-config"
endef


define Package/anyterm/install
    $(INSTALL_DIR) $(1)/usr
    $(INSTALL_DIR) $(1)/usr/bin
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/build/anytermd $(1)/usr/bin/anytermd
endef

$(eval $(call BuildPackage,anyterm))

...and some patches for anyterm:

Index: anyterm-1.1.28/common.mk
===================================================================
--- anyterm-1.1.28.orig/common.mk    2009-01-06 22:52:03.000000000 +0100
+++ anyterm-1.1.28/common.mk    2009-01-30 06:49:49.000000000 +0100
@@ -39,7 +39,7 @@
 
 LIBPBE_DIR=../libpbe
 
-CPP_FLAGS=
+CPP_FLAGS=$(CPPFLAGS)
 
 GCC_FLAGS=-pthread
 #GCC_FLAGS=-D_REENTRANT
@@ -48,7 +48,7 @@
 
 CC_COMPILE_FLAGS=$(COMPILE_FLAGS)
 
-LINK_FLAGS=${GCC_FLAGS} ${DEBUG_FLAGS} \
+LINK_FLAGS=${GCC_FLAGS} ${DEBUG_FLAGS} $(LDFLAGS) \
     -lutil
 
 ifeq (${UNAME_S},OpenBSD)
Index: anyterm-1.1.28/libpbe/include/Iconver.hh
===================================================================
--- anyterm-1.1.28.orig/libpbe/include/Iconver.hh    2009-01-30 07:16:47.000000000 +0100
+++ anyterm-1.1.28/libpbe/include/Iconver.hh    2009-01-30 07:16:59.000000000 +0100
@@ -107,7 +107,7 @@
       char* op = reinterpret_cast<char*>(obuf.get());
       size_t on = buf_bytes;
     
-      int rc = iconv(iconverter, &ip, &in, &op, &on);
+      int rc = iconv(iconverter, (const char**) &ip, &in, &op, &on);
       if (rc==-1) {
         if (errno==E2BIG) {
           // Output buffer is full.  We'll go around the loop again.
Index: anyterm-1.1.28/libpbe/common.mk
===================================================================
--- anyterm-1.1.28.orig/libpbe/common.mk    2009-01-30 07:25:59.000000000 +0100
+++ anyterm-1.1.28/libpbe/common.mk    2009-01-30 07:26:28.000000000 +0100
@@ -63,7 +63,7 @@
   PG_INC_FLAGS=
 endif
 
-INC_FLAGS+=$(PG_INC_FLAGS) -I${INCLUDE_DIR}
+INC_FLAGS+=$(PG_INC_FLAGS) -I${INCLUDE_DIR} $(CPPFLAGS)
 
 COMPILE_FLAGS=$(WARN_FLAGS) $(OPTIMISE_FLAGS) $(DEBUG_FLAGS) $(INC_FLAGS) -pthread -fPIC
Index: anyterm-1.1.28/libpbe/src/segv_backtrace.cc
===================================================================
--- anyterm-1.1.28.orig/libpbe/src/segv_backtrace.cc      2008-02-01 23:59:18.000000000 +0100
+++ anyterm-1.1.28/libpbe/src/segv_backtrace.cc   2009-02-05 03:45:00.000000000 +0100
@@ -19,7 +19,7 @@
 #include "segv_backtrace.hh"
 
 // This is available on glibc on Linux; I'm not sure about other platforms.
-#ifdef __linux__
+#ifdef __GLIBC__
 
 #include <execinfo.h>
 #include <signal.h>
Index: anyterm-1.1.28/libpbe/include/ci_string.hh
===================================================================
--- anyterm-1.1.28.orig/libpbe/include/ci_string.hh    2009-02-05 00:20:59.000000000 +0100
+++ anyterm-1.1.28/libpbe/include/ci_string.hh    2009-02-05 00:21:31.000000000 +0100
@@ -19,8 +19,8 @@
 #define libpbe_ci_string_hh
 
 #include <ctype.h>
-#include <strings.h>
 #include <string>
+#include <strings.h>
 
 using namespace std;

STATUS:

It compiles for armeb-linux, but when I run

anytermd --diff -s ISO-8859-1 -u root

I get

Server returned status code 500: 
Server Error: Invalid character set or unsupported conversion

VERSIONS:

TODO: any help would be appreciated.

(Last edited by arnold on 5 Feb 2009, 07:29)

Any luck with this?

I'd REALLY like to run Anyterm on the router...

The discussion might have continued from here.