Debian Codegraph @

debian/rust-vendor/crc-fast/Makefile

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