Skip to content

Commit

Permalink
tinyx: add ports of tinyx/Xfbdev, necessary libs and ico
Browse files Browse the repository at this point in the history
JIRA: RTOS-861, RTOS-863
  • Loading branch information
adamgreloch committed Aug 2, 2024
1 parent 85770ab commit 0af4985
Show file tree
Hide file tree
Showing 31 changed files with 2,609 additions and 0 deletions.
260 changes: 260 additions & 0 deletions tinyx/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
#!/usr/bin/env bash

set -e

PREFIX_SHARE="${PREFIX_A}/share/"

# FIXME there *should* be a clean way to disable doc building via autotools config
TMP_DIR=`mktemp -d`

inner_log() {
echo -e "$1"
}

extract_sources() {
if [ ! -d "${PREFIX_PORT_SRC}" ]; then
echo "Extracting sources from ${archive_filename}"
mkdir -p "${PREFIX_PORT_SRC}"
tar -axf "${PREFIX_PORT}/${archive_filename}" --strip-components 1 -C "${PREFIX_PORT_SRC}"
fi
}

exec_configure() {
(cd ${PREFIX_PORT_SRC} &&
autoreconf -vfi && # reconf, as there may be patches to configure.ac
"${PREFIX_PORT_SRC}/configure" CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
--host="${HOST%phoenix}linux" --sbindir="${PREFIX_PROG}" \
--libdir="${PREFIX_A}" --includedir="${PREFIX_H}" \
--prefix="${PREFIX_PORT_INSTALL}" --datarootdir="${PREFIX_A}" "${@}" \
--disable-shared --enable-static
)
}

md5_checksum() {
if [ ! -d "$1" ]; then
echo "no patches"
else
tar cfP - "$1" | md5sum
fi
}

port_cleanup() {
if [ -z "${1}" ]; then
echo "port_cleanup: no arg provided"
fi
rm -rf ${PREFIX_PORT_SRC}
rm -rf "${PREFIX_PORT_BUILD}/markers/${1}"
}

# TODO: add dependency rebuild on patch change, i.e. tinyxlib rebuild -> tinyx,
# ico rebuild
should_rebuild() {
patch_subdir="${1}"
marker_dir="${PREFIX_PORT_BUILD}/markers/${patch_subdir}"
patch_dir="${PREFIX_PORT}/patches/${patch_subdir}"

built_md5_path="${marker_dir}/built.md5"

if [ ! -f "${built_md5_path}" ]; then
inner_log "Patch and build ${patch_subdir} from scratch"
port_cleanup ${patch_subdir}

true
else
patch_md5=`md5_checksum ${patch_dir}`
if [ "${patch_md5}" = "$(cat ${built_md5_path})" ]; then
inner_log "${patch_subdir} up-to-date, not rebuilding"
false
else
inner_log "Cleaning ${patch_subdir} up after previous patch set"
port_cleanup ${patch_subdir}

inner_log "Patch and build ${patch_subdir} from scratch"
true
fi
fi
}

mark_as_built() {
patch_subdir="${1}"
marker_dir="${PREFIX_PORT_BUILD}/markers/${patch_subdir}"
mkdir -p "${marker_dir}"

patch_dir="${PREFIX_PORT}/patches/${patch_subdir}"

built_md5_path="${marker_dir}/built.md5"
md5_checksum ${patch_dir} > ${built_md5_path}
}

_build_xorgproto() {
b_log "tinyx: building xorgproto"

version="2023.1"
archive_filename="xorgproto-${version}.tar.gz"

PREFIX_PORT_SRC="${PREFIX_PORT_BUILD}/xorgproto/${version}"
b_port_download "https://www.x.org/archive/individual/proto/" "${archive_filename}"

port_cleanup "xorgproto/${version}"

extract_sources

if [ ! -f "${PREFIX_PORT_SRC}/config.status" ]; then
exec_configure --disable-specs --docdir="${TMP_DIR}/doc"
fi

b_port_apply_patches "${PREFIX_PORT_SRC}" "xorgproto/${version}"

make -C "${PREFIX_PORT_SRC}"
make -C "${PREFIX_PORT_SRC}" install

rm -rf "${PREFIX_H}/GL" # GL headers (possibly) unnecessary for now
}

