Skip to content

Commit 5f5ced8

Browse files
committed
Improve Makefile
- Builds all the features - Installs static library - Installs CLI binaries
1 parent 41279ef commit 5f5ced8

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

Makefile

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ UNAME_S := $(shell uname -s)
77
ifeq ($(UNAME_S),Linux)
88
DESTDIR ?= /usr/local
99
LIB_EXTENSION := so
10+
STATIC_LIB_EXTENSION := a
1011
INSTALL_LIB_DIR := /lib
12+
INSTALL_BIN_DIR := /bin
1113
INSTALL_INCLUDE_DIR := /include
1214
POST_INSTALL := ldconfig
1315
else ifeq ($(UNAME_S),Darwin)
@@ -17,7 +19,9 @@ else ifeq ($(UNAME_S),Darwin)
1719
$(error On macOS, DESTDIR must be set for installation. Common locations include /usr/local or /opt/homebrew)
1820
endif
1921
LIB_EXTENSION := dylib
22+
STATIC_LIB_EXTENSION := a
2023
INSTALL_LIB_DIR := /lib
24+
INSTALL_BIN_DIR := /bin
2125
INSTALL_INCLUDE_DIR := /include
2226
POST_INSTALL := true
2327
else
@@ -27,15 +31,21 @@ else
2731
$(error On Windows, DESTDIR must be set for installation. Common locations include C:\)
2832
endif
2933
LIB_EXTENSION := dll
34+
STATIC_LIB_EXTENSION := lib
3035
# Use relative paths when DESTDIR is set to avoid path joining issues
3136
PREFIX ?= Program Files\\$(PROJECT_NAME)
3237
INSTALL_LIB_DIR := $(PREFIX)\\bin
38+
INSTALL_BIN_DIR := $(PREFIX)\\bin
3339
INSTALL_INCLUDE_DIR := $(PREFIX)\\include
3440
POST_INSTALL := true
3541
endif
3642

3743
# Library name with extension
3844
LIB_NAME := lib$(PROJECT_NAME).$(LIB_EXTENSION)
45+
STATIC_LIB_NAME := lib$(PROJECT_NAME).$(STATIC_LIB_EXTENSION)
46+
47+
# CLI binaries
48+
CLI_BINARIES := checksum arch-check get-custom-params
3949

4050
# Default target
4151
.PHONY: all
@@ -44,23 +54,29 @@ all: build
4454
# Build the library using Cargo
4555
.PHONY: build
4656
build: test
47-
cargo build --release
57+
cargo build --all-features --release
4858

4959
# Test the library using Cargo
5060
.PHONY: test
5161
test:
52-
cargo test
62+
cargo test --all-features
5363

5464
# Install the library and headers
5565
.PHONY: install
5666
install: print-paths build
5767
@install -d $(DESTDIR)$(INSTALL_LIB_DIR)
68+
@install -d $(DESTDIR)$(INSTALL_BIN_DIR)
5869
@install -d $(DESTDIR)$(INSTALL_INCLUDE_DIR)
5970

6071
install -m 644 target/release/$(LIB_NAME) $(DESTDIR)$(INSTALL_LIB_DIR)/
72+
install -m 644 target/release/$(STATIC_LIB_NAME) $(DESTDIR)$(INSTALL_LIB_DIR)/
6173

6274
install -m 644 lib$(PROJECT_NAME).h $(DESTDIR)$(INSTALL_INCLUDE_DIR)/
6375

76+
@for bin in $(CLI_BINARIES); do \
77+
install -m 755 target/release/$$bin $(DESTDIR)$(INSTALL_BIN_DIR)/; \
78+
done
79+
6480
@if [ -z "$(DESTDIR)" ] && [ "$(POST_INSTALL)" != "true" ]; then \
6581
$(POST_INSTALL); \
6682
fi
@@ -69,8 +85,13 @@ install: print-paths build
6985
.PHONY: uninstall
7086
uninstall: print-paths
7187
rm -f $(DESTDIR)$(INSTALL_LIB_DIR)/$(LIB_NAME)
88+
rm -f $(DESTDIR)$(INSTALL_LIB_DIR)/$(STATIC_LIB_NAME)
7289
rm -f $(DESTDIR)$(INSTALL_INCLUDE_DIR)/lib$(PROJECT_NAME).h
7390

91+
@for bin in $(CLI_BINARIES); do \
92+
rm -f $(DESTDIR)$(INSTALL_BIN_DIR)/$$bin; \
93+
done
94+
7495
@if [ -z "$(DESTDIR)" ] && [ "$(UNAME_S)" = "Linux" ]; then \
7596
ldconfig; \
7697
fi
@@ -85,4 +106,5 @@ clean:
85106
print-paths:
86107
@echo "Installation paths:"
87108
@echo "Library dir: $(DESTDIR)$(INSTALL_LIB_DIR)"
109+
@echo "Binary dir: $(DESTDIR)$(INSTALL_BIN_DIR)"
88110
@echo "Include dir: $(DESTDIR)$(INSTALL_INCLUDE_DIR)"

0 commit comments

Comments
 (0)