-
Notifications
You must be signed in to change notification settings - Fork 14
/
Makefile
66 lines (51 loc) · 1.71 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
BIN_DIR := bin
SRC_DIR := src
RES_DIR := res
TEST_DIR := test
BINS := bin/jpeg_gpu
OBJS := $(patsubst $(SRC_DIR)/%.c,$(BIN_DIR)/%.o,$(filter-out \
$(patsubst $(BIN_DIR)/%,$(SRC_DIR)/%.c,$(BINS)),$(wildcard $(SRC_DIR)/*.c)))
TEST := $(patsubst $(TEST_DIR)/%.c,$(BIN_DIR)/test/%, \
$(wildcard $(TEST_DIR)/*.c))
GLSL := $(wildcard $(RES_DIR)/*.glsl)
ifneq ($(shell uname),Darwin)
LIBS := `pkg-config --libs glfw3` `pkg-config --libs gl` -ljpeg -lm
else
LIBS := `pkg-config --libs glfw3` -L/usr/local/lib -ljpeg -lm -framework OpenGL
endif
CFLAGS := -std=c89 -pedantic
CFLAGS += -O2 -Wall -Wextra -Wno-parentheses -pedantic -Wno-overlength-strings
#CFLAGS += -g
CFLAGS += `pkg-config --cflags glfw3`
CFLAGS += -DGLJ_ENABLE_LOGGING
#CFLAGS += -DGLJ_ENABLE_VALIDATION
ifeq ($(shell uname),Darwin)
CFLAGS += -I/usr/local/include
endif
guard=@mkdir -p $(@D)
all: $(OBJS) $(BINS) $(TEST)
$(BIN_DIR)/%.o:$(SRC_DIR)/%.c
$(guard)
$(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $<
$(BIN_DIR)/%:$(SRC_DIR)/%.c $(OBJS)
$(guard)
$(CC) $(INCLUDES) $(CFLAGS) $< $(OBJS) -o $@ $(LIBS)
$(BIN_DIR)/test/%: $(TEST_DIR)/%.c $(OBJS)
$(guard)
$(CC) $(INCLUDES) $(CFLAGS) $< $(OBJS) -o $@ $(LIBS)
test: all
@true $(foreach test,$(TEST), && $(test))
clean:
rm -rf $(BIN_DIR) src/jpeg_gpu.h
check-syntax:
$(CC) $(INCLUDES) $(CFLAGS) -o /dev/null -S ${CHK_SOURCES} $(LIBS)
src/jpeg_gpu.h: $(GLSL)
@echo '/* Generated file, do not commit */' > src/jpeg_gpu.h
@$(foreach glsl,$(patsubst $(RES_DIR)/%.glsl,%,$(GLSL)), \
echo 'static const char' \
$(shell echo $(glsl)[] | tr '[.a-z]' '[_A-Z]') \
'= {' >> src/jpeg_gpu.h; \
xxd -i - < $(RES_DIR)/$(glsl).glsl >> src/jpeg_gpu.h; \
echo ', 0x00 };' >> src/jpeg_gpu.h; \
)
bin/jpeg_gpu: src/jpeg_gpu.h