-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
69 lines (54 loc) · 1.16 KB
/
Makefile
File metadata and controls
69 lines (54 loc) · 1.16 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
TARGET := chip8
# Compiler
CC := clang
# Files
SRCDIR := src
BLDDIR := build
SRC := $(shell find $(SRCDIR) -type f -name *.c)
OBJ := $(subst $(SRCDIR),$(BLDDIR),$(SRC:.c=.o))
CMD := $(OBJ:.o=.o.json)
# Libraries
LIBS := $(shell sdl-config --libs)
LIBS += -lSDL_mixer
# CFLAGS
CFLAGS += -pipe
CFLAGS += -std=c11
CFLAGS += $(shell sdl-config --cflags)
# CFLAG options
# Compiler debugging enabled
DEBUG := yes
ifeq ($(DEBUG), yes)
CFLAGS += -Wall
CFLAGS += -Wextra
CFLAGS += -g
CFLAGS += -pedantic
CFLAGS += -DDEBUG
COMP := yes
else
CFLAGS += -O2
endif
all: setup options $(TARGET)
setup:
@mkdir -p build
options:
@echo "$(TARGET) build options:"
@echo "CFLAGS = $(CFLAGS)"
@echo "LDFLAGS = $(LIBS)"
@echo "CC = $(CC)"
@echo "SRC = $(SRC)"
@echo "OBJ = $(OBJ)"
@echo "CMD = $(CMD)"
$(BLDDIR)/%.o: $(SRCDIR)/%.c
ifeq ($(COMP), yes)
$(CC) -MJ $@.json $(CFLAGS) -c $< -o $@
else
$(CC) $(CFLAGS) -c $< -o $@
endif
$(TARGET): $(OBJ)
$(CC) $(LIBS) $(OBJ) -o $(BLDDIR)/$(TARGET)
ifeq ($(COMP), yes)
@sed -e '1s/^/[\n/' -e '$$s/,$$/\n/' $(CMD) > $(BLDDIR)/compile_commands.json
endif
clean:
@rm -rvf $(OBJ) $(CMD) $(TARGET)
.PHONY: all setup options clean