-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
77 lines (59 loc) · 1.89 KB
/
makefile
File metadata and controls
77 lines (59 loc) · 1.89 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
# Set compiler
CC = gcc
# Set name for the executable
NAME = hawk
# Directories
BUILD = build
SRC = src
# Files
VERSION_FILE = ./data/version/version.json
VERSION_HEADER_FILE = ./include/version.h
VERSION = $(shell jq .version $(VERSION_FILE))
# ------------------------------------------------------
# Code compilation
# ------------------------------------------------------
# Flags for compiling
DEBUG_CFLAGS = -Wall -g
RELEASE_CFLAGS =
LDFLAGS = -lpcap --pthread -lcjson
# Get all the source files in the SRC directory and its subdirectories
SRCFILES = $(shell find $(SRC) -name '*.c')
# Generate object file names from source file names
OBJFILES = $(patsubst $(SRC)/%.c, $(BUILD)/%.o, $(SRCFILES))
.PHONY: debug release clean setup-version
# Target to build the executable with debug flags
debug: CFLAGS = $(DEBUG_CFLAGS)
debug: $(OBJFILES)
@$(MAKE) setup-version --no-print-directory
@echo "Building $(NAME) in debug mode"
@$(CC) $(CFLAGS) $^ -o $(NAME) $(LDFLAGS)
@echo "Done!"
# Target to build the executable with release flags
build_release: CFLAGS = $(RELEASE_CFLAGS)
build_release: $(OBJFILES)
@echo "Building $(NAME) in release mode"
@$(CC) $(CFLAGS) $^ -o $(NAME) $(LDFLAGS)
@echo "Done!"
# To clean out debug code
release:
@$(MAKE) setup-version --no-print-directory
@$(MAKE) clean --no-print-directory
@$(MAKE) build_release --no-print-directory
# Rule to compile each source file into an object file
$(BUILD)/%.o: $(SRC)/%.c
@mkdir -p $(@D)
@echo "Compiling $<"
@$(CC) $(CFLAGS) -c -o $@ $<
# Target to clean up generated file
clean:
@rm -rf $(OBJFILES) $(NAME)
setup-version:
@echo "Setting up version"
@echo "#pragma once" > $(VERSION_HEADER_FILE)
@echo '#define VERSION $(VERSION)' >> $(VERSION_HEADER_FILE)
setup-hooks:
@echo "Setting up git hooks"
cp ./data/hooks/* ./.git/hooks/
chmod +x ./.git/hooks/*
test-compile:
act --rm -W .github/workflows/compile-test.yml