forked from 61315/resynthesizer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
110 lines (91 loc) · 3.6 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
.POSIX:
CC = c++ -std=c++11
CPPFLAGS = -MMD -MP -DSYNTH_LIB_ALONE
CFLAGS = -Wall -Wextra -pedantic -O3 -fpermissive
LDFLAGS = -lm
LDLIBS =
# PREFIX = /usr/local
LIB_DIR := lib
BUILD_DIR := build
SRC_DIR := resynthesizer
# Collect resynthesizer sources and headers, then create object files out of the sources.
SRCS := $(shell find $(SRC_DIR) -name '*.c')
OBJS := $(SRCS:%.c=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
INC_DIRS := $(shell find $(SRC_DIR) -type d)
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
STATIC_LIB := $(LIB_DIR)/libresynthesizer.a
ASSET_DIR := assets
EXAMPLE_DIR := examples
EXAMPLES := $(EXAMPLE_DIR)/hello $(EXAMPLE_DIR)/ppm $(EXAMPLE_DIR)/painter
# -g -Wall -Wextra -Werror -std=c99 -pedantic-errors
# TODO: Try both -Werror and -pedantic-errors after all the chores are done.
all: $(STATIC_LIB) test
@echo "\033[1;92mDone!\033[0m"
# Build resynthesizer as static library.
$(STATIC_LIB): $(OBJS)
@echo "\033[1;92mBuilding $@\033[0m"
mkdir -p $(dir $@)
ar rvs $@ $^
$(BUILD_DIR)/%.o: %.c
@echo "\033[1;92mBuilding $@\033[0m"
mkdir -p $(dir $@)
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
# Build the example executables.
$(EXAMPLE_DIR)/hello: $(EXAMPLE_DIR)/hello.c $(STATIC_LIB)
@echo "\033[1;92mBuilding $@\033[0m"
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -o $@ $(EXAMPLE_DIR)/hello.c $(LDFLAGS) $(INC_FLAGS) $(STATIC_LIB)
$(EXAMPLE_DIR)/ppm: $(EXAMPLE_DIR)/ppm.c $(STATIC_LIB)
@echo "\033[1;92mBuilding $@\033[0m"
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -o $@ $(EXAMPLE_DIR)/ppm.c $(LDFLAGS) $(INC_FLAGS) $(STATIC_LIB)
$(EXAMPLE_DIR)/painter: $(EXAMPLE_DIR)/painter.c $(STATIC_LIB)
@echo "\033[1;92mBuilding $@\033[0m"
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -o $@ $(EXAMPLE_DIR)/painter.c $(LDFLAGS) $(INC_FLAGS) $(STATIC_LIB) $(shell pkg-config --cflags --libs sdl2)
# Build lib for python's numpy using pybind11
content-aware-fill: python/content-aware-fill.cpp $(SRCS)
@echo "\033[1;92mBuilding $@\033[0m"
$(CC) -O3 -Wall -shared -fPIC \
python/content-aware-fill.cpp -o python/libcontent_aware_fill$(shell python3-config --extension-suffix) \
-DPYTHON_LIB_NAME=libcontent_aware_fill \
$(shell python3 -m pybind11 --includes) \
$(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(INC_FLAGS) $(SRCS)
@echo "\033[1;92mLib is saved to:\033[0m \033[1;36mpython/libcontent_aware_fill$(shell python3-config --extension-suffix)\033[0m"
@echo "\033[1;92mDone!\033[0m"
SITE_PKG_DIR = $(shell python3 -c "import site; print(site.getsitepackages()[0])")
install-content-aware-fill: content-aware-fill
@echo "\033[1;92mInstalling $@\033[0m"
cp python/libcontent_aware_fill*.so $(SITE_PKG_DIR)
@echo "\033[1;92mInstalled to $(shell ls $(SITE_PKG_DIR)/libcontent_aware_fill*.so) \033[0m"
# Run the executable(ppm) against the sample images with varying parameters.
fuzz: $(EXAMPLE_DIR)/ppm
@echo "\033[1;92mFuzzing...\033[0m"
mkdir -p $(EXAMPLE_DIR)/output
@for number in 0 1 2 3 4 ; do \
for context in 0 1 2 3 4 5 6 7 8 ; do \
for neighbors in 9 64 ; do \
for probes in 64 256 ; do \
$(EXAMPLE_DIR)/ppm \
$(ASSET_DIR)/source00$${number}.ppm \
$(ASSET_DIR)/mask00$${number}.ppm \
$(EXAMPLE_DIR)/output/result00$${number}"_"$${context}"_"$${neighbors}"_"$${probes}.ppm \
$${context} $${neighbors} $${probes} ; \
done \
done \
done \
done
test: $(EXAMPLE_DIR)/hello
@echo "\033[1;92mTesting...\033[0m"
@if $(EXAMPLE_DIR)/hello; then \
echo "\033[1;92mTest Passed!\033[0m"; \
else \
echo "\033[1;91mTest Failed!\033[0m"; \
exit 1; \
fi
.PHONY: clean test all
clean:
$(RM) -r $(BUILD_DIR) $(LIB_DIR) $(EXAMPLES)
# Include resynthesizer headers from the `-MMD` and `-MP` flags.
-include $(DEPS)