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.
This commit is contained in:
Francesco Abbate 2020-12-03 16:46:18 +01:00
parent 277186491a
commit c41dedafad
5 changed files with 102 additions and 37 deletions

View File

@ -64,16 +64,32 @@ ninja -C build
ninja -C build install 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`: If you want to install Lite XL on Windows or Mac OS X we suggest to use the script `build-packages.sh`:
```sh ```sh
bash build-packages.sh <version> <arch> bash build-packages.sh <version> <arch>
# In alternative the -portable option can be used like below:
# bash build-packages.sh -portable <version> <arch>
``` ```
It will run meson and create a Zip file that can be easily installed or uninstalled. 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 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 ## Contributing
Any additional functionality that can be added through a plugin should be done Any additional functionality that can be added through a plugin should be done

View File

@ -22,19 +22,21 @@ build_dir_is_usable () {
# Ordinary release build # Ordinary release build
lite_build () { lite_build () {
local build="$1" local meson_options=("-Dportable=$1")
local build="$2"
build_dir_is_usable "$build" || exit 1 build_dir_is_usable "$build" || exit 1
rm -fr "$build" rm -fr "$build"
meson setup --buildtype=release "$build" || exit 1 meson setup --buildtype=release "${meson_options[@]}" "$build" || exit 1
ninja -C "$build" || exit 1 ninja -C "$build" || exit 1
} }
# Build using Profile Guided Optimizations (PGO) # Build using Profile Guided Optimizations (PGO)
lite_build_pgo () { lite_build_pgo () {
local build="$1" local meson_options=("-Dportable=$1")
local build="$2"
build_dir_is_usable "$build" || exit 1 build_dir_is_usable "$build" || exit 1
rm -fr "$build" 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 ninja -C "$build" || exit 1
copy_directory_from_repo data "$build/src" copy_directory_from_repo data "$build/src"
"$build/src/lite" "$build/src/lite"
@ -43,15 +45,26 @@ lite_build_pgo () {
} }
lite_build_package_windows () { lite_build_package_windows () {
build="$1" local portable="$1"
version="$2" local build="$2"
arch="$3" local version="$3"
os="win" local arch="$4"
local os="win"
local pdir=".package-build/lite-xl" local pdir=".package-build/lite-xl"
mkdir -p "$pdir" if [ $portable == "true" ]; then
copy_directory_from_repo data "$pdir" local bindir="$pdir"
cp "$build/src/lite.exe" "$pdir" local datadir="$pdir/data"
strip --strip-all "$pdir/lite.exe" 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" pushd ".package-build"
local package_name="lite-xl-$os-$arch.zip" local package_name="lite-xl-$os-$arch.zip"
zip "$package_name" -r "lite-xl" zip "$package_name" -r "lite-xl"
@ -62,15 +75,26 @@ lite_build_package_windows () {
} }
lite_build_package_macosx () { lite_build_package_macosx () {
build="$1" local portable="$1"
version="$2" local build="$2"
arch="$3" local version="$3"
os="macosx" local arch="$4"
local os="macosx"
local pdir=".package-build/lite-xl.app/Contents/MacOS" local pdir=".package-build/lite-xl.app/Contents/MacOS"
mkdir -p "$pdir" if [ $portable == "true" ]; then
copy_directory_from_repo data "$pdir" local bindir="$pdir"
cp "$build/src/lite" "$pdir" local datadir="$pdir/data"
strip "$pdir/lite" 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" pushd ".package-build"
local package_name="lite-xl-$os-$arch.zip" local package_name="lite-xl-$os-$arch.zip"
zip "$package_name" -r "lite-xl.app" zip "$package_name" -r "lite-xl.app"
@ -81,15 +105,26 @@ lite_build_package_macosx () {
} }
lite_build_package_linux () { lite_build_package_linux () {
build="$1" local portable="$1"
version="$2" local build="$2"
arch="$3" local version="$3"
os="linux" local arch="$4"
local os="linux"
local pdir=".package-build/lite-xl" local pdir=".package-build/lite-xl"
mkdir -p "$pdir" if [ $portable == "true" ]; then
copy_directory_from_repo data "$pdir" local bindir="$pdir"
cp "$build/src/lite" "$pdir" local datadir="$pdir/data"
strip "$pdir/lite" 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" pushd ".package-build"
local package_name="lite-xl-$os-$arch.tar.gz" local package_name="lite-xl-$os-$arch.tar.gz"
tar czf "$package_name" "lite-xl" tar czf "$package_name" "lite-xl"
@ -113,7 +148,7 @@ lite_build_package () {
} }
if [[ -z "$1" || -z "$2" ]]; then if [[ -z "$1" || -z "$2" ]]; then
echo "usage: $0 <version> <arch>" echo "usage: $0 [options] <version> <arch>"
exit 1 exit 1
fi fi
@ -122,14 +157,20 @@ if [[ "$1" == "-pgo" ]]; then
shift shift
fi fi
portable="false"
if [ "$1" == "-portable" ]; then
portable="true"
shift
fi
version="$1" version="$1"
arch="$2" arch="$2"
build_dir=".build-$arch" build_dir=".build-$arch"
if [ -z ${pgo+set} ]; then if [ -z ${pgo+set} ]; then
lite_build "$build_dir" lite_build "$portable" "$build_dir"
else else
lite_build_pgo "$build_dir" lite_build_pgo "$portable" "$build_dir"
fi fi
lite_build_package "$build_dir" "$version" "$arch" lite_build_package "$portable" "$build_dir" "$version" "$arch"

View File

@ -1,6 +1,10 @@
#!/bin/bash #!/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)" cflags+=" $(pkg-config --cflags lua5.2) $(sdl2-config --cflags)"
lflags="-static-libgcc -static-libstdc++" lflags="-static-libgcc -static-libstdc++"
for package in libagg freetype2 lua5.2; do for package in libagg freetype2 lua5.2; do

View File

@ -15,7 +15,7 @@ endif
sdl_dep = dependency('sdl2', method: 'config-tool') sdl_dep = dependency('sdl2', method: 'config-tool')
lite_cargs = [] lite_cargs = []
if host_machine.system() == 'windows' if get_option('portable')
lite_cargs += ['-DLITE_XL_DATA_USE_EXEDIR'] lite_cargs += ['-DLITE_XL_DATA_USE_EXEDIR']
endif endif

View File

@ -129,9 +129,13 @@ int main(int argc, char **argv) {
#else #else
" do\n" " do\n"
" local prefix = EXEDIR:match(\"^(.+)[/\\\\]bin$\")\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" " 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" " end\n"
" package.path = package.path .. ';' .. USERDIR .. '/?.lua'\n" " package.path = package.path .. ';' .. USERDIR .. '/?.lua'\n"
" package.path = package.path .. ';' .. USERDIR .. '/?/init.lua'\n" " package.path = package.path .. ';' .. USERDIR .. '/?/init.lua'\n"