-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
executable file
·72 lines (60 loc) · 1.51 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
#!/usr/bin/env -S make -f
# Compiler
CC := gcc
# Compiler flags
CFLAGS := -pedantic -std=c99
CLIBS := -lcurl -ljson-c
ifeq ($(shell uname),Darwin)
CFLAGS += -I/opt/homebrew/include
LDFLAGS += -L/opt/homebrew/lib
endif
# Source files location
SRC_DIR := src
# Object files location
OBJ_DIR := obj
# Source files
SRC := $(wildcard $(SRC_DIR)/*.c)
# Object files (derived from source files)
OBJ := $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SRC))
# Binary name
TARGET := gpt
.PHONY: all clean debug release
# Default Target
.DEFAULT_GOAL := release
all: $(TARGET)
debug: CFLAGS += -O0 -g
debug: all
release: CFLAGS += -O3
release: STRIP := -s
release: all
# Compile object files
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(OBJ_DIR)
$(CC) -c $< -o $@ $(CFLAGS)
# Link object files and create binary
$(TARGET): $(OBJ)
@mkdir -p $(dir $(TARGET))
$(CC) $(OBJ) -o $(TARGET) $(LDFLAGS) $(CLIBS) $(CFLAGS) $(STRIP)
# Clean object files and binary
clean:
$(RM) -r $(OBJ_DIR) $(TARGET)
#```
#
#To use this Makefile, create a directory structure as follows:
#
#```
#project_folder/
# |--- src/
# | |- file1.c
# | |- file2.c
# | |- file3.c
# | ...
# |
# |--- obj/
# |
# |--- Makefile
#```
#
#Place your C source files inside the `src/` directory. Then, execute `make` command in the `project_folder/` directory to compile and link all the source files into a binary named `my_binary`. The compiled binary will be created in `project_folder/`.
#
#To clean the generated object files and binary, execute `make clean`.