diff options
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/README.md | 28 | ||||
| -rw-r--r-- | scripts/appdmg.sh | 30 | ||||
| -rw-r--r-- | scripts/appimage.sh | 162 | ||||
| -rw-r--r-- | scripts/build.sh | 117 | ||||
| -rw-r--r-- | scripts/common.sh | 25 | ||||
| -rw-r--r-- | scripts/innosetup/innosetup.iss.in | 88 | ||||
| -rw-r--r-- | scripts/innosetup/innosetup.sh | 65 | ||||
| -rw-r--r-- | scripts/innosetup/litexl-55px.bmp | bin | 0 -> 12238 bytes | |||
| -rw-r--r-- | scripts/innosetup/wizard-modern-image.bmp | bin | 0 -> 52574 bytes | |||
| -rw-r--r-- | scripts/install-dependencies.sh | 74 | ||||
| -rw-r--r-- | scripts/lhelper.sh | 75 | ||||
| -rw-r--r-- | scripts/meson.build | 8 | ||||
| -rw-r--r-- | scripts/package.sh | 259 | ||||
| -rw-r--r-- | scripts/repackage.sh | 10 | ||||
| -rwxr-xr-x | scripts/run-local | 10 |
15 files changed, 946 insertions, 5 deletions
diff --git a/scripts/README.md b/scripts/README.md new file mode 100644 index 00000000..a236599c --- /dev/null +++ b/scripts/README.md @@ -0,0 +1,28 @@ +# Scripts + +Various scripts and configurations used to configure, build, and package Lite XL. + +### Build + +- **build.sh** +- **build-packages.sh**: In root directory, as all in one script; relies to the + ones in this directory. + +### Package + +- **appdmg.sh**: Create a macOS DMG image using [AppDMG][1]. +- **appimage.sh**: [AppImage][2] builder. +- **innosetup.sh**: Creates a 32/64 bit [InnoSetup][3] installer package. +- **package.sh**: Creates all binary / DMG image / installer / source packages. + +### Utility + +- **common.sh**: Common functions used by other scripts. +- **install-dependencies.sh**: Installs required applications to build, package + and run Lite XL, mainly useful for CI and documentation purpose. + Preferably not to be used in user systems. +- **fontello-config.json**: Used by the icons generator. + +[1]: https://github.com/LinusU/node-appdmg +[2]: https://docs.appimage.org/ +[3]: https://jrsoftware.org/isinfo.php 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..8844fafe --- /dev/null +++ b/scripts/appimage.sh @@ -0,0 +1,162 @@ +#!/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 + +source scripts/common.sh + +show_help(){ + echo + echo "Usage: $0 <OPTIONS>" + 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="$(get_default_build_dir)" +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..75212468 --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,117 @@ +#!/bin/bash +set -e + +if [ ! -e "src/api/api.h" ]; then + echo "Please run this script from the root directory of Lite XL."; exit 1 +fi + +source scripts/common.sh + +show_help() { + echo + echo "Usage: $0 <OPTIONS>" + echo + echo "Available options:" + echo + echo "-b --builddir DIRNAME Sets the name of the build directory (not path)." + echo " Default: '$(get_default_build_dir)'." + echo " --debug Debug this script." + echo "-f --forcefallback Force to build dependencies statically." + echo "-h --help Show this help and exit." + echo "-p --prefix PREFIX Install directory prefix. Default: '/'." + echo "-B --bundle Create an App bundle (macOS only)" + echo "-P --portable Create a portable binary package." + echo "-O --pgo Use profile guided optimizations (pgo)." + echo " macOS: disabled when used with --bundle," + echo " Windows: Implicit being the only option." + echo +} + +main() { + local platform="$(get_platform_name)" + local build_dir="$(get_default_build_dir)" + local prefix=/ + local force_fallback + local bundle + local portable + local pgo + + for i in "$@"; do + case $i in + -h|--help) + show_help + exit 0 + ;; + -b|--builddir) + build_dir="$2" + shift + shift + ;; + --debug) + set -x + shift + ;; + -f|--forcefallback) + force_fallback="--wrap-mode=forcefallback" + shift + ;; + -p|--prefix) + prefix="$2" + shift + shift + ;; + -B|--bundle) + if [[ "$platform" != "macos" ]]; then + echo "Warning: ignoring --bundle option, works only under macOS." + else + bundle="-Dbundle=true" + fi + shift + ;; + -P|--portable) + portable="-Dportable=true" + shift + ;; + -O|--pgo) + pgo="-Db_pgo=generate" + shift + ;; + *) + # unknown option + ;; + esac + done + + if [[ -n $1 ]]; then + show_help + exit 1 + fi + + if [[ $platform == "macos" && -n $bundle && -n $portable ]]; then + echo "Warning: \"bundle\" and \"portable\" specified; excluding portable package." + portable="" + fi + + rm -rf "${build_dir}" + + CFLAGS=$CFLAGS LDFLAGS=$LDFLAGS meson setup \ + --buildtype=release \ + --prefix "$prefix" \ + $force_fallback \ + $bundle \ + $portable \ + $pgo \ + "${build_dir}" + + meson compile -C "${build_dir}" + + if [ ! -z ${pgo+x} ]; then + cp -r data "${build_dir}/src" + "${build_dir}/src/lite-xl" + meson configure -Db_pgo=use "${build_dir}" + meson compile -C "${build_dir}" + rm -fr "${build_dir}/data" + fi +} + +main "$@" diff --git a/scripts/common.sh b/scripts/common.sh new file mode 100644 index 00000000..2b49d362 --- /dev/null +++ b/scripts/common.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +set -e + +get_platform_name() { + if [[ "$OSTYPE" == "msys" ]]; then + echo "windows" + elif [[ "$OSTYPE" == "darwin"* ]]; then + echo "macos" + elif [[ "$OSTYPE" == "linux"* || "$OSTYPE" == "freebsd"* ]]; then + echo "linux" + else + echo "UNSUPPORTED-OS" + fi +} + +get_default_build_dir() { + platform=$(get_platform_name) + echo "build-$platform-$(uname -m)" +} + +if [[ $(get_platform_name) == "UNSUPPORTED-OS" ]]; then + echo "Error: unknown OS type: \"$OSTYPE\"" + exit 1 +fi diff --git a/scripts/innosetup/innosetup.iss.in b/scripts/innosetup/innosetup.iss.in new file mode 100644 index 00000000..2b669fc0 --- /dev/null +++ b/scripts/innosetup/innosetup.iss.in @@ -0,0 +1,88 @@ +#define MyAppName "Lite XL"
+#define MyAppVersion "@PROJECT_VERSION@"
+#define MyAppPublisher "Lite XL Team"
+#define MyAppURL "https://lite-xl.github.io"
+#define MyAppExeName "lite-xl.exe"
+#define BuildDir "@PROJECT_BUILD_DIR@"
+#define SourceDir "@PROJECT_SOURCE_DIR@"
+
+; Use /dArch option to create a setup for a different architecture, e.g.:
+; iscc /dArch=x86 innosetup.iss
+#ifndef Arch
+ #define Arch "x64"
+#endif
+
+[Setup]
+; NOTE: The value of AppId uniquely identifies this application.
+; Do not use the same AppId value in installers for other applications.
+; To generate a new GUID, click Tools | Generate GUID inside the InnoSetup IDE.
+AppId={{06761240-D97C-43DE-B9ED-C15F765A2D65}
+
+AppName={#MyAppName}
+AppVersion={#MyAppVersion}
+;AppVerName={#MyAppName} {#MyAppVersion}
+AppPublisher={#MyAppPublisher}
+AppPublisherURL={#MyAppURL}
+AppSupportURL={#MyAppURL}
+AppUpdatesURL={#MyAppURL}
+
+#if Arch=="x64"
+ ArchitecturesAllowed=x64
+ ArchitecturesInstallIn64BitMode=x64
+ #define ArchInternal "x86_64"
+#else
+ #define ArchInternal "i686"
+#endif
+
+AllowNoIcons=yes
+Compression=lzma
+SolidCompression=yes
+DefaultDirName={autopf}/{#MyAppName}
+DefaultGroupName={#MyAppPublisher}
+UninstallFilesDir={app}
+
+; Uncomment the following line to run in non administrative install mode
+; (install for current user only.)
+;PrivilegesRequired=lowest
+PrivilegesRequiredOverridesAllowed=dialog
+
+; The [Icons] "quicklaunchicon" entry uses {userappdata}
+; but its [Tasks] entry has a proper IsAdminInstallMode Check.
+UsedUserAreasWarning=no
+
+OutputDir=.
+OutputBaseFilename=LiteXL-{#MyAppVersion}-{#ArchInternal}-setup
+;DisableDirPage=yes
+;DisableProgramGroupPage=yes
+
+LicenseFile={#SourceDir}/LICENSE
+SetupIconFile={#SourceDir}/resources/icons/icon.ico
+WizardImageFile="{#SourceDir}/scripts/innosetup/wizard-modern-image.bmp"
+WizardSmallImageFile="{#SourceDir}/scripts/innosetup/litexl-55px.bmp"
+
+[Languages]
+Name: "english"; MessagesFile: "compiler:Default.isl"
+
+[Tasks]
+Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
+Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 6.1; Check: not IsAdminInstallMode
+Name: "portablemode"; Description: "Portable Mode"; Flags: unchecked
+
+[Files]
+Source: "{#BuildDir}/src/lite-xl.exe"; DestDir: "{app}"; Flags: ignoreversion
+Source: "{#BuildDir}/mingwLibs{#Arch}/*"; DestDir: "{app}"; Flags: ignoreversion ; Check: DirExists(ExpandConstant('{#BuildDir}/mingwLibs{#Arch}'))
+Source: "{#SourceDir}/data/*"; DestDir: "{app}/data"; Flags: ignoreversion recursesubdirs
+; NOTE: Don't use "Flags: ignoreversion" on any shared system files
+
+[Icons]
+Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
+Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Check: not WizardIsTaskSelected('portablemode')
+Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"; Check: not WizardIsTaskSelected('portablemode')
+Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: quicklaunchicon; Check: not WizardIsTaskSelected('portablemode')
+; Name: "{usersendto}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
+
+[Run]
+Filename: "{app}/{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
+
+[Setup]
+Uninstallable=not WizardIsTaskSelected('portablemode')
diff --git a/scripts/innosetup/innosetup.sh b/scripts/innosetup/innosetup.sh new file mode 100644 index 00000000..4384d13c --- /dev/null +++ b/scripts/innosetup/innosetup.sh @@ -0,0 +1,65 @@ +#!/bin/bash +set -e + +if [ ! -e "src/api/api.h" ]; then + echo "Please run this script from the root directory of Lite XL."; exit 1 +fi + +source scripts/common.sh + +show_help() { + echo + echo "Usage: $0 <OPTIONS>" + echo + echo "Available options:" + echo + echo "-b --builddir DIRNAME Sets the name of the build directory (not path)." + echo " Default: '$(get_default_build_dir)'." + echo " --debug Debug this script." + echo +} + +main() { + local build_dir=$(get_default_build_dir) + local arch + + if [[ $MSYSTEM == "MINGW64" ]]; then arch=x64; else arch=Win32; fi + + for i in "$@"; do + case $i in + -h|--help) + show_help + exit 0 + ;; + -b|--builddir) + build_dir="$2" + shift + shift + ;; + --debug) + set -x + shift + ;; + *) + # unknown option + ;; + esac + done + + if [[ -n $1 ]]; then + show_help + exit 1 + fi + + # Copy MinGW libraries dependencies. + # MSYS2 ldd command seems to be only 64bit, so use ntldd + # see https://github.com/msys2/MINGW-packages/issues/4164 + local mingwLibsDir="${build_dir}/mingwLibs$arch" + mkdir -p "$mingwLibsDir" + ntldd -R "${build_dir}/src/lite-xl.exe" | grep mingw | awk '{print $3}' | sed 's#\\#/#g' | xargs -I '{}' cp -v '{}' $mingwLibsDir + + "/c/Program Files (x86)/Inno Setup 6/ISCC.exe" -dARCH=$arch "${build_dir}/scripts/innosetup.iss" + pushd "${build_dir}/scripts"; mv LiteXL*.exe "./../../"; popd +} + +main "$@" diff --git a/scripts/innosetup/litexl-55px.bmp b/scripts/innosetup/litexl-55px.bmp Binary files differnew file mode 100644 index 00000000..d3424a9b --- /dev/null +++ b/scripts/innosetup/litexl-55px.bmp diff --git a/scripts/innosetup/wizard-modern-image.bmp b/scripts/innosetup/wizard-modern-image.bmp Binary files differnew file mode 100644 index 00000000..cf844e09 --- /dev/null +++ b/scripts/innosetup/wizard-modern-image.bmp diff --git a/scripts/install-dependencies.sh b/scripts/install-dependencies.sh new file mode 100644 index 00000000..2f9519b1 --- /dev/null +++ b/scripts/install-dependencies.sh @@ -0,0 +1,74 @@ +#!/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 "Lite XL dependecies installer. Mainly used for CI but can also work on users systems." + echo "USE IT AT YOUR OWN RISK!" + echo + echo "Usage: $0 <OPTIONS>" + echo + echo "Available options:" + echo + echo "-l --lhelper Install tools required by LHelper and doesn't" + echo " install external libraries." + echo " --debug Debug this script." + echo +} + +main() { + local lhelper=false + + for i in "$@"; do + case $i in + -s|--lhelper) + lhelper=true + shift + ;; + --debug) + set -x + shift + ;; + *) + # unknown option + ;; + esac + done + + if [[ -n $1 ]]; then + show_help + exit 1 + fi + + if [[ "$OSTYPE" == "linux"* ]]; then + if [[ $lhelper == true ]]; then + sudo apt-get install -qq ninja-build + else + sudo apt-get install -qq ninja-build libsdl2-dev libfreetype6 + fi + pip3 install meson + elif [[ "$OSTYPE" == "darwin"* ]]; then + if [[ $lhelper == true ]]; then + brew install bash md5sha1sum ninja + else + brew install bash ninja sdl2 + fi + pip3 install meson + cd ~; npm install appdmg; cd - + ~/node_modules/appdmg/bin/appdmg.js --version + elif [[ "$OSTYPE" == "msys" ]]; then + if [[ $lhelper == true ]]; then + pacman --noconfirm -S \ + ${MINGW_PACKAGE_PREFIX}-{gcc,meson,ninja,ntldd,pkg-config} unzip + else + pacman --noconfirm -S \ + ${MINGW_PACKAGE_PREFIX}-{gcc,meson,ninja,ntldd,pkg-config,freetype,pcre2,SDL2} unzip + fi + fi +} + +main "$@" diff --git a/scripts/lhelper.sh b/scripts/lhelper.sh new file mode 100644 index 00000000..af6ae158 --- /dev/null +++ b/scripts/lhelper.sh @@ -0,0 +1,75 @@ +#!/bin/bash +set -e + +show_help() { + echo + echo "Usage: $0 <OPTIONS>" + echo + echo "Available options:" + echo + echo " --debug Debug this script." + echo "-h --help Show this help and exit." + echo "-p --prefix PREFIX Install directory prefix." + echo " Default: '$HOME/.local'." + echo +} + +main() { + local lhelper_prefix="$HOME/.local" + + for i in "$@"; do + case $i in + -h|--help) + show_help + exit 0 + ;; + -p|--prefix) + lhelper_prefix="$2" + echo "LHelper prefix set to: \"${lhelper_prefix}\"" + shift + shift + ;; + --debug) + set -x + shift + ;; + *) + # unknown option + ;; + esac + done + + if [[ -n $1 ]]; then show_help; exit 1; fi + + if [[ ! -f ${lhelper_prefix}/bin/lhelper ]]; then + + git clone https://github.com/franko/lhelper.git + + # FIXME: This should be set in ~/.bash_profile if not using CI + # export PATH="${HOME}/.local/bin:${PATH}" + mkdir -p "${lhelper_prefix}/bin" + pushd lhelper; bash install "${lhelper_prefix}"; 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) to support CI + 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 +} + +main diff --git a/scripts/meson.build b/scripts/meson.build new file mode 100644 index 00000000..8b45814d --- /dev/null +++ b/scripts/meson.build @@ -0,0 +1,8 @@ +if host_machine.system() == 'windows' + configure_file( + input : 'innosetup/innosetup.iss.in', + output : 'innosetup.iss', + configuration : conf_data + ) +endif + diff --git a/scripts/package.sh b/scripts/package.sh new file mode 100644 index 00000000..1370aee8 --- /dev/null +++ b/scripts/package.sh @@ -0,0 +1,259 @@ +#!/bin/bash +set -e + +if [ ! -e "src/api/api.h" ]; then + echo "Please run this script from the root directory of Lite XL."; exit 1 +fi + +source scripts/common.sh + +show_help() { + echo + echo "Usage: $0 <OPTIONS>" + echo + echo "Available options:" + echo + echo "-b --builddir DIRNAME Sets the name of the build directory (not path)." + echo " Default: '$(get_default_build_dir)'." + echo "-d --destdir DIRNAME Set the name of the package directory (not path)." + echo " Default: 'lite-xl'." + echo "-h --help Show this help and exit." + echo "-p --prefix PREFIX Install directory prefix. Default: '/'." + echo "-v --version VERSION Sets the version on the package name." + echo " --addons Install 3rd party addons (currently RXI colors)." + echo " --debug Debug this script." + echo "-A --appimage Create an AppImage (Linux only)." + echo "-B --binary Create a normal / portable package or macOS bundle," + echo " depending on how the build was configured. (Default.)" + echo "-D --dmg Create a DMG disk image with AppDMG (macOS only)." + echo "-I --innosetup Create a InnoSetup package (Windows only)." + echo "-S --source Create a source code package," + echo " including subprojects dependencies." + echo +} + +# Addons installation: some distributions forbid external downloads +# so make it as optional module. +install_addons() { + local build_dir="$1" + local data_dir="$2" + + if [[ -d "${build_dir}/third/data/colors" ]]; then + echo "Warning: found previous colors addons installation, skipping." + return 0 + fi + + # Copy third party color themes + curl --insecure \ + -L "https://github.com/rxi/lite-colors/archive/master.zip" \ + -o "${build_dir}/rxi-lite-colors.zip" + + mkdir -p "${build_dir}/third/data/colors" + unzip "${build_dir}/rxi-lite-colors.zip" -d "${build_dir}" + mv "${build_dir}/lite-colors-master/colors" "${build_dir}/third/data" + rm -rf "${build_dir}/lite-colors-master" + + for module_name in colors; do + cp -r "${build_dir}/third/data/$module_name" "${data_dir}" + done +} + +source_package() { + local build_dir=build-src + local package_name=$1 + + rm -rf ${build_dir} + rm -rf ${package_name} + rm -f ${package_name}.tar.gz + + meson subprojects download + meson setup ${build_dir} -Dsource-only=true + + # Note: not using git-archive(-all) because it can't include subprojects ignored by git + rsync -arv \ + --exclude /*build*/ \ + --exclude *.git* \ + --exclude lhelper \ + --exclude lite-xl* \ + --exclude submodules \ + . ${package_name} + + cp "${build_dir}/start.lua" "${package_name}/data/core" + + tar rf ${package_name}.tar ${package_name} + gzip -9 ${package_name}.tar +} + +main() { + local arch="$(uname -m)" + local platform="$(get_platform_name)" + local build_dir="$(get_default_build_dir)" + local dest_dir=lite-xl + local prefix=/ + local version + local addons=false + local appimage=false + local binary=false + local dmg=false + local innosetup=false + local source=false + + for i in "$@"; do + case $i in + -b|--builddir) + build_dir="$2" + shift + shift + ;; + -d|--destdir) + dest_dir="$2" + shift + shift + ;; + -h|--help) + show_help + exit 0 + ;; + -p|--prefix) + prefix="$2" + shift + shift + ;; + -v|--version) + if [[ -n $2 ]]; then version="-$2"; fi + shift + shift + ;; + -A|--appimage) + if [[ "$platform" != "linux" ]]; then + echo "Warning: ignoring --appimage option, works only under Linux." + else + appimage=true + fi + shift + ;; + -B|--binary) + binary=true + shift + ;; + -D|--dmg) + if [[ "$platform" != "macos" ]]; then + echo "Warning: ignoring --dmg option, works only under macOS." + else + dmg=true + fi + shift + ;; + -I|--innosetup) + if [[ "$platform" != "windows" ]]; then + echo "Warning: ignoring --innosetup option, works only under Windows." + else + innosetup=true + fi + shift + ;; + -S|--source) + source=true + shift + ;; + --addons) + addons=true + shift + ;; + --debug) + set -x + shift + ;; + *) + # unknown option + ;; + esac + done + + if [[ -n $1 ]]; then show_help; exit 1; fi + + # The source package doesn't require a previous build, + # nor the following install step, so run it now. + if [[ $source == true ]]; then source_package "lite-xl$version-src"; fi + + # No packages request + if [[ $appimage == false && $binary == false && $dmg == false && $innosetup == false ]]; then + # Source only, return. + if [[ $source == true ]]; then return 0; fi + # Build the binary package as default instead doing nothing. + binary=true + fi + + rm -rf "${dest_dir}" + + DESTDIR="$(pwd)/${dest_dir}" meson install -C "${build_dir}" + + local data_dir="$(pwd)/${dest_dir}/data" + local exe_file="$(pwd)/${dest_dir}/lite-xl" + local package_name=lite-xl$version-$platform-$arch + local bundle=false + local portable=false + local stripcmd="strip" + + if [[ -d "${data_dir}" ]]; then + echo "Creating a portable, compressed archive..." + portable=true + exe_file="$(pwd)/${dest_dir}/lite-xl" + if [[ $platform == "windows" ]]; then + exe_file="${exe_file}.exe" + stripcmd="strip --strip-all" + else + # Windows archive is always portable + package_name+="-portable" + fi + elif [[ $platform == "macos" && ! -d "${data_dir}" ]]; then + data_dir="$(pwd)/${dest_dir}/Contents/Resources" + if [[ -d "${data_dir}" ]]; then + echo "Creating a macOS bundle application..." + bundle=true + # Specify "bundle" on compressed archive only, implicit on images + if [[ $dmg == false ]]; then package_name+="-bundle"; fi + rm -rf "Lite XL.app"; mv "${dest_dir}" "Lite XL.app" + dest_dir="Lite XL.app" + exe_file="$(pwd)/${dest_dir}/Contents/MacOS/lite-xl" + fi + fi + + if [[ $bundle == false && $portable == false ]]; then + echo "Creating a compressed archive..." + data_dir="$(pwd)/${dest_dir}/$prefix/share/lite-xl" + exe_file="$(pwd)/${dest_dir}/$prefix/bin/lite-xl" + fi + + mkdir -p "${data_dir}" + + if [[ $addons == true ]]; then install_addons "${build_dir}" "${data_dir}"; fi + + # TODO: use --skip-subprojects when 0.58.0 will be available on supported + # distributions to avoid subprojects' include and lib directories to be copied. + # Install Meson with PIP to get the latest version is not always possible. + pushd "${dest_dir}" + find . -type d -name 'include' -prune -exec rm -rf {} \; + find . -type d -name 'lib' -prune -exec rm -rf {} \; + find . -type d -empty -delete + popd + + $stripcmd "${exe_file}" + + if [[ $binary == true ]]; then + rm -f "${package_name}".tar.gz + rm -f "${package_name}".zip + + if [[ $platform == "windows" ]]; then + zip -9rv ${package_name}.zip ${dest_dir}/* + else + tar czvf "${package_name}".tar.gz "${dest_dir}" + fi + fi + + if [[ $appimage == true ]]; then source scripts/appimage.sh; fi + if [[ $bundle == true && $dmg == true ]]; then source scripts/appdmg.sh "${package_name}"; fi + if [[ $innosetup == true ]]; then source scripts/innosetup/innosetup.sh -b "${build_dir}"; fi +} + +main "$@" diff --git a/scripts/repackage.sh b/scripts/repackage.sh index 99368582..f8da579f 100644 --- a/scripts/repackage.sh +++ b/scripts/repackage.sh @@ -10,7 +10,7 @@ copy_directory_from_repo () { fi local dirname="$1" local destdir="$2" - git archive master "$dirname" --format=tar | tar xf - -C "$destdir" "${tar_options[@]}" + git archive "$lite_branch" "$dirname" --format=tar | tar xf - -C "$destdir" "${tar_options[@]}" } lite_copy_third_party_modules () { @@ -23,12 +23,17 @@ lite_copy_third_party_modules () { rm "$build/rxi-lite-colors.zip" } +lite_branch=master while [ ! -z ${1+x} ]; do case "$1" in -dir) use_dir="$(realpath $2)" shift 2 ;; + -branch) + lite_branch="$2" + shift 2 + ;; *) echo "unknown option: $1" exit 1 @@ -73,6 +78,8 @@ for filename in $(ls -1 *.zip *.tar.*); do fi rm "$filename" find lite-xl -name lite -exec chmod a+x '{}' \; + start_file=$(find lite-xl -name start.lua) + lite_version=$(cat "$start_file" | awk 'match($0, /^\s*VERSION\s*=\s*"(.+)"/, a) { print(a[1]) }') xcoredir="$(find lite-xl -type d -name 'core')" coredir="$(dirname $xcoredir)" echo "coredir: $coredir" @@ -81,6 +88,7 @@ for filename in $(ls -1 *.zip *.tar.*); do rm -fr "$coredir/$module_name" (cd .. && copy_directory_from_repo --strip-components=1 "data/$module_name" "$workdir/$coredir") done + sed -i "s/@PROJECT_VERSION@/$lite_version/g" "$start_file" for module_name in plugins colors; do cp -r "third/data/$module_name" "$coredir" done diff --git a/scripts/run-local b/scripts/run-local index d5de23aa..8a32e7fa 100755 --- a/scripts/run-local +++ b/scripts/run-local @@ -47,10 +47,7 @@ if [[ "$OSTYPE" == "msys"* || "$OSTYPE" == "mingw"* ]]; then fi rundir=".run" -if [[ "$OSTYPE" == "darwin"* ]]; then - bindir="$rundir" - datadir="$rundir" -elif [ "$option_portable" == on ]; then +if [ "$option_portable" == on ]; then bindir="$rundir" datadir="$rundir/data" else @@ -75,9 +72,14 @@ copy_lite_build () { else cp "$builddir/src/lite-xl" "$bindir" fi + mkdir -p "$datadir/core" for module_name in core plugins colors fonts; do cp -r "data/$module_name" "$datadir" done + # The start.lua file is generated by meson in $builddir but + # there is already a start.lua file in data/core so the command below + # should be executed after we copy the data/core directory. + cp "$builddir/start.lua" "$datadir/core" } run_lite () { |
