Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
117 lines (92 loc) · 2.51 KB
/
Copy pathMakefile
File metadata and controls
117 lines (92 loc) · 2.51 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
# Cross-platform Makefile for SM9 Library
# Supports: Linux, macOS, Windows (MinGW/MSYS2)
CC = gcc
CFLAGS += -Wall -O2 -I$(INCLUDE_DIR)
LDFLAGS += -lm
# Directories
INCLUDE_DIR = include
SRC_DIR = src
BUILD_DIR = build
BIN_DIR = bin
# Detect operating system
ifeq ($(OS),Windows_NT)
TARGET_OS = Windows
RM = del /Q
MKDIR = mkdir
TARGET_EXT = .exe
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
TARGET_OS = Linux
endif
ifeq ($(UNAME_S),Darwin)
TARGET_OS = macOS
endif
RM = rm -f
MKDIR = mkdir -p
TARGET_EXT =
endif
# Core sources
CORE_SRCS = $(SRC_DIR)/core/bigint.c \
$(SRC_DIR)/core/field2.c \
$(SRC_DIR)/core/field4.c \
$(SRC_DIR)/core/field12.c
# Curve sources
CURVE_SRCS = $(SRC_DIR)/curve/point.c \
$(SRC_DIR)/curve/point2.c \
$(SRC_DIR)/curve/pairing.c
# Hash sources
HASH_SRCS = $(SRC_DIR)/hash/sm3.c \
$(SRC_DIR)/hash/sm4.c
# SM9 sources
SM9_SRCS = $(SRC_DIR)/sm9/params.c \
$(SRC_DIR)/sm9/sm9_dsa.c \
$(SRC_DIR)/sm9/sm9_ka.c \
$(SRC_DIR)/sm9/sm9_pkc.c
# Utility
UTILITY_SRCS = $(SRC_DIR)/utility.c
# All library sources
LIB_SRCS = $(CORE_SRCS) $(CURVE_SRCS) $(HASH_SRCS) $(SM9_SRCS) $(UTILITY_SRCS)
# Object files
LIB_OBJS = $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(LIB_SRCS))
# Test sources
TEST_SRCS = tests/test_sm9.c
TEST_OBJ = $(BUILD_DIR)/test_sm9.o
# Library and executable
LIBRARY = $(BUILD_DIR)/libsm9.a
BIN = $(BIN_DIR)/sm9_test$(TARGET_EXT)
# Create directories
$(BUILD_DIR):
$(MKDIR) $(BUILD_DIR)
$(MKDIR) $(BUILD_DIR)/core
$(MKDIR) $(BUILD_DIR)/curve
$(MKDIR) $(BUILD_DIR)/hash
$(MKDIR) $(BUILD_DIR)/sm9
$(BIN_DIR):
$(MKDIR) $(BIN_DIR)
# Compile source files
$(BUILD_DIR)/core/%.o: $(SRC_DIR)/core/%.c | $(BUILD_DIR)
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/curve/%.o: $(SRC_DIR)/curve/%.c | $(BUILD_DIR)
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/hash/%.o: $(SRC_DIR)/hash/%.c | $(BUILD_DIR)
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/sm9/%.o: $(SRC_DIR)/sm9/%.c | $(BUILD_DIR)
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c | $(BUILD_DIR)
$(CC) $(CFLAGS) -c $< -o $@
# Create static library
$(LIBRARY): $(LIB_OBJS) | $(BUILD_DIR)
ar rcs $@ $(LIB_OBJS)
# Build test executable
$(BIN): $(TEST_OBJ) $(LIBRARY) | $(BIN_DIR)
$(CC) $(LDFLAGS) -o $@ $(TEST_OBJ) -L$(BUILD_DIR) -lsm9
all: $(BIN)
test: $(BIN)
./$(BIN)
clean:
$(RM) -r $(BUILD_DIR)
$(RM) -r $(BIN_DIR)
$(RM) *.o
$(RM) $(BIN)
.PHONY: all clean test