diff --git a/.gitignore b/.gitignore index aa8f4ba0..7dc39e42 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ submodules/ subprojects/lua/ subprojects/libagg/ subprojects/reproc/ +/appimage* .ccls-cache .lite-debug.log .run* @@ -13,7 +14,6 @@ subprojects/reproc/ *.zip *.DS_Store *App* -appimage* compile_commands.json error.txt lite-xl* diff --git a/resources/macos/appdmg.png b/resources/macos/appdmg.png new file mode 100644 index 00000000..1df7b60d Binary files /dev/null and b/resources/macos/appdmg.png differ diff --git a/scripts/appdmg.sh b/scripts/appdmg.sh new file mode 100644 index 00000000..840f518b --- /dev/null +++ b/scripts/appdmg.sh @@ -0,0 +1,30 @@ +#!/bin/bash +set -ex + +if [ ! -e "src/api/api.h" ]; then + echo "Please run this script from the root directory of Lite XL." + exit 1 +fi + +cat > lite-xl-dmg.json << EOF +{ + "title": "Lite XL", + "icon": "$(pwd)/resources/icons/icon.icns", + "background": "$(pwd)/resources/macos/appdmg.png", + "window": { + "position": { + "x": 360, + "y": 360 + }, + "size": { + "width": 480, + "height": 360 + } + }, + "contents": [ + { "x": 144, "y": 248, "type": "file", "path": "$(pwd)/Lite XL.app" }, + { "x": 336, "y": 248, "type": "link", "path": "/Applications" } + ] +} +EOF +~/node_modules/appdmg/bin/appdmg.js lite-xl-dmg.json "$(pwd)/$1.dmg" diff --git a/scripts/appimage.sh b/scripts/appimage.sh new file mode 100644 index 00000000..b2cc5cd7 --- /dev/null +++ b/scripts/appimage.sh @@ -0,0 +1,160 @@ +#!/bin/env bash +set -ex + +if [ ! -e "src/api/api.h" ]; then + echo "Please run this script from the root directory of Lite XL." + exit 1 +fi + +show_help(){ + echo + echo $0 + echo + echo "Available options:" + echo + echo "-h --help Show this help and exits." + echo "-b --builddir DIRNAME Sets the name of the build dir (no path)." + echo " Default: 'build'." + echo "-n --nobuild Skips the build step, use existing files." + echo "-s --static Specify if building using static libraries" + echo " by using lhelper tool." + echo "-v --version VERSION Specify a version, non whitespace separated string." + echo +} + +ARCH="$(uname -m)" +BUILD_DIR=build +RUN_BUILD=true +STATIC_BUILD=false + +for i in "$@"; do + case $i in + -h|--belp) + show_help + exit 0 + ;; + -b|--builddir) + BUILD_DIR="$2" + shift + shift + ;; + -n|--nobuild) + RUN_BUILD=false + shift + ;; + -s|--static) + STATIC_BUILD=true + shift + ;; + -v|--version) + VERSION="$2" + shift + shift + ;; + *) + # unknown option + ;; + esac +done + +# TODO: Versioning using git +#if [[ -z $VERSION && -d .git ]]; then +# VERSION=$(git describe --tags --long | sed 's/^v//; s/\([^-]*-g\)/r\1/; s/-/./g') +#fi + +if [[ -n $1 ]]; then + show_help + exit 1 +fi + +setup_appimagetool(){ + if ! which appimagetool > /dev/null ; then + if [ ! -e appimagetool ]; then + if ! wget -O appimagetool "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-${ARCH}.AppImage" ; then + echo "Could not download the appimagetool for the arch '${ARCH}'." + exit 1 + else + chmod 0755 appimagetool + fi + fi + fi +} + +download_appimage_apprun(){ + if [ ! -e AppRun ]; then + if ! wget -O AppRun "https://github.com/AppImage/AppImageKit/releases/download/continuous/AppRun-${ARCH}" ; then + echo "Could not download AppRun for the arch '${ARCH}'." + exit 1 + else + chmod 0755 AppRun + fi + fi +} + +build_litexl(){ + if [ -e build ]; then + rm -rf build + fi + + if [ -e ${BUILD_DIR} ]; then + rm -rf ${BUILD_DIR} + fi + + echo "Build lite-xl..." + sleep 1 + meson setup --buildtype=release --prefix /usr ${BUILD_DIR} + meson compile -C ${BUILD_DIR} +} + +generate_appimage(){ + if [ -e LiteXL.AppDir ]; then + rm -rf LiteXL.AppDir + fi + + echo "Creating LiteXL.AppDir..." + + DESTDIR="$(realpath LiteXL.AppDir)" meson install --skip-subprojects -C ${BUILD_DIR} + mv AppRun LiteXL.AppDir/ + # These could be symlinks but it seems they doesn't work with AppimageLauncher + cp resources/icons/lite-xl.svg LiteXL.AppDir/ + cp resources/linux/org.lite-xl.lite-xl.desktop LiteXL.AppDir/ + + if [[ $STATIC_BUILD == false ]]; then + echo "Copying libraries..." + + mkdir -p LiteXL.AppDir/usr/lib/ + + local allowed_libs=( + libfreetype + libpcre2 + libSDL2 + libsndio + liblua + ) + + while read line; do + local libname="$(echo $line | cut -d' ' -f1)" + local libpath="$(echo $line | cut -d' ' -f2)" + for lib in "${allowed_libs[@]}" ; do + if echo "$libname" | grep "$lib" > /dev/null ; then + cp "$libpath" LiteXL.AppDir/usr/lib/ + continue 2 + fi + done + echo " Ignoring: $libname" + done < <(ldd build/src/lite-xl | awk '{print $1 " " $3}') + fi + + echo "Generating AppImage..." + local version="" + if [ -n "$VERSION" ]; then + version="-$VERSION" + fi + + ./appimagetool LiteXL.AppDir LiteXL${version}-${ARCH}.AppImage +} + +setup_appimagetool +download_appimage_apprun +if [[ $RUN_BUILD == true ]]; then build_litexl; fi +generate_appimage $1 diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100644 index 00000000..b0e013b1 --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,103 @@ +#!/bin/bash +set -ex + +if [ ! -e "src/api/api.h" ]; then + echo "Please run this script from the root directory of Lite XL." + exit 1 +fi + +show_help(){ + echo + echo "Usage: $0 " + echo + echo "Available options:" + echo + echo "-b --builddir DIRNAME Sets the name of the build directory (not path)." + echo " Default: 'build'." + echo "-p --prefix Install directory prefix. Mandatory." + echo "-s --static Specify if building using static libraries" + echo " by using lhelper tool." + echo +} + +install_lhelper() { + if [[ ! -d lhelper ]]; then + git clone https://github.com/franko/lhelper.git + pushd lhelper; bash install-github; popd + + if [[ "$OSTYPE" == "darwin"* ]]; then + CC=clang CXX=clang++ lhelper create lite-xl -n + else + lhelper create lite-xl -n + fi + fi + + # Not using `lhelper activate lite-xl` + source "$(lhelper env-source lite-xl)" + + lhelper install freetype2 + lhelper install sdl2 2.0.14-wait-event-timeout-1 + lhelper install pcre2 + + # Help MSYS2 to find the SDL2 include and lib directories to avoid errors + # during build and linking when using lhelper. + if [[ "$OSTYPE" == "msys" ]]; then + CFLAGS=-I${LHELPER_ENV_PREFIX}/include/SDL2 + LDFLAGS=-L${LHELPER_ENV_PREFIX}/lib + fi +} + +build() { + CFLAGS=$CFLAGS LDFLAGS=$LDFLAGS meson setup \ + --buildtype=release \ + --prefix "$PREFIX" \ + --wrap-mode=forcefallback \ + "${BUILD_DIR}" + + meson compile -C build +} + +BUILD_DIR=build +STATIC_BUILD=false + +for i in "$@"; do + case $i in + -h|--belp) + show_help + exit 0 + ;; + -b|--builddir) + BUILD_DIR="$2" + shift + shift + ;; + -p|--prefix) + PREFIX="$2" + shift + shift + ;; + -s|--static) + STATIC_BUILD=true + shift + ;; + *) + # unknown option + ;; + esac +done + +if [[ -n $1 ]]; then + show_help + exit 1 +fi + +if [[ -z $PREFIX ]]; then + echo "ERROR: prefix argument is missing." + exit 1 +fi + +if [[ $STATIC_BUILD == true ]]; then + install_lhelper +fi + +build diff --git a/scripts/msys2-package.sh b/scripts/msys2-package.sh new file mode 100644 index 00000000..5138d8a3 --- /dev/null +++ b/scripts/msys2-package.sh @@ -0,0 +1,56 @@ +#!/bin/bash +set -ex + +if [ ! -e "src/api/api.h" ]; then + echo "Please run this script from the root directory of Lite XL." + exit 1 +fi + +# FIXME: For some strange reason sometimes an error occurs randomly on the +# MINGW32 build of GitHub Actions; the environment variable $INSTALL_NAME +# is correct, but it expands with a drive letter at the end (all builds). + +show_help(){ + echo + echo "Usage: $0 " + echo + echo "Available options:" + echo + echo "-b --builddir DIRNAME Sets the name of the build directory (not path)." + echo " Default: 'build'." + echo "-d --destdir DIRNAME Sets the name of the install directory (not path)." + echo +} + +BUILD_DIR=build + +for i in "$@"; do + case $i in + -h|--belp) + show_help + exit 0 + ;; + -b|--builddir) + BUILD_DIR="$2" + shift + shift + ;; + -d|--destdir) + DEST_DIR="$2" + shift + shift + ;; + *) + # unknown option + ;; + esac +done + +if [[ -n $1 ]]; then + show_help + exit 1 +fi + +DESTDIR="$(pwd)/${DEST_DIR}" meson install --skip-subprojects -C ${BUILD_DIR} + +zip -9rv ${DEST_DIR}.zip ${DEST_DIR}/* diff --git a/scripts/source-package.sh b/scripts/source-package.sh new file mode 100644 index 00000000..aff80c9d --- /dev/null +++ b/scripts/source-package.sh @@ -0,0 +1,69 @@ +#!/bin/bash +set -ex + +if [ ! -e "src/api/api.h" ]; then + echo "Please run this script from the root directory of Lite XL." + exit 1 +fi + +show_help(){ + echo + echo "Usage: $0 " + echo + echo "Available options:" + echo + echo "-b --builddir DIRNAME Sets the name of the build directory (no path)." + echo " Default: 'build'." + echo "-d --destdir DIRNAME Sets the name of the install directory (no path)." + echo +} + +BUILD_DIR=build +DEST_DIR=lite-xl-src + +for i in "$@"; do + case $i in + -h|--belp) + show_help + exit 0 + ;; + -b|--builddir) + BUILD_DIR="$2" + shift + shift + ;; + -d|--destdir) + DEST_DIR="$2" + shift + shift + ;; + *) + # unknown option + ;; + esac +done + +if [[ -n $1 ]]; then + show_help + exit 1 +fi + +if test -d ${BUILD_DIR}; then rm -rf ${BUILD_DIR}; fi +if test -d ${DEST_DIR}; then rm -rf ${DEST_DIR}; fi +if test -f ${DEST_DIR}.tar.gz; then rm ${DEST_DIR}.tar.gz; fi + +meson subprojects download +meson setup ${BUILD_DIR} + +rsync -arv \ + --exclude /*build*/ \ + --exclude *.git* \ + --exclude lhelper \ + --exclude lite-xl* \ + --exclude submodules \ + . ${DEST_DIR} + +cp "${BUILD_DIR}/start.lua" "${DEST_DIR}/data/core" + +tar rf ${DEST_DIR}.tar ${DEST_DIR} +gzip -9 ${DEST_DIR}.tar