Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Makefile
.deps
*.o

CMakeLists.txt.user

/tests/*.log
/tests/*.trs
/tests/no-rpath
Expand Down
31 changes: 31 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ libraries. In particular, it can do the following:

## Compiling and Testing

### Via Autotools
### Via [GNU Autotools](https://www.gnu.org/software/automake/manual/html_node/Autotools-Introduction.html)
```console
./bootstrap.sh
./configure
Expand All @@ -81,6 +81,16 @@ make check
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

You can build with Nix in several ways.
Expand Down
68 changes: 48 additions & 20 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,37 @@
version = lib.removeSuffix "\n" (builtins.readFile ./version);
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 = ./.;
fileset = lib.fileset.unions [
./COPYING
./Makefile.am
./README.md
./completions
./configure.ac
./m4
./patchelf.1
./patchelf.spec.in
./src
./tests
./version
];
fileset = lib.fileset.unions (baseSrcFiles ++ autotoolsSrcFiles);
};

patchelfFor =
pkgs:
pkgs.callPackage ./package.nix {
inherit version src;
pkgs.callPackage ./package-autotools.nix {
inherit version;
src = autotoolsSrc;
};

# We don't apply flake-parts to the whole flake so that non-development attributes
Expand All @@ -76,7 +86,11 @@
hydraJobs = {
tarball = pkgs.releaseTools.sourceTarball rec {
name = "patchelf-tarball";
inherit version src;
inherit version;
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions (baseSrcFiles ++ autotoolsSrcFiles ++ cmakeSrcFiles);
};
versionSuffix = ""; # obsolete
preAutoconf = "echo ${version} > version";

Expand Down Expand Up @@ -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
build-sanitized-clang = lib.genAttrs [ "x86_64-linux" ] (
system:
Expand All @@ -134,6 +150,7 @@
self.hydraJobs.tarball
self.hydraJobs.build.x86_64-linux
self.hydraJobs.build.i686-linux
self.hydraJobs.build-cmake.x86_64-linux
# FIXME: add aarch64 emulation to our github action...
#self.hydraJobs.build.aarch64-linux
self.hydraJobs.build-sanitized.x86_64-linux
Expand Down Expand Up @@ -172,8 +189,10 @@
}";
};
nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [
#pkgs.buildPackages.cmake
#pkgs.buildPackages.ninja
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)
];
}
);
Expand All @@ -194,8 +213,9 @@

patchelfForWindowsStatic =
pkgs:
(pkgs.callPackage ./package.nix {
inherit version src;
(pkgs.callPackage ./package-autotools.nix {
inherit version;
src = autotoolsSrc;
# On windows we use win32 threads to get a static binary,
# otherwise `-static` below doesn't work.
stdenv = pkgs.stdenv.override (old: {
Expand All @@ -217,6 +237,14 @@
patchelf = patchelfFor pkgs;
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
# tests if our testsuite uses target-prefixed executable names.
patchelf-musl-cross = patchelfFor pkgs.pkgsCross.musl64;
Expand Down
3 changes: 3 additions & 0 deletions maintainers/flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
fi
''}";
};
cmake-format = {
enable = true;
};
nixfmt-rfc-style = {
enable = true;
};
Expand Down
File renamed without changes.
17 changes: 17 additions & 0 deletions package-cmake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
stdenv,
cmake,
ninja,
version,
src,
}:

stdenv.mkDerivation {
pname = "patchelf";
inherit version src;
nativeBuildInputs = [
cmake
ninja
];
doCheck = true;
}
Loading