mirror of
https://github.com/NixOS/patchelf.git
synced 2025-10-19 19:53:19 +08:00
Add CMake build
Co-Authored-by: John Ericson <John.Ericson@Obsidian.Systems>
This commit is contained in:

committed by
John Ericson

parent
f8621b633a
commit
51cf74ce10
2
.gitignore
vendored
2
.gitignore
vendored
@@ -18,6 +18,8 @@ Makefile
|
|||||||
.deps
|
.deps
|
||||||
*.o
|
*.o
|
||||||
|
|
||||||
|
CMakeLists.txt.user
|
||||||
|
|
||||||
/tests/*.log
|
/tests/*.log
|
||||||
/tests/*.trs
|
/tests/*.trs
|
||||||
/tests/no-rpath
|
/tests/no-rpath
|
||||||
|
31
CMakeLists.txt
Normal file
31
CMakeLists.txt
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
|
||||||
|
project(patchelf)
|
||||||
|
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
|
||||||
|
set(PAGESIZE 4096)
|
||||||
|
|
||||||
|
set(ADDITIONAL_HEADERS src/elf.h)
|
||||||
|
|
||||||
|
set(SOURCES src/patchelf.cc)
|
||||||
|
|
||||||
|
file(READ version VERSION)
|
||||||
|
|
||||||
|
add_executable(${PROJECT_NAME} ${SOURCES} ${ADDITIONAL_HEADERS})
|
||||||
|
|
||||||
|
target_compile_definitions(
|
||||||
|
patchelf PRIVATE PAGESIZE=${PAGESIZE}
|
||||||
|
PACKAGE_STRING="patchelf ${VERSION_STRING}")
|
||||||
|
|
||||||
|
install(TARGETS patchelf RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||||
|
|
||||||
|
install(FILES patchelf.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
|
||||||
|
|
||||||
|
install(FILES README.md DESTINATION ${CMAKE_INSTALL_DOCDIR})
|
||||||
|
|
||||||
|
install(FILES completions/zsh/_patchelf
|
||||||
|
DESTINATION ${CMAKE_INSTALL_DATADIR}/zsh/site-functions)
|
12
README.md
12
README.md
@@ -72,7 +72,7 @@ libraries. In particular, it can do the following:
|
|||||||
|
|
||||||
## Compiling and Testing
|
## Compiling and Testing
|
||||||
|
|
||||||
### Via Autotools
|
### Via [GNU Autotools](https://www.gnu.org/software/automake/manual/html_node/Autotools-Introduction.html)
|
||||||
```console
|
```console
|
||||||
./bootstrap.sh
|
./bootstrap.sh
|
||||||
./configure
|
./configure
|
||||||
@@ -81,6 +81,16 @@ make check
|
|||||||
sudo make install
|
sudo make install
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Via [CMake](https://cmake.org/) (and [Ninja](https://ninja-build.org/))
|
||||||
|
|
||||||
|
```console
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake .. -GNinja
|
||||||
|
ninja all
|
||||||
|
sudo ninja install
|
||||||
|
```
|
||||||
|
|
||||||
### Via Nix
|
### Via Nix
|
||||||
|
|
||||||
You can build with Nix in several ways.
|
You can build with Nix in several ways.
|
||||||
|
68
flake.nix
68
flake.nix
@@ -30,27 +30,37 @@
|
|||||||
version = lib.removeSuffix "\n" (builtins.readFile ./version);
|
version = lib.removeSuffix "\n" (builtins.readFile ./version);
|
||||||
pkgs = nixpkgs.legacyPackages.x86_64-linux;
|
pkgs = nixpkgs.legacyPackages.x86_64-linux;
|
||||||
|
|
||||||
src = lib.fileset.toSource {
|
baseSrcFiles = [
|
||||||
|
./COPYING
|
||||||
|
./README.md
|
||||||
|
./completions
|
||||||
|
./patchelf.1
|
||||||
|
./patchelf.spec.in
|
||||||
|
./src
|
||||||
|
./tests
|
||||||
|
./version
|
||||||
|
];
|
||||||
|
|
||||||
|
autotoolsSrcFiles = [
|
||||||
|
./Makefile.am
|
||||||
|
./configure.ac
|
||||||
|
./m4
|
||||||
|
];
|
||||||
|
|
||||||
|
cmakeSrcFiles = [
|
||||||
|
./CMakeLists.txt
|
||||||
|
];
|
||||||
|
|
||||||
|
autotoolsSrc = lib.fileset.toSource {
|
||||||
root = ./.;
|
root = ./.;
|
||||||
fileset = lib.fileset.unions [
|
fileset = lib.fileset.unions (baseSrcFiles ++ autotoolsSrcFiles);
|
||||||
./COPYING
|
|
||||||
./Makefile.am
|
|
||||||
./README.md
|
|
||||||
./completions
|
|
||||||
./configure.ac
|
|
||||||
./m4
|
|
||||||
./patchelf.1
|
|
||||||
./patchelf.spec.in
|
|
||||||
./src
|
|
||||||
./tests
|
|
||||||
./version
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
patchelfFor =
|
patchelfFor =
|
||||||
pkgs:
|
pkgs:
|
||||||
pkgs.callPackage ./package.nix {
|
pkgs.callPackage ./package-autotools.nix {
|
||||||
inherit version src;
|
inherit version;
|
||||||
|
src = autotoolsSrc;
|
||||||
};
|
};
|
||||||
|
|
||||||
# We don't apply flake-parts to the whole flake so that non-development attributes
|
# We don't apply flake-parts to the whole flake so that non-development attributes
|
||||||
@@ -76,7 +86,11 @@
|
|||||||
hydraJobs = {
|
hydraJobs = {
|
||||||
tarball = pkgs.releaseTools.sourceTarball rec {
|
tarball = pkgs.releaseTools.sourceTarball rec {
|
||||||
name = "patchelf-tarball";
|
name = "patchelf-tarball";
|
||||||
inherit version src;
|
inherit version;
|
||||||
|
src = lib.fileset.toSource {
|
||||||
|
root = ./.;
|
||||||
|
fileset = lib.fileset.unions (baseSrcFiles ++ autotoolsSrcFiles ++ cmakeSrcFiles);
|
||||||
|
};
|
||||||
versionSuffix = ""; # obsolete
|
versionSuffix = ""; # obsolete
|
||||||
preAutoconf = "echo ${version} > version";
|
preAutoconf = "echo ${version} > version";
|
||||||
|
|
||||||
@@ -117,6 +131,8 @@
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
build-cmake = forAllSystems (system: self.packages.${system}.patchelf-cmake);
|
||||||
|
|
||||||
# x86_64-linux seems to be only working clangStdenv at the moment
|
# x86_64-linux seems to be only working clangStdenv at the moment
|
||||||
build-sanitized-clang = lib.genAttrs [ "x86_64-linux" ] (
|
build-sanitized-clang = lib.genAttrs [ "x86_64-linux" ] (
|
||||||
system:
|
system:
|
||||||
@@ -134,6 +150,7 @@
|
|||||||
self.hydraJobs.tarball
|
self.hydraJobs.tarball
|
||||||
self.hydraJobs.build.x86_64-linux
|
self.hydraJobs.build.x86_64-linux
|
||||||
self.hydraJobs.build.i686-linux
|
self.hydraJobs.build.i686-linux
|
||||||
|
self.hydraJobs.build-cmake.x86_64-linux
|
||||||
# FIXME: add aarch64 emulation to our github action...
|
# FIXME: add aarch64 emulation to our github action...
|
||||||
#self.hydraJobs.build.aarch64-linux
|
#self.hydraJobs.build.aarch64-linux
|
||||||
self.hydraJobs.build-sanitized.x86_64-linux
|
self.hydraJobs.build-sanitized.x86_64-linux
|
||||||
@@ -172,8 +189,10 @@
|
|||||||
}";
|
}";
|
||||||
};
|
};
|
||||||
nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [
|
nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [
|
||||||
|
#pkgs.buildPackages.cmake
|
||||||
|
#pkgs.buildPackages.ninja
|
||||||
modular.pre-commit.settings.package
|
modular.pre-commit.settings.package
|
||||||
(pkgs.writeScriptBin "pre-commit-hooks-install" modular.pre-commit.settings.installationScript)
|
(pkgs.buildPackages.writeScriptBin "pre-commit-hooks-install" modular.pre-commit.settings.installationScript)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -194,8 +213,9 @@
|
|||||||
|
|
||||||
patchelfForWindowsStatic =
|
patchelfForWindowsStatic =
|
||||||
pkgs:
|
pkgs:
|
||||||
(pkgs.callPackage ./package.nix {
|
(pkgs.callPackage ./package-autotools.nix {
|
||||||
inherit version src;
|
inherit version;
|
||||||
|
src = autotoolsSrc;
|
||||||
# On windows we use win32 threads to get a static binary,
|
# On windows we use win32 threads to get a static binary,
|
||||||
# otherwise `-static` below doesn't work.
|
# otherwise `-static` below doesn't work.
|
||||||
stdenv = pkgs.stdenv.override (old: {
|
stdenv = pkgs.stdenv.override (old: {
|
||||||
@@ -217,6 +237,14 @@
|
|||||||
patchelf = patchelfFor pkgs;
|
patchelf = patchelfFor pkgs;
|
||||||
default = self.packages.${system}.patchelf;
|
default = self.packages.${system}.patchelf;
|
||||||
|
|
||||||
|
patchelf-cmake = pkgs.callPackage ./package-cmake.nix {
|
||||||
|
inherit version;
|
||||||
|
src = lib.fileset.toSource {
|
||||||
|
root = ./.;
|
||||||
|
fileset = lib.fileset.unions (baseSrcFiles ++ cmakeSrcFiles);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
# This is a good test to see if packages can be cross-compiled. It also
|
# This is a good test to see if packages can be cross-compiled. It also
|
||||||
# tests if our testsuite uses target-prefixed executable names.
|
# tests if our testsuite uses target-prefixed executable names.
|
||||||
patchelf-musl-cross = patchelfFor pkgs.pkgsCross.musl64;
|
patchelf-musl-cross = patchelfFor pkgs.pkgsCross.musl64;
|
||||||
|
@@ -37,6 +37,9 @@
|
|||||||
fi
|
fi
|
||||||
''}";
|
''}";
|
||||||
};
|
};
|
||||||
|
cmake-format = {
|
||||||
|
enable = true;
|
||||||
|
};
|
||||||
nixfmt-rfc-style = {
|
nixfmt-rfc-style = {
|
||||||
enable = true;
|
enable = true;
|
||||||
};
|
};
|
||||||
|
17
package-cmake.nix
Normal file
17
package-cmake.nix
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
stdenv,
|
||||||
|
cmake,
|
||||||
|
ninja,
|
||||||
|
version,
|
||||||
|
src,
|
||||||
|
}:
|
||||||
|
|
||||||
|
stdenv.mkDerivation {
|
||||||
|
pname = "patchelf";
|
||||||
|
inherit version src;
|
||||||
|
nativeBuildInputs = [
|
||||||
|
cmake
|
||||||
|
ninja
|
||||||
|
];
|
||||||
|
doCheck = true;
|
||||||
|
}
|
Reference in New Issue
Block a user