-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
87 lines (69 loc) · 2.79 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
CC ?= gcc
RM = rm -f
INCLUDE_DIR ?= /usr/include
OPTFLAGS ?= -Ofast -march=native
# Default: Enable all features that do not impact performance
FEATURES ?= SIZE OFFSET STATISTICS SDL NUMA VNC TTF FBDEV #PIXEL_COUNT BROKEN_PTHREAD ALPHA_BLENDING
# Declare features compiled conditionally
CODE_FEATURES = STATISTICS SDL NUMA VNC TTF FBDEV
SOURCE_SDL = sdl.c
HEADER_SDL = sdl.h
DEPS_SDL = sdl2
CCFLAGS_sdl2 = -I$(INCLUDE_DIR)SDL2 -D_REENTRANT
LDFLAGS_sdl2 = -lSDL2
SOURCE_VNC = vnc.c
HEADER_VNC = vnc.h
DEPS_VNC = libvncserver
LDFLAGS_libvncserver = -lvncserver
SOURCE_TTF = textrender.c
HEADER_TTF = textrender.h
DEPS_TTF = freetype2
CCFLAGS_freetype2 = -I$(INCLUDE_DIR)freetype2 -I$(INCLUDE_DIR)libpng16 -I$(INCLUDE_DIR)harfbuzz -I$(INCLUDE_DIR)glib-2.0 -I/usr/lib/glib-2.0/include
LDFLAGS_freetype2 = -lfreetype
SOURCE_STATISTICS = statistics.c
HEADER_STATISTICS = statistics.h
SOURCE_FBDEV = linuxfb.c
HEADER_FBDEV = linuxfb.h
DEPS_NUMA = numa
LDFLAGS_numa = -lnuma
# Create lists of features components
FEATURE_SOURCES = $(foreach feature,$(CODE_FEATURES),$(SOURCE_$(feature)))
FEATURE_HEADERS = $(foreach feature,$(CODE_FEATURES),$(HEADER_$(feature)))
FEATURE_DEPS = $(foreach feature,$(CODE_FEATURES),$(DEPS_$(feature)))
# Set default compile flags
CCFLAGS = -Wall -D_GNU_SOURCE
ifneq ($(DEBUG),)
CCFLAGS += -O1 -ggdb -DDEBUG=$(DEBUG)
else
CCFLAGS += $(OPTFLAGS)
endif
CCFLAGS += $(foreach feature,$(FEATURES),-DFEATURE_$(feature))
# Build dependency compile flags
DEPFLAGS_CC =
DEPS = $(filter $(FEATURE_DEPS),$(foreach feature,$(FEATURES),$(DEPS_$(feature))))
# Try fetching compile flags from pkg-config, use static ones on failure
DEPFLAGS_CC += $(foreach feature,$(FEATURES),\
$(foreach dep,$(DEPS_$(feature)),\
$(shell pkg-config --cflags $(dep) || ((1>&2 echo Missing pkg-config file for $(dep), trying $(CCFLAGS_$(dep)) && echo "$(CCFLAGS_$(dep))") ))))
# Build dependency linker flags
DEPFLAGS_LD = -lpthread
# Try fetching linker flags from pkg-config, use static ones on failure
DEPFLAGS_LD += $(foreach feature,$(FEATURES),\
$(foreach dep,$(DEPS_$(feature)),\
$(shell pkg-config --libs $(dep) || ((1>&2 echo Missing pkg-config file for $(dep), trying $(LDFLAGS_$(dep)) && echo "$(LDFLAGS_$(dep))") ))))
# Select source files
FEATURE_SOURCE = $(foreach feature,$(FEATURES),$(SOURCE_$feature))
SOURCE = $(filter-out $(FEATURE_SOURCES),$(wildcard *.c))
SOURCE += $(foreach feature,$(FEATURES),$(SOURCE_$(feature)))
OBJS = $(patsubst %.c,%.o,$(SOURCE))
HDRS = $(filter-out $(FEATURE_HEADERS),$(wildcard *.h))
HDRS += $(foreach feature,$(FEATURES),$(HEADER_$(feature)))
all: shoreline
%.o : %.c $(HDRS) Makefile
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(CCFLAGS) $(DEPFLAGS_CC) $< -o $@
shoreline: $(OBJS)
$(CC) $(LDFLAGS) $(CFLAGS) $(CCFLAGS) $^ $(DEPFLAGS_LD) -o shoreline
clean:
$(RM) $(OBJS)
$(RM) shoreline
.PHONY: all clean