aboutsummaryrefslogtreecommitdiff
path: root/svg-flatten/Makefile
blob: 082456181dcd6fd287c70c81c37a2f131c47e934 (plain)
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
CXX := clang++
LD ?= ld
INSTALL := install
PKG_CONFIG ?= pkg-config

BUILDDIR ?= build
PREFIX ?= /usr/local
UPSTREAM_DIR ?= ../upstream

SOURCES := src/svg_color.cpp \
	src/svg_doc.cpp \
	src/svg_geom.cpp \
	src/svg_import_util.cpp \
	src/svg_path.cpp \
	src/svg_pattern.cpp \
	src/vec_core.cpp \
	src/vec_grid.cpp \
	src/main.cpp \
	src/flatten.cpp \
	src/out_svg.cpp \
	src/out_gerber.cpp \
	src/out_sexp.cpp \
	src/out_flattener.cpp \
	src/out_dilater.cpp \
	src/lambda_sink.cpp \
	src/flatten.cpp \
	$(UPSTREAM_DIR)/cpp-base64/base64.cpp

CLIPPER_SOURCES ?= $(UPSTREAM_DIR)/clipper-6.4.2/cpp/clipper.cpp
CLIPPER_INCLUDES 	?= -I$(UPSTREAM_DIR)/clipper-6.4.2/cpp
VORONOI_INCLUDES 	?= -I$(UPSTREAM_DIR)/voronoi/src
POISSON_INCLUDES 	?= -I$(UPSTREAM_DIR)/poisson-disk-sampling/thinks/poisson_disk_sampling/
BASE64_INCLUDES 	?= -I$(UPSTREAM_DIR)/cpp-base64
ARGAGG_INCLUDES 	?= -I$(UPSTREAM_DIR)/argagg/include/argagg
CAVC_INCLUDES 		?= -I$(UPSTREAM_DIR)/CavalierContours/include/cavc/
SUBPROCESS_INCLUDES	?= -I$(UPSTREAM_DIR)/subprocess.h
MINUNIT_INCLUDES	?= -I$(UPSTREAM_DIR)/minunit
STB_INCLUDES		?= -isystem$(UPSTREAM_DIR)/stb

SOURCES += $(CLIPPER_SOURCES)
INCLUDES := -Iinclude -Isrc $(CLIPPER_INCLUDES) $(VORONOI_INCLUDES) $(POISSON_INCLUDES) $(BASE64_INCLUDES) $(ARGAGG_INCLUDES) $(CAVC_INCLUDES) $(SUBPROCESS_INCLUDES) $(MINUNIT_INCLUDES) $(STB_INCLUDES)

PKG_CONFIG_DEPS := pugixml
CXXFLAGS := -std=c++2a -g -Wall -Wextra -O0
CXXFLAGS += $(shell $(PKG_CONFIG) --cflags $(PKG_CONFIG_DEPS)) 
# hack for stone age opencv in debian stable
CXXFLAGS += $(shell $(PKG_CONFIG) --cflags opencv4 2> /dev/null || $(PKG_CONFIG) --cflags opencv 2>/dev/null) 

LDFLAGS := -lm -lc -lstdc++
LDFLAGS += $(shell $(PKG_CONFIG) --libs $(PKG_CONFIG_DEPS))
# debian hack. see above.
OPENCV_LDFLAGS := $(shell $(PKG_CONFIG) --libs opencv4 2> /dev/null || $(PKG_CONFIG) --libs opencv 2>/dev/null) 
LDFLAGS += $(shell echo $(OPENCV_LDFLAGS) | sed 's/-l\S\+ //g') -lopencv_core -lopencv_imgproc -lopencv_imgcodecs

TARGET := svg-flatten

all: $(BUILDDIR)/$(TARGET)

.PHONY: check-deps
check-deps:
	@echo
	@$(PKG_CONFIG) --cflags --libs pugixml >/dev/null
	# debian hack. see above.
	@$(PKG_CONFIG) --cflags --libs opencv4 >/dev/null ||$(PKG_CONFIG) --cflags --libs opencv >/dev/null 

$(BUILDDIR)/%.o: %.cpp
	@mkdir -p $(dir $@) 
	$(CXX) -c $(CXXFLAGS) $(CXXFLAGS) $(INCLUDES) -o $@ $^

$(BUILDDIR)/$(TARGET): $(SOURCES:%.cpp=$(BUILDDIR)/%.o)
	@mkdir -p $(dir $@) 
	if [ $$(uname -s) = "Darwin" ]; then \
		$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $^; \
	else \
		$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ -Wl,--start-group $^ -lstdc++fs -Wl,--end-group; \
	fi

$(BUILDDIR)/nopencv-tests: src/nopencv_test.cpp src/nopencv.cpp
	@mkdir -p $(dir $@) 
	$(CXX) $(CXXFLAGS) $(INCLUDES) $(LDFLAGS) -o $@ $^


.PHONY: tests
tests: $(BUILDDIR)/nopencv-tests

.PHONY: install
install:
	$(INSTALL) $(BUILDDIR)/$(TARGET) $(PREFIX)/bin
	
.PHONY: clean
clean:
	rm -rf $(BUILDDIR)