0 branches 0 tags
93 94
95
Add build directory
on 9:02 AM Jun 12 2026
trunk/makefile
94
95
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
# Basic Makefile for a C program with multiple source files and header dependencies
CC = gcc
CFLAGS = -Wall -Wextra -g -O0 -MMD -MP -std=c17
EXAMPLES_SRC = $(wildcard examples/*.c)
EXAMPLES_OBJ = $(EXAMPLES_SRC:.c=.o)
EXAMPLES = $(patsubst examples/%.c, %, $(wildcard examples/*.c))
LIB_SRC = $(wildcard coroutine/*.c)
LIB_OBJ = $(LIB_SRC:.c=.o)
OBJ = $(EXAMPLES_OBJ) $(LIB_OBJ)
DEP = $(OBJ:.o=.d)
all: $(EXAMPLES)
%: examples/%.o $(LIB_OBJ)
$(CC) $(CFLAGS) -o $@ $^
%.o: %.c
$(CC) $(CFLAGS) -I include -c $< -o $@
-include $(DEP)
clean:
rm -f $(OBJ) $(DEP) $(EXAMPLES)
.PHONY: all clean
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
# Basic Makefile for a C program with multiple source files and header dependencies
CC = gcc
CDFLAGS = -Wall -Wextra -std=c17 -I include
CFLAGS = $(CDFLAGS) -g -O0 -MMD -MP
BUILD = build
EXAMPLES_SRC = $(wildcard examples/*.c)
EXAMPLES_OBJ = $(patsubst %.c, $(BUILD)/%.o, $(EXAMPLES_SRC))
EXAMPLES = $(patsubst examples/%.c, %, $(wildcard examples/*.c))
LIB_SRC = $(wildcard coroutine/*.c)
LIB_OBJ = $(patsubst %.c, $(BUILD)/%.o, $(LIB_SRC))
OBJ = $(EXAMPLES_OBJ) $(LIB_OBJ)
DEP = $(OBJ:.o=.d)
# Have $(OBJ) as a dependenacy for $(ALL) to avoid them being treated as intermediates which are deleted after build
all: $(EXAMPLES) $(OBJ)
build:
mkdir $(BUILD)
%: $(BUILD)/examples/%.o $(LIB_OBJ)
$(CC) $(CFLAGS) -o $@ $^
$(BUILD)/%.o: %.c build
$(CC) $(CFLAGS) -c $< -o $@ -MF $(@:.o=.d)
-include $(DEP)
clean:
echo Doing clean
rm -f $(OBJ) $(DEP) $(EXAMPLES)
.PHONY: all clean