forked from Byte-Ocelots/cMDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
101 lines (78 loc) · 2.58 KB
/
makefile
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
# Define the compiler and compiler flags
CC = gcc
CFLAGS = -Iinclude -Wall -Wextra
# Define RM, MV and SEP command specific to platform
ifeq ($(OS),Windows_NT)
RM = del /Q /F
MV = move
SEP = \\
else
RM = rm -f
MV = mv
SEP = /
endif
# Define directories
SRC_MD_DIR = src/md
SRC_RFC_DIR = src/rfc
TEST_DIR = test
BIN_DIR = bin
LIB_DIR = lib
# Find all .c files in the src/md directory
SRC_MD_FILES = $(wildcard $(SRC_MD_DIR)/*.c)
MD_BIN_FILES = $(patsubst $(SRC_MD_DIR)/%.c,$(BIN_DIR)/%,$(SRC_MD_FILES))
# Find all .c files in the src/rfc directory
SRC_RFC_FILES = $(wildcard $(SRC_RFC_DIR)/*.c)
RFC_OBJ_FILES = $(patsubst $(SRC_RFC_DIR)/%.c,$(SRC_RFC_DIR)/%.o,$(SRC_RFC_FILES))
# Find all .c files in the test directory
TEST_FILES = $(wildcard $(TEST_DIR)/*.c)
TEST_BIN_FILES = $(patsubst $(TEST_DIR)/%.c,$(BIN_DIR)/%,$(TEST_FILES))
# Define the static library
STATIC_LIB = $(LIB_DIR)/libmd.a
# Define the shared library
ifeq ($(OS),Windows_NT)
SHARED_LIB = $(LIB_DIR)/md.dll
else
SHARED_LIB = $(LIB_DIR)/md.so
endif
# Default target
all: _shared _static _build _test clean_o
# Build target for src/md files
_build: $(MD_BIN_FILES)
build : _build clean_o
# Rule to compile each .c file in src/md into its corresponding binary
$(BIN_DIR)/%: $(SRC_MD_DIR)/%.c | $(BIN_DIR) $(STATIC_LIB)
$(CC) $(CFLAGS) -L$(LIB_DIR) -o $@ $< -lm -lmd
# Build target for static library
_static: $(STATIC_LIB)
static : _static clean_o
# Rule to create the static library from src/rfc files
$(STATIC_LIB): $(RFC_OBJ_FILES) | $(LIB_DIR)
ar rcs $@ $(RFC_OBJ_FILES)
# Build target for shared library
_shared: $(SHARED_LIB)
shared : _shared clean_o
# Rule to create the shared library from src/rfc files
$(SHARED_LIB): $(RFC_OBJ_FILES) | $(LIB_DIR)
$(CC) -shared -o $@ $(RFC_OBJ_FILES)
# Rule to compile each .c file in src/rfc into position-independent code (.o files)
$(SRC_RFC_DIR)/%.o: $(SRC_RFC_DIR)/%.c
$(CC) $(CFLAGS) -fPIC -c -o $@ $<
# Build target for test files
_test: $(TEST_BIN_FILES)
test : _test clean_o
# Rule to compile each .c file in test into its corresponding binary
$(BIN_DIR)/%: $(TEST_DIR)/%.c | $(BIN_DIR) $(STATIC_LIB)
$(CC) $(CFLAGS) -o $@ $< -L$(LIB_DIR) -lmd
# Create the bin directory if it doesn't exist
$(BIN_DIR):
mkdir -p $(BIN_DIR)
# Create the lib directory if it doesn't exist
$(LIB_DIR):
mkdir -p $(LIB_DIR)
# Clean target to remove compiled binaries and libraries
clean:
$(RM) $(subst /,$(SEP),$(BIN_DIR)/* $(LIB_DIR)/* $(SRC_RFC_DIR)/*.o)
# Clean target to remove compiled binaries and libraries
clean_o:
$(RM) $(subst /,$(SEP),$(SRC_RFC_DIR)/*.o)
.PHONY: all build static shared test clean