-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
68 lines (45 loc) · 1.49 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
# ROOT_DIR := $(notdir $(patsubst %/,%,$(CURDIR)))
MAKEFILE := $(firstword $(MAKEFILE_LIST))
SHELL := /bin/bash
TARGET := ttytris
LIBS := ncurses
CC := gcc
# CFLAGS := --std=c99 -D_POSIX_C_SOURCE=199309L
CFLAGS :=
ifdef PKG_LIBS
CFLAGS += $(shell pkg-config --cflags $(PKG_LIBS)) -std=c11
LIB_FLAGS += $(shell pkg-config --libs $(PKG_LIBS))
endif
LIB_FLAGS += $(addprefix -l, $(LIBS))
PREFIX ?= /usr/local
BINPREFIX := $(PREFIX)/bin
SOURCES := $(wildcard src/*.c)
HEADERS := $(wildcard src/*.h)
OBJECTS := $(SOURCES:.c=.o)
TEST_SOURCES := $(wildcard test/*.c)
TEST_HEADERS := $(wildcard test/*.h)
TEST_OBJECTS := $(TEST_SOURCES:.c=.o)
TEST_TARGET := test/runtests
.PHONY: debug default uninstall clean test
all: # Multi-threaded make by default
$(MAKE) -j $(shell nproc) $(TARGET)
debug: CFLAGS += -D DEBUG
debug: $(TARGET)
$(TARGET): $(OBJECTS)
$(CC) $(CFLAGS) $(LDFLAGS) $(LIB_FLAGS) $^ -o $@ -O3
$(OBJECTS): $(SOURCES) $(HEADERS)
%.o: %.c
$(CC) $(FEATURES) $(CFLAGS) $(LDFLAGS) $(LIB_FLAGS) -c $< -o $@
$(SOURCES): $(MAKEFILE) # If Makefile changes, recompile
@touch $(SOURCES)
install: $(TARGET)
install -m 755 -D --target-directory "$(BINPREFIX)" "$(TARGET)"
uninstall:
rm -f "$(BINPREFIX)/$(TARGET)"
clean:
rm -f $(TARGET) $(TEST_TARGET) $(OBJECTS) $(TEST_OBJECTS)
test: $(TEST_TARGET)
$(TEST_TARGET)
$(TEST_TARGET): $(TEST_OBJECTS) $(filter-out src/main.o, $(OBJECTS))
$(CC) $(CFLAGS) $(LDFLAGS) $(LIB_FLAGS) $^ -o $@ -O3
$(TEST_OBJECTS): $(TEST_SOURCES) $(TEST_HEADERS)