-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathMakefile
More file actions
120 lines (102 loc) · 3.33 KB
/
Makefile
File metadata and controls
120 lines (102 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
PROJECT_NAME := crc_fast
# Detect operating system
UNAME_S := $(shell uname -s)
# Determine OS-specific variables
ifeq ($(UNAME_S),Linux)
DESTDIR ?= /usr/local
LIB_EXTENSION := so
STATIC_LIB_EXTENSION := a
INSTALL_LIB_DIR := /lib
INSTALL_BIN_DIR := /bin
INSTALL_INCLUDE_DIR := /include
POST_INSTALL := ldconfig
else ifeq ($(UNAME_S),Darwin)
DESTDIR ?=
# on macOS, there's not really a default location, so require DESTDIR
ifeq ($(DESTDIR),)
$(error On macOS, DESTDIR must be set for installation. Common locations include /usr/local or /opt/homebrew)
endif
LIB_EXTENSION := dylib
STATIC_LIB_EXTENSION := a
INSTALL_LIB_DIR := /lib
INSTALL_BIN_DIR := /bin
INSTALL_INCLUDE_DIR := /include
POST_INSTALL := true
else
# Windows
DESTDIR ?=
ifeq ($(DESTDIR),)
$(error On Windows, DESTDIR must be set for installation. Common locations include C:\)
endif
LIB_EXTENSION := dll
STATIC_LIB_EXTENSION := lib
# Use relative paths when DESTDIR is set to avoid path joining issues
PREFIX ?= Program Files\\$(PROJECT_NAME)
INSTALL_LIB_DIR := $(PREFIX)\\bin
INSTALL_BIN_DIR := $(PREFIX)\\bin
INSTALL_INCLUDE_DIR := $(PREFIX)\\include
POST_INSTALL := true
endif
# Library name with extension
LIB_NAME := lib$(PROJECT_NAME).$(LIB_EXTENSION)
STATIC_LIB_NAME := lib$(PROJECT_NAME).$(STATIC_LIB_EXTENSION)
# CLI binaries
CLI_BINARIES := checksum arch-check get-custom-params
# Default target
.PHONY: all
all: build
# Build the library using Cargo
.PHONY: build
build: test
cargo build --all-features --release
# Test the library using Cargo
.PHONY: test
test:
cargo test --all-features
# Install the library and headers
.PHONY: install
install: print-paths build
@install -d $(DESTDIR)$(INSTALL_LIB_DIR)
@install -d $(DESTDIR)$(INSTALL_BIN_DIR)
@install -d $(DESTDIR)$(INSTALL_INCLUDE_DIR)
install -m 644 target/release/$(LIB_NAME) $(DESTDIR)$(INSTALL_LIB_DIR)/
install -m 644 target/release/$(STATIC_LIB_NAME) $(DESTDIR)$(INSTALL_LIB_DIR)/
install -m 644 lib$(PROJECT_NAME).h $(DESTDIR)$(INSTALL_INCLUDE_DIR)/
@for bin in $(CLI_BINARIES); do \
install -m 755 target/release/$$bin $(DESTDIR)$(INSTALL_BIN_DIR)/; \
done
@if [ -z "$(DESTDIR)" ] && [ "$(POST_INSTALL)" != "true" ]; then \
$(POST_INSTALL); \
fi
# Uninstall the library and headers
.PHONY: uninstall
uninstall: print-paths
rm -f $(DESTDIR)$(INSTALL_LIB_DIR)/$(LIB_NAME)
rm -f $(DESTDIR)$(INSTALL_LIB_DIR)/$(STATIC_LIB_NAME)
rm -f $(DESTDIR)$(INSTALL_INCLUDE_DIR)/lib$(PROJECT_NAME).h
@for bin in $(CLI_BINARIES); do \
rm -f $(DESTDIR)$(INSTALL_BIN_DIR)/$$bin; \
done
@if [ -z "$(DESTDIR)" ] && [ "$(UNAME_S)" = "Linux" ]; then \
ldconfig; \
fi
# Run all code quality checks
.PHONY: check
check:
cargo fmt --all
cargo check --workspace --all-targets --all-features
cargo clippy --workspace --all-targets --all-features --fix --allow-dirty -- -D warnings
# cargo deny check all
# RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --all-features
# cargo audit
# Clean build artifacts
.PHONY: clean
clean:
cargo clean
# Print installation paths (useful for debugging)
.PHONY: print-paths
print-paths:
@echo "Installation paths:"
@echo "Library dir: $(DESTDIR)$(INSTALL_LIB_DIR)"
@echo "Binary dir: $(DESTDIR)$(INSTALL_BIN_DIR)"
@echo "Include dir: $(DESTDIR)$(INSTALL_INCLUDE_DIR)"