Skip to content

Commit 3a751e0

Browse files
committed
Add Makefile
1 parent 8a8de87 commit 3a751e0

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

Makefile

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
PROJECT_NAME := crc32fast
2+
3+
# Detect operating system
4+
UNAME_S := $(shell uname -s)
5+
6+
# Allow override of installation directory
7+
DESTDIR ?=
8+
9+
# Determine OS-specific variables
10+
ifeq ($(UNAME_S),Linux)
11+
LIB_EXTENSION := so
12+
INSTALL_LIB_DIR := $(PREFIX)/lib
13+
INSTALL_INCLUDE_DIR := $(PREFIX)/include
14+
POST_INSTALL := ldconfig
15+
else ifeq ($(UNAME_S),Darwin)
16+
LIB_EXTENSION := dylib
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)
20+
endif
21+
INSTALL_LIB_DIR := /lib
22+
INSTALL_INCLUDE_DIR := /include
23+
POST_INSTALL := true
24+
else
25+
# Windows
26+
LIB_EXTENSION := dll
27+
ifeq ($(DESTDIR),)
28+
$(error On Windows, DESTDIR must be set for installation)
29+
endif
30+
# Use relative paths when DESTDIR is set to avoid path joining issues
31+
PREFIX ?= Program Files\\$(PROJECT_NAME)
32+
INSTALL_LIB_DIR := $(PREFIX)\\bin
33+
INSTALL_INCLUDE_DIR := $(PREFIX)\\include
34+
POST_INSTALL := true
35+
endif
36+
37+
# Library name with extension
38+
LIB_NAME := lib$(PROJECT_NAME).$(LIB_EXTENSION)
39+
40+
# Default target
41+
.PHONY: all
42+
all: build
43+
44+
# Build the library using Cargo
45+
.PHONY: build
46+
build:
47+
cargo build --release
48+
49+
# Test the library using Cargo
50+
.PHONY: test
51+
test:
52+
cargo test
53+
54+
# Install the library and headers
55+
.PHONY: install
56+
install: build
57+
@install -d $(DESTDIR)$(INSTALL_LIB_DIR)
58+
@install -d $(DESTDIR)$(INSTALL_INCLUDE_DIR)
59+
60+
install -m 755 target/release/$(LIB_NAME) $(DESTDIR)$(INSTALL_LIB_DIR)/
61+
62+
install -m 644 $(PROJECT_NAME).h $(DESTDIR)$(INSTALL_INCLUDE_DIR)/
63+
64+
@if [ -z "$(DESTDIR)" ] && [ "$(POST_INSTALL)" != "true" ]; then \
65+
$(POST_INSTALL); \
66+
fi
67+
68+
# Uninstall the library and headers
69+
.PHONY: uninstall
70+
uninstall:
71+
rm -f $(DESTDIR)$(INSTALL_LIB_DIR)/$(LIB_NAME)
72+
rm -f $(DESTDIR)$(INSTALL_INCLUDE_DIR)/$(PROJECT_NAME).h
73+
74+
@if [ -z "$(DESTDIR)" ] && [ "$(UNAME_S)" = "Linux" ]; then \
75+
ldconfig; \
76+
fi
77+
78+
# Clean build artifacts
79+
.PHONY: clean
80+
clean:
81+
cargo clean
82+
83+
# Print installation paths (useful for debugging)
84+
.PHONY: print-paths
85+
print-paths:
86+
@echo "Installation paths:"
87+
@echo "Library dir: $(DESTDIR)$(INSTALL_LIB_DIR)"
88+
@echo "Include dir: $(DESTDIR)$(INSTALL_INCLUDE_DIR)"

0 commit comments

Comments
 (0)