-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
97 lines (72 loc) · 1.73 KB
/
Makefile
File metadata and controls
97 lines (72 loc) · 1.73 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
# Compiler
CC = gcc
# Compiler flags
CFLAGS = -Wall -Wextra -Iinclude
# Source directory
SRC_DIR = source
# Include directory
INC_DIR = include
# Object directory
OBJ_DIR = obj
# Library directory
LIB_DIR = lib
# Test directory
TEST_DIR = test
# Source files
SRCS = $(wildcard $(SRC_DIR)/*.c)
# Header files
HDRS = $(wildcard $(INC_DIR)/*.h)
# Object files
OBJS = $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SRCS))
# Library name
LIB_NAME = libNeatConfig.a
# Target
TARGET = $(LIB_DIR)/$(LIB_NAME)
# Test source file
TEST_SRC = $(TEST_DIR)/test.c
# Test object file
TEST_OBJ = $(TEST_DIR)/test.o
# Test executable
TEST_EXEC = $(TEST_DIR)/test
# Rule to compile object files
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) -c $< -o $@
# Rule to build library
$(TARGET): $(OBJS)
@mkdir -p $(@D)
ar rcs $@ $^
# Rule to build test executable
$(TEST_EXEC): $(TEST_OBJ)
@mkdir -p $(@D)
$(CC) $(CFLAGS) -o $@ $(TEST_OBJ) -L$(LIB_DIR) -lNeatConfig
.PHONY: all clean test
# Build all
all: $(TARGET)
# Install library
install:
make
sudo cp lib/$(LIB_NAME) /usr/local/lib
for header in $(HDRS); do \
sudo cp $$header /usr/local/include/; \
done
# Build test executable
test: $(TEST_EXEC)
# Clean objects and library
clean:
rm -rf $(OBJ_DIR) $(LIB_DIR) $(TEST_OBJ) $(TEST_EXEC)
if [ -f /usr/local/lib/$(LIB_NAME) ]; then \
sudo rm /usr/local/lib/$(LIB_NAME); \
fi
for header in $(HDRS); do \
header_name=$$(basename $$header); \
if [ -f /usr/local/include/$$header_name ]; then \
sudo rm /usr/local/include/$$header_name; \
fi \
done
for header in $(HDRS); do \
header_name=$$(basename $$header); \
if [ -f /usr/local/include/$$header_name ]; then \
sudo rm /usr/local/include/$$header_name; \
fi \
done