From c70790bf627b45704abda33e643d0830f13ab17d Mon Sep 17 00:00:00 2001 From: apio Date: Mon, 24 Jul 2023 18:50:51 +0200 Subject: [PATCH] ports: Add some defaults for CMake projects as well --- ports/README.md | 21 +++++++++------------ ports/minitar/PACKAGE | 14 ++++---------- tools/make-package.sh | 9 ++++++++- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/ports/README.md b/ports/README.md index 38d78850..65cad69f 100644 --- a/ports/README.md +++ b/ports/README.md @@ -113,8 +113,9 @@ do_configure() The first two flags `--host=$LUNA_ARCH-luna --prefix=/usr` are required if using a standard configure script, to indicate that we're cross-compiling (compiling the program for another system). Alternatively, you can simply set `use_default_configure=true` without a `do_configure` function, which will simply run the configure script with these two flags, if you don't need anything else. +If using CMake and not needing any extra parameters, setting `use_cmake_configure=true` will have the same effect. -This function is required (unless setting `use_default_configure` to `true`), if you don't need it you can simply make it an empty function. +This function is required (unless setting `use_default_configure` or `use_cmake_configure` to `true`), if you don't need it you can simply make it an empty function. #### Building This step is self-explanatory, and is done using the `do_build` function. @@ -131,6 +132,7 @@ As always, you can refer to the source directory with `srcdir`. If you're using make, you can use the variable `MAKEJOBS` to run the build process in parallel. Alternatively, if you're invoking make without any specific parameters, you can set `default_build_make=true` and skip the `do_build` function. This is the equivalent of doing `make -j$MAKEJOBS`. +Alternatively, if using CMake, you can set `default_build_cmake=true` to do the same thing. In any other case, the `do_build` function is required. @@ -151,6 +153,7 @@ do_install() } ``` If you're invoking `make install` without any specific parameters, you can set `default_install_make=true` and skip the `do_install` function. +If the project uses CMake and you don't need to pass any extra parameters, you can set `default_install_cmake=true`. In any other case, the `do_install` function is required. @@ -168,28 +171,22 @@ url="https://git.cloudapio.eu/apio/minitar.git" tag="$version" # Build instructions -do_configure() -{ - cmake -S $srcdir -B $builddir -DCMAKE_C_COMPILER=$LUNA_ARCH-luna-gcc -} +use_cmake_configure=true do_build() { # Also build the examples - cmake --build $builddir --target examples + cmake --build . --target examples } do_install() { - mkdir -p $installdir/usr/lib/ - cp $builddir/libmtar.a $installdir/usr/lib/ + cmake --install . --prefix /usr mkdir -p $installdir/usr/bin/ - cp $builddir/examples/pack $builddir/examples/untar $builddir/examples/list $installdir/usr/bin/ - mkdir -p $installdir/usr/include/ - cp $srcdir/minitar.h $installdir/usr/include/ + cp examples/pack examples/untar examples/list $installdir/usr/bin/ } ``` -This port is downloaded using git and built using cmake. Since the defaults are geared towards make, all the functions must be defined. The `do_install` function is a bit manual because cmake is a bit more complicated. +This port is downloaded using git and built using cmake. Since we're building some extra components, `do_build` and `do_install` cannot be set to the default. #### nasm ``` diff --git a/ports/minitar/PACKAGE b/ports/minitar/PACKAGE index 93c35566..a338f78f 100644 --- a/ports/minitar/PACKAGE +++ b/ports/minitar/PACKAGE @@ -8,23 +8,17 @@ url="https://git.cloudapio.eu/apio/minitar.git" tag="$version" # Build instructions -do_configure() -{ - cmake -S $srcdir -B $builddir -DCMAKE_C_COMPILER=$LUNA_ARCH-luna-gcc -} +use_cmake_configure=true do_build() { # Also build the examples - cmake --build $builddir --target examples + cmake --build . --target examples } do_install() { - mkdir -p $installdir/usr/lib/ - cp $builddir/libmtar.a $installdir/usr/lib/ + cmake --install . --prefix /usr mkdir -p $installdir/usr/bin/ - cp $builddir/examples/pack $builddir/examples/untar $builddir/examples/list $installdir/usr/bin/ - mkdir -p $installdir/usr/include/ - cp $srcdir/minitar.h $installdir/usr/include/ + cp examples/pack examples/untar examples/list $installdir/usr/bin/ } diff --git a/tools/make-package.sh b/tools/make-package.sh index 0110c73e..4d78afba 100755 --- a/tools/make-package.sh +++ b/tools/make-package.sh @@ -70,8 +70,10 @@ echo "Configuring $name..." if [ "$use_default_configure" = "true" ]; then $srcdir/configure --host=$LUNA_ARCH-luna --prefix=/usr +elif [ "$use_cmake_configure" = "true" ]; then + cmake -S $srcdir -B . -DCMAKE_C_COMPILER=$LUNA_ARCH-luna-gcc -DCMAKE_CXX_COMPILER=$LUNA_ARCH-luna-g++ -G "Unix Makefiles" else - declare -F do_configure &>/dev/null || show_error "error: If not using the default configure line, the PACKAGE file must provide a 'do_configure' function." + declare -F do_configure &>/dev/null || show_error "error: If not using a default configure line, the PACKAGE file must provide a 'do_configure' function." do_configure fi @@ -81,6 +83,8 @@ export MAKEJOBS=$(nproc) if [ "$default_build_make" = "true" ]; then make -j$MAKEJOBS +elif [ "$default_build_cmake" = "true" ]; then + cmake --build . else declare -F do_build &>/dev/null || show_error "error: If not using a default build preset, the PACKAGE file must provide a 'do_build' function." do_build @@ -88,10 +92,13 @@ fi echo "Installing $name..." +mkdir -p $installdir export DESTDIR=$installdir if [ "$default_install_make" = "true" ]; then make install +elif [ "$default_install_cmake" = "true" ]; then + cmake --install $builddir --prefix /usr else declare -F do_install &>/dev/null || show_error "error: If not using a default install preset, the PACKAGE file must provide a 'do_install' function." do_install