From c41dedafadeab200e671b73a8dcfa2231da09a61 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Thu, 3 Dec 2020 16:46:18 +0100 Subject: [PATCH] Improve the implementation of unix-like directories usage Add a Meson option "portable" to choose between "portable" and unix-like directories. Add information about this option in the README. To determine the user's directory use the variable USERPROFILE only on Windows and use HOME otherwise. Implement the "portable" option in the package build script. --- README.md | 18 +++++++- build-packages.sh | 105 ++++++++++++++++++++++++++++++++-------------- build.sh | 6 ++- meson.build | 2 +- src/main.c | 8 +++- 5 files changed, 102 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 69d4a876..2622e7c0 100644 --- a/README.md +++ b/README.md @@ -64,16 +64,32 @@ ninja -C build ninja -C build install ``` +When performing the "meson setup" command you may enable the "portable" option. + +If this latter is enabled Lite XL is built to use a "data" and a "user" directory +from the same directory of the executable. +If "portable" is not enabled (this is the default) Lite XL will use unix-like +directory locations. +In this case the "data" directory will be `$prefix/share/lite-xl` and the "user" +directory will be `$HOME/.config/lite-xl`. +The `$prefix` is determined as the directory such as `$prefix/bin` corresponds to +the location of the executable. +The `$HOME` is determined from the corresponding environment variable. +As a special case on Windows the variable `$USERPROFILE` will be used instead. + If you want to install Lite XL on Windows or Mac OS X we suggest to use the script `build-packages.sh`: ```sh bash build-packages.sh + +# In alternative the -portable option can be used like below: +# bash build-packages.sh -portable ``` It will run meson and create a Zip file that can be easily installed or uninstalled. Please note the, while compiling Lite XL on Mac OS X should work Mac OS X -is not well supported. +is not currently supported. ## Contributing Any additional functionality that can be added through a plugin should be done diff --git a/build-packages.sh b/build-packages.sh index b66f12ec..d89bdc94 100755 --- a/build-packages.sh +++ b/build-packages.sh @@ -22,19 +22,21 @@ build_dir_is_usable () { # Ordinary release build lite_build () { - local build="$1" + local meson_options=("-Dportable=$1") + local build="$2" build_dir_is_usable "$build" || exit 1 rm -fr "$build" - meson setup --buildtype=release "$build" || exit 1 + meson setup --buildtype=release "${meson_options[@]}" "$build" || exit 1 ninja -C "$build" || exit 1 } # Build using Profile Guided Optimizations (PGO) lite_build_pgo () { - local build="$1" + local meson_options=("-Dportable=$1") + local build="$2" build_dir_is_usable "$build" || exit 1 rm -fr "$build" - meson setup --buildtype=release -Db_pgo=generate "$build" || exit 1 + meson setup --buildtype=release "${meson_options[@]}" -Db_pgo=generate "$build" || exit 1 ninja -C "$build" || exit 1 copy_directory_from_repo data "$build/src" "$build/src/lite" @@ -43,15 +45,26 @@ lite_build_pgo () { } lite_build_package_windows () { - build="$1" - version="$2" - arch="$3" - os="win" + local portable="$1" + local build="$2" + local version="$3" + local arch="$4" + local os="win" local pdir=".package-build/lite-xl" - mkdir -p "$pdir" - copy_directory_from_repo data "$pdir" - cp "$build/src/lite.exe" "$pdir" - strip --strip-all "$pdir/lite.exe" + if [ $portable == "true" ]; then + local bindir="$pdir" + local datadir="$pdir/data" + else + local bindir="$pdir/bin" + local datadir="$pdir/share/lite-xl" + fi + mkdir -p "$bindir" + mkdir -p "$datadir" + for module_name in core plugins fonts; do + copy_directory_from_repo "data/$module_name" "$datadir" + done + cp "$build/src/lite.exe" "$bindir" + strip --strip-all "$bindir/lite.exe" pushd ".package-build" local package_name="lite-xl-$os-$arch.zip" zip "$package_name" -r "lite-xl" @@ -62,15 +75,26 @@ lite_build_package_windows () { } lite_build_package_macosx () { - build="$1" - version="$2" - arch="$3" - os="macosx" + local portable="$1" + local build="$2" + local version="$3" + local arch="$4" + local os="macosx" local pdir=".package-build/lite-xl.app/Contents/MacOS" - mkdir -p "$pdir" - copy_directory_from_repo data "$pdir" - cp "$build/src/lite" "$pdir" - strip "$pdir/lite" + if [ $portable == "true" ]; then + local bindir="$pdir" + local datadir="$pdir/data" + else + local bindir="$pdir/bin" + local datadir="$pdir/share/lite-xl" + fi + mkdir -p "$bindir" + mkdir -p "$datadir" + for module_name in core plugins fonts; do + copy_directory_from_repo "data/$module_name" "$datadir" + done + cp "$build/src/lite" "$bindir" + strip "$bindir/lite" pushd ".package-build" local package_name="lite-xl-$os-$arch.zip" zip "$package_name" -r "lite-xl.app" @@ -81,15 +105,26 @@ lite_build_package_macosx () { } lite_build_package_linux () { - build="$1" - version="$2" - arch="$3" - os="linux" + local portable="$1" + local build="$2" + local version="$3" + local arch="$4" + local os="linux" local pdir=".package-build/lite-xl" - mkdir -p "$pdir" - copy_directory_from_repo data "$pdir" - cp "$build/src/lite" "$pdir" - strip "$pdir/lite" + if [ $portable == "true" ]; then + local bindir="$pdir" + local datadir="$pdir/data" + else + local bindir="$pdir/bin" + local datadir="$pdir/share/lite-xl" + fi + mkdir -p "$bindir" + mkdir -p "$datadir" + for module_name in core plugins fonts; do + copy_directory_from_repo "data/$module_name" "$datadir" + done + cp "$build/src/lite" "$bindir" + strip "$bindir/lite" pushd ".package-build" local package_name="lite-xl-$os-$arch.tar.gz" tar czf "$package_name" "lite-xl" @@ -113,7 +148,7 @@ lite_build_package () { } if [[ -z "$1" || -z "$2" ]]; then - echo "usage: $0 " + echo "usage: $0 [options] " exit 1 fi @@ -122,14 +157,20 @@ if [[ "$1" == "-pgo" ]]; then shift fi +portable="false" +if [ "$1" == "-portable" ]; then + portable="true" + shift +fi + version="$1" arch="$2" build_dir=".build-$arch" if [ -z ${pgo+set} ]; then - lite_build "$build_dir" + lite_build "$portable" "$build_dir" else - lite_build_pgo "$build_dir" + lite_build_pgo "$portable" "$build_dir" fi -lite_build_package "$build_dir" "$version" "$arch" +lite_build_package "$portable" "$build_dir" "$version" "$arch" diff --git a/build.sh b/build.sh index 96afb71c..a7951ea1 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,10 @@ #!/bin/bash -cflags="-Wall -O3 -g -std=gnu11 -fno-strict-aliasing -Isrc -Ilib/font_renderer" +if [[ $1 == -portable ]]; then + cflags="-DLITE_XL_DATA_USE_EXEDIR" +fi + +cflags+="-Wall -O3 -g -std=gnu11 -fno-strict-aliasing -Isrc -Ilib/font_renderer" cflags+=" $(pkg-config --cflags lua5.2) $(sdl2-config --cflags)" lflags="-static-libgcc -static-libstdc++" for package in libagg freetype2 lua5.2; do diff --git a/meson.build b/meson.build index 247e3f10..059681a1 100644 --- a/meson.build +++ b/meson.build @@ -15,7 +15,7 @@ endif sdl_dep = dependency('sdl2', method: 'config-tool') lite_cargs = [] -if host_machine.system() == 'windows' +if get_option('portable') lite_cargs += ['-DLITE_XL_DATA_USE_EXEDIR'] endif diff --git a/src/main.c b/src/main.c index d9783a31..ba113d75 100644 --- a/src/main.c +++ b/src/main.c @@ -129,9 +129,13 @@ int main(int argc, char **argv) { #else " do\n" " local prefix = EXEDIR:match(\"^(.+)[/\\\\]bin$\")\n" +#ifdef _WIN32 + " local home = os.getenv('USERPROFILE')\n" +#else + " local home = os.getenv('HOME')\n" +#endif " DATADIR = prefix and (prefix .. '/share/lite-xl') or (EXEDIR .. '/data')\n" - " local home = os.getenv('USERPROFILE') or os.getenv('HOME')\n" - " USERDIR = home and home .. '/.config/lite-xl' or (EXEDIR .. '/user')\n" + " USERDIR = home and (home .. '/.config/lite-xl') or (EXEDIR .. '/user')\n" " end\n" " package.path = package.path .. ';' .. USERDIR .. '/?.lua'\n" " package.path = package.path .. ';' .. USERDIR .. '/?/init.lua'\n"