-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
42 lines (32 loc) · 905 Bytes
/
Makefile
File metadata and controls
42 lines (32 loc) · 905 Bytes
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
CC = gcc
CFLAGS-common = -std=gnu18 -Wall -Wextra -Werror -pedantic
CFLAGS = $(CFLAGS-common) -O2
CFLAGS-dbg = $(CFLAGS-common) -Og -ggdb
TARGET = wsh
# Source files
SRC = wsh.c dynamic_array.c utils.c hash_map.c
# Build directories
BUILDDIR = build
RELEASEDIR = $(BUILDDIR)/release
DEBUGDIR = $(BUILDDIR)/debug
# Object files
OBJ = $(patsubst %.c,$(RELEASEDIR)/%.o,$(SRC))
OBJ-dbg = $(patsubst %.c,$(DEBUGDIR)/%.o,$(SRC))
all: $(TARGET) $(TARGET)-dbg
# Optimized build
$(TARGET): $(OBJ)
$(CC) $(CFLAGS) $^ -o $@
# Debug build
$(TARGET)-dbg: $(OBJ-dbg)
$(CC) $(CFLAGS-dbg) $^ -o $@
# Compile release objects
$(RELEASEDIR)/%.o: %.c %.h | $(RELEASEDIR)
$(CC) $(CFLAGS) -c $< -o $@
# Compile debug objects
$(DEBUGDIR)/%.o: %.c %.h | $(DEBUGDIR)
$(CC) $(CFLAGS-dbg) -c $< -o $@
# Ensure build dirs exist
$(RELEASEDIR) $(DEBUGDIR):
mkdir -p $@
clean:
rm -rf $(BUILDDIR) $(TARGET) $(TARGET)-dbg