-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
66 lines (50 loc) · 1.62 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
-include config/*.mk
LIB_NAME = $(BIN_DIR)/Slibc.a
SO_NAME = $(BIN_DIR)/Slibc.so
TEST_BIN := benchmark
ifeq ($(VERBOSE), true)
CFLAGS += -D VERBOSE
endif
# Source files
SRC = $(shell find $(SRC_DIR) -type f -name '*.c')
ASM_FILES = $(shell find $(ASM_SRC_DIR) -type f -name '*.s')
# Object files
OBJ = $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SRC))
ASM_OBJ = $(patsubst $(ASM_SRC_DIR)/%.s, $(OBJ_DIR)/%.o, $(ASM_FILES))
# Include directories
INCLUDE = -I $(INCLUDE_DIR)
INCLUDE += -I $(SRC_DIR)/config
all: $(OBJ_DIR) $(BIN_DIR) $(LIB_NAME) $(SO_NAME)
# Compile .c files
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(dir $@)
@echo "Compiling $< into $@..."
$(CC) $(CFLAGS) $(PIC_FLAGS) $(INCLUDE) -c $< -o $@
@test -f $@ || (echo "Error: $@ is not a file! Something went wrong." && exit 1)
# Assemble .s files
$(OBJ_DIR)/%.o: $(ASM_SRC_DIR)/%.s
@mkdir -p $(dir $@)
@echo "Assembling $< into $@..."
$(AS) $(NASM_FLAGS) -o $@ $<
@test -f $@ || (echo "Error: $@ is not a file! Something went wrong." && exit 1)
# Build static library
$(LIB_NAME): $(OBJ) $(ASM_OBJ)
@echo "Building static library $(LIB_NAME)..."
@$(AR) rcs $@ $(filter %.o,$^)
# Build shared library with version script
$(SO_NAME): $(OBJ) $(ASM_OBJ)
@echo "Building shared library $@..."
@$(CC) $(LDFLAGS) $(PIC_FLAGS) $(INCLUDE) -shared -o $@ $(OBJ) $(ASM_OBJ)
@strip --strip-all $@
# Clean object files
clean:
@echo "Removing object files..."
@rm -rf $(OBJ_DIR)
# Full clean of libraries and executables
fclean: clean
@echo "Removing libraries and executables..."
@rm -rf $(BIN_DIR)
# Rebuild all
re: fclean all
-include $(OBJ:.o=.d)
.PHONY: all clean fclean re