-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
72 lines (51 loc) · 1.61 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
# Directories
SRC_DIR=./src
CMD_DIR=./cmd
BUILD_DIR=./build
CMD_C_DIR=$(CMD_DIR)/c
BUILD_C_DIR=$(BUILD_DIR)/c
BIN_C_DIR=$(BUILD_C_DIR)
CMD_GO_DIR=$(CMD_DIR)/go
BUILD_GO_DIR=$(BUILD_DIR)/go
# Define the compiler
CC=gcc
# CC=aarch64-linux-gnu-gcc
# Define any compile-time flags
CFLAGS=-Wall -g -MMD -MP -O2 -march=native -std=c17
# Define any directories containing header files
INCLUDES=
# Define library paths in addition to /usr/lib
LDFLAGS=
# Define any libraries to link into executable
LIBS=
# Define the C source files
MAIN_SRC=$(shell find $(CMD_C_DIR) -name 'main.c')
SRCS=$(shell find $(SRC_DIR) -name '*.c')
# Define the C object files
MAIN_OBJ=$(patsubst $(CMD_C_DIR)/%.c, $(BUILD_C_DIR)/%.o, $(MAIN_SRC))
OBJS=$(patsubst $(SRC_DIR)/%.c, $(BUILD_C_DIR)/%.o, $(SRCS))
# Dependency files
DEPS=$(OBJS:.o=.d)
# Define the executable file
EXECUTABLE=$(BIN_C_DIR)/main
.PHONY: clean
c: $(BUILD_C_DIR) $(EXECUTABLE)
@echo Compiling $(EXECUTABLE)
$(BUILD_C_DIR):
mkdir -p $(BUILD_C_DIR)
$(EXECUTABLE): $(OBJS) $(MAIN_OBJ)
$(CC) $(CFLAGS) $(INCLUDES) -o $@ $^ $(LDFLAGS) $(LIBS)
$(BUILD_C_DIR)/main.o: $(CMD_C_DIR)/main.c
@mkdir -p $(dir $@) # Ensure the directory for the .o file exists
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
$(BUILD_C_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(dir $@) # Ensure the directory for the .o file exists
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
# Include the dependency files
-include $(DEPS)
go:
@go build -mod=readonly -o $(BUILD_GO_DIR)/main -ldflags="-s -w" $(CMD_GO_DIR)/main.go
asm-fallback:
@gcc -o $(BUILD_C_DIR)/asm-fallback $(CMD_C_DIR)/asm-fallback.c
clean:
rm -rf $(BUILD_DIR)