Skip to content

Commit 01dcf63

Browse files
Copiloterikd
andcommitted
Build static lib only, use INSTALL env var, generate pkg-config from template
Co-authored-by: erikd <307277+erikd@users.noreply.github.com>
1 parent 1a5821f commit 01dcf63

File tree

3 files changed

+32
-28
lines changed

3 files changed

+32
-28
lines changed

Makefile

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -48,37 +48,30 @@ ci: fmt-check clippy test
4848

4949
# Generate pkg-config file
5050
pkgconfig: build-release
51+
@if [ -z "$$INSTALL" ]; then \
52+
echo "Error: INSTALL environment variable is not set."; \
53+
echo "Please set INSTALL to the installation directory, e.g.: export INSTALL=/usr/local"; \
54+
exit 1; \
55+
fi
5156
@mkdir -p rust_accumulator/target/pkgconfig
5257
@VERSION=$$(grep '^version' rust_accumulator/Cargo.toml | head -1 | cut -d'"' -f2); \
53-
echo "prefix=/usr/local" > rust_accumulator/target/pkgconfig/librust_accumulator.pc; \
54-
echo "exec_prefix=\$${prefix}" >> rust_accumulator/target/pkgconfig/librust_accumulator.pc; \
55-
echo "libdir=\$${exec_prefix}/lib" >> rust_accumulator/target/pkgconfig/librust_accumulator.pc; \
56-
echo "includedir=\$${prefix}/include" >> rust_accumulator/target/pkgconfig/librust_accumulator.pc; \
57-
echo "" >> rust_accumulator/target/pkgconfig/librust_accumulator.pc; \
58-
echo "Name: librust_accumulator" >> rust_accumulator/target/pkgconfig/librust_accumulator.pc; \
59-
echo "Description: A rust based lib for a PCS based accumulator" >> rust_accumulator/target/pkgconfig/librust_accumulator.pc; \
60-
echo "Version: $$VERSION" >> rust_accumulator/target/pkgconfig/librust_accumulator.pc; \
61-
echo "" >> rust_accumulator/target/pkgconfig/librust_accumulator.pc; \
62-
echo "Cflags: -I\$${includedir}" >> rust_accumulator/target/pkgconfig/librust_accumulator.pc; \
63-
echo "Libs: -L\$${libdir} -lrust_accumulator" >> rust_accumulator/target/pkgconfig/librust_accumulator.pc
58+
sed -e "s|@PREFIX@|$$INSTALL|g" -e "s|@VERSION@|$$VERSION|g" \
59+
librust_accumulator.pc.in > rust_accumulator/target/pkgconfig/librust_accumulator.pc
6460
@echo "pkg-config file created at rust_accumulator/target/pkgconfig/librust_accumulator.pc"
6561

66-
# Install library and pkg-config file (requires sudo for system-wide install)
62+
# Install library and pkg-config file
6763
install: build-release pkgconfig
68-
@echo "Installing to prefix: $${PREFIX:-/usr/local}"
69-
install -d $${PREFIX:-/usr/local}/lib
70-
@if [ -f rust_accumulator/target/release/librust_accumulator.so ]; then \
71-
install -m 755 rust_accumulator/target/release/librust_accumulator.so $${PREFIX:-/usr/local}/lib/; \
72-
elif [ -f rust_accumulator/target/release/librust_accumulator.dylib ]; then \
73-
install -m 755 rust_accumulator/target/release/librust_accumulator.dylib $${PREFIX:-/usr/local}/lib/; \
74-
elif [ -f rust_accumulator/target/release/librust_accumulator.dll ]; then \
75-
install -m 755 rust_accumulator/target/release/librust_accumulator.dll $${PREFIX:-/usr/local}/lib/; \
76-
else \
77-
echo "Error: No library file found"; exit 1; \
64+
@if [ -z "$$INSTALL" ]; then \
65+
echo "Error: INSTALL environment variable is not set."; \
66+
echo "Please set INSTALL to the installation directory, e.g.: export INSTALL=/usr/local"; \
67+
exit 1; \
7868
fi
79-
install -d $${PREFIX:-/usr/local}/lib/pkgconfig
80-
install -m 644 rust_accumulator/target/pkgconfig/librust_accumulator.pc $${PREFIX:-/usr/local}/lib/pkgconfig/
81-
@echo "Installation complete. Library installed to $${PREFIX:-/usr/local}/lib/"
69+
@echo "Installing to: $$INSTALL"
70+
install -d $$INSTALL/lib
71+
install -m 644 rust_accumulator/target/release/librust_accumulator.a $$INSTALL/lib/
72+
install -d $$INSTALL/lib/pkgconfig
73+
install -m 644 rust_accumulator/target/pkgconfig/librust_accumulator.pc $$INSTALL/lib/pkgconfig/
74+
@echo "Installation complete. Library installed to $$INSTALL/lib/"
8275

8376
# Show help
8477
help:
@@ -95,6 +88,6 @@ help:
9588
@echo " doc - Build documentation"
9689
@echo " doc-open - Build and open documentation in browser"
9790
@echo " ci - Run all checks (format, clippy, test)"
98-
@echo " pkgconfig - Generate pkg-config file"
99-
@echo " install - Install library and pkg-config file (use PREFIX=/path to customize)"
91+
@echo " pkgconfig - Generate pkg-config file (requires INSTALL env var)"
92+
@echo " install - Install library and pkg-config file (requires INSTALL env var)"
10093
@echo " help - Show this help message"

librust_accumulator.pc.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
prefix=@PREFIX@
2+
exec_prefix=${prefix}
3+
libdir=${exec_prefix}/lib
4+
includedir=${prefix}/include
5+
6+
Name: librust_accumulator
7+
Description: A rust based lib for a PCS based accumulator
8+
Version: @VERSION@
9+
10+
Cflags: -I${includedir}
11+
Libs: -L${libdir} -lrust_accumulator

rust_accumulator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2018"
55

66
[lib]
77
name = "rust_accumulator"
8-
crate-type = ["cdylib", "rlib"]
8+
crate-type = ["staticlib"]
99

1010
[dependencies]
1111
blstrs = "0.7.1"

0 commit comments

Comments
 (0)