build_tinyxlib() {
b_log "tinyx: building tinyxlib"

ref="9862f359a745be8ee8f6505571e09c38e2439c6d"
short_ref=`echo ${ref} | cut -c -6`
archive_filename="${ref}.tar.gz"

PREFIX_PORT_SRC="${PREFIX_PORT_BUILD}/tinyxlib/${short_ref}"
b_port_download "https://github.com/idunham/tinyxlib/archive/" "${archive_filename}"

if should_rebuild "tinyxlib/${short_ref}"; then
extract_sources

b_port_apply_patches "${PREFIX_PORT_SRC}" "tinyxlib/${short_ref}"

# set up a dir for X11 files (currently just for XKeysymDB)
mkdir -p "$PREFIX_SHARE/X11" # FIXME path chosen arbitrarily

make -C "${PREFIX_PORT_SRC}"
make -C "${PREFIX_PORT_SRC}" LIBDIR="${PREFIX_A}" INCDIR="${PREFIX_H}" install

# Install libxtrans
cp -ar "${PREFIX_PORT_SRC}/libxtrans/." "${PREFIX_H}/X11/Xtrans"
ln -sf "${PREFIX_H}/X11/Xtrans.h" "${PREFIX_H}/X11/Xtrans/Xtrans.h"

# remove sync.h, syncstr.h to avoid conflict with xorgproto
rm "${PREFIX_H}/X11/extensions/sync.h"
rm "${PREFIX_H}/X11/extensions/syncstr.h"

_build_xorgproto

mark_as_built "tinyxlib/${short_ref}"
fi
}

build_a_lib() {
libname="$1"
version="$2"
configure_opts="${@:3}"

b_log "tinyx: building ${libname}"

archive_filename="${libname}-${version}.tar.gz"

PREFIX_PORT_SRC="${PREFIX_PORT_BUILD}/${libname}/${version}"

b_port_download "https://www.x.org/archive/individual/lib/" "${archive_filename}"

if should_rebuild "${libname}/${version}"; then
extract_sources

b_port_apply_patches "${PREFIX_PORT_SRC}" "${libname}/${version}"

if [ ! -f "${PREFIX_PORT_SRC}/config.status" ]; then
exec_configure ${configure_opts}
fi

make -C "${PREFIX_PORT_SRC}"
make -C "${PREFIX_PORT_SRC}" install

mark_as_built "${libname}/${version}"
fi
}

build_tinyx() {
b_log "tinyx: building xserver"

ref="eed4902840732f170a7020cedb381017de99f2e6"
short_ref=`echo ${ref} | cut -c -6`
archive_filename="${ref}.tar.gz"

PREFIX_PORT_SRC="${PREFIX_PORT_BUILD}/tinyx/${short_ref}"
b_port_download "https://github.com/tinycorelinux/tinyx/archive/" "${archive_filename}"

if should_rebuild "tinyx/${short_ref}"; then
extract_sources

if [ ! -d "${PREFIX_PORT_SRC}/kdrive/phoenix/" ]; then
mkdir -p "${PREFIX_PORT_SRC}/kdrive/phoenix/"
cp "${PREFIX_PORT_SRC}/kdrive/linux/mouse.c" "${PREFIX_PORT_SRC}/kdrive/phoenix/mouse.c"
fi

b_port_apply_patches "${PREFIX_PORT_SRC}" "tinyx/${short_ref}"

if [ ! -f "${PREFIX_PORT_SRC}/config.status" ]; then
exec_configure --disable-xres --disable-screensaver --disable-xdmcp \
--disable-dpms --disable-xf86bigfont --disable-xdm-auth-1 \
--disable-dbe --host="${HOST}" \
--with-default-font-path="built-ins" # otherwise won't find 'fixed'. libxfont/src/fontfile.c:FontFileNameCheck()

# (brutally) force static compilation in generated Makefiles
# FIXME do it properly by patching configure.ac instead?
find . -name 'Makefile' -print0 | xargs -0 sed -i 's/ -lz/ -l:libz.a/g;s/ -lXfont/ -l:libXfont.a/g;s/ -lfontenc/ -l:libfontenc.a/g;s/-lm//g'
fi

make -C "${PREFIX_PORT_SRC}"

${STRIP} -o "${PREFIX_PROG_STRIPPED}/Xfbdev" "${PREFIX_PORT_SRC}/kdrive/fbdev/Xfbdev"
cp -a "${PREFIX_PORT_SRC}/kdrive/fbdev/Xfbdev" "${PREFIX_PROG}/Xfbdev"

b_install "${PREFIX_PORTS_INSTALL}/Xfbdev" /bin

mark_as_built "tinyx/${short_ref}"
fi
}

# building ico requires gettext
build_ico() {
b_log "tinyx: building ico"

version="1.0.4"
archive_filename="ico-${version}.tar.gz"
PREFIX_PORT_SRC="${PREFIX_PORT_BUILD}/ico/${version}"

b_port_download "https://www.x.org/archive/individual/app/" "${archive_filename}"

if should_rebuild "ico/${version}"; then
extract_sources

b_port_apply_patches "${PREFIX_PORT_SRC}" "ico/${version}"

if [ ! -f "${PREFIX_PORT_SRC}/config.status" ]; then
exec_configure
fi

make -C "${PREFIX_PORT_SRC}"

$STRIP -o "${PREFIX_PROG_STRIPPED}/ico" "${PREFIX_PORT_SRC}/ico"

b_install "${PREFIX_PORTS_INSTALL}/ico" /bin

mark_as_built "ico/${version}"
fi
}


# Call ordering is important here
build_tinyxlib
build_a_lib libfontenc 1.1.8

# libXfont depends on libfontenc and headers from xorgproto/tinyxlib
build_a_lib libXfont 1.5.4 --disable-freetype
build_ico

build_tinyx

rm -rf $TMP_DIR
31 changes: 31 additions & 0 deletions tinyx/patches/ico/1.0.4/01-ico.c.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
diff -ruN a/ico.c b/ico.c
--- a/ico.c 2024-07-22 14:37:21.564164578 +0200
+++ b/ico.c 2024-07-24 11:32:51.014963666 +0200
@@ -74,12 +74,16 @@
#ifdef HAVE_CONFIG_H
#include "config.h"

-#include <X11/XlibConf.h>
#ifdef XTHREADS
# define MULTITHREAD
#endif
#endif /* HAVE_CONFIG_H / autoconf */

+#define _X_UNUSED
+#define _X_NORETURN
+#define DEBUG
+#undef MULTITHREAD
+
#include <math.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
@@ -90,9 +94,7 @@
#ifdef MULTIBUFFER
#include <X11/extensions/multibuf.h>
#endif /* MULTIBUFFER */
-#ifdef MULTITHREAD
#include <X11/Xthreads.h>
-#endif
#include <X11/Xos.h>

#define MIN_ICO_WIDTH 5
14 changes: 14 additions & 0 deletions tinyx/patches/libXfont/1.5.4/01-src-bitmap-bitscale.c.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff -ruN a/src/bitmap/bitscale.c b/src/bitmap/bitscale.c
--- a/src/bitmap/bitscale.c 2017-11-28 15:34:21.000000000 +0100
+++ b/src/bitmap/bitscale.c 2024-07-16 16:49:46.936913990 +0200
@@ -39,6 +39,10 @@
#include <X11/fonts/fontutil.h>
#include <math.h>

+#ifdef __phoenix__
+#define hypot(x,y) sqrt(((x)*(x))+((y)*(y)))
+#endif
+
#ifndef MAX
#define MAX(a,b) (((a)>(b)) ? a : b)
#endif
15 changes: 15 additions & 0 deletions tinyx/patches/libXfont/1.5.4/02-src-fc-fslibos.h.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff -ruN a/src/fc/fslibos.h b/src/fc/fslibos.h
--- a/src/fc/fslibos.h 2017-11-28 15:34:21.000000000 +0100
+++ b/src/fc/fslibos.h 2024-07-16 16:50:15.143867373 +0200
@@ -92,6 +92,11 @@
# define NMSKBITS 32
# endif

+#ifdef __phoenix__
+#include <sys/resource.h>
+#define NOFILES_MAX RLIMIT_NOFILE
+#endif
+
# define MSKCNT ((FONT_OPEN_MAX + NMSKBITS - 1) / NMSKBITS)

typedef unsigned long FdSet[MSKCNT];
21 changes: 21 additions & 0 deletions tinyx/patches/libXfont/1.5.4/03-src-fontfile-dirfile.c.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
diff -ruN a/src/fontfile/dirfile.c b/src/fontfile/dirfile.c
--- a/src/fontfile/dirfile.c 2017-11-28 15:34:21.000000000 +0100
+++ b/src/fontfile/dirfile.c 2024-07-16 16:51:06.852786243 +0200
@@ -94,7 +94,7 @@
strcat(dir_file, "/");
strcat(dir_file, FontDirFile);
#ifndef WIN32
- file_fd = open(dir_file, O_RDONLY | O_NOFOLLOW);
+ file_fd = open(dir_file, O_RDONLY);
if (file_fd >= 0) {
file = fdopen(file_fd, "rt");
}
@@ -291,7 +291,7 @@
}

#ifndef WIN32
- file_fd = open(alias_file, O_RDONLY | O_NOFOLLOW);
+ file_fd = open(alias_file, O_RDONLY);
if (file_fd >= 0) {
file = fdopen(file_fd, "rt");
}
14 changes: 14 additions & 0 deletions tinyx/patches/libXfont/1.5.4/04-src-fontfile-fontscale.c.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff -ruN a/src/fontfile/fontscale.c b/src/fontfile/fontscale.c
--- a/src/fontfile/fontscale.c 2017-11-28 15:34:21.000000000 +0100
+++ b/src/fontfile/fontscale.c 2024-07-16 16:50:34.984835602 +0200
@@ -34,6 +34,10 @@
#include <X11/fonts/fntfilst.h>
#include <math.h>

+#ifdef __phoenix__
+#define hypot(x,y) sqrt(((x)*(x))+((y)*(y)))
+#endif
+
Bool
FontFileAddScaledInstance (FontEntryPtr entry, FontScalablePtr vals,
FontPtr pFont, char *bitmapName)
13 changes: 13 additions & 0 deletions tinyx/patches/libXfont/1.5.4/05-src-util-fontxlfd.c.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff -ruN a/src/util/fontxlfd.c b/src/util/fontxlfd.c
--- a/src/util/fontxlfd.c 2017-11-28 15:34:21.000000000 +0100
+++ b/src/util/fontxlfd.c 2024-07-16 16:52:11.788691581 +0200
@@ -43,6 +43,9 @@
#if defined(sony) && !defined(SYSTYPE_SYSV) && !defined(_SYSTYPE_SYSV)
#define NO_LOCALE
#endif
+#ifdef __phoenix__
+#define NO_LOCALE
+#endif
#ifndef NO_LOCALE
#include <locale.h>
#endif
10 changes: 10 additions & 0 deletions tinyx/patches/libXfont/1.5.4/06-configure.ac.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--- a/configure.ac 2024-07-11 10:09:26.599010599 +0200
+++ b/configure.ac 2024-07-11 10:09:45.520728347 +0200
@@ -201,8 +201,6 @@
fi


-AC_CHECK_LIB(m, hypot, [MATH_LIBS=-lm
-AC_SUBST(MATH_LIBS)], AC_MSG_ERROR([*** libm is required]))

PKG_CHECK_MODULES(XFONT, [xproto xtrans fontsproto >= 2.1.3 fontenc])
Loading

0 comments on commit 0af4985

Please sign in to comment.