summaryrefslogtreecommitdiffhomepage
path: root/Makefile
blob: 50c49b63c04115a7a5029f21194d938db49a3e00 (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
PROJECTNAME=unicode
VERSION=$(shell dpkg-parsechangelog --show-field Version)

DISTROS=base debian10 ubuntu2004 ubuntu2010

ifeq ($(wildcard $(shell which clang++-13)),)
ifeq ($(wildcard $(shell which clang++)),)
CXX=g++-11
else
CXX=clang++
endif
else
CXX=clang++-13
endif

# boost is buggy for C++20: error: static_assert failed due to requirement 'detail::is_endian_reversible_inplace<char8_t>
STANDARD=c++17
#STANDARD=c++20

ifeq ($(CXXFLAGS),)
#CXXFLAGS=-O0 -g -D_DEBUG
CXXFLAGS=-O2 -DNDEBUG
endif

CXXFLAGS+=-Wall -Iinclude -std=$(STANDARD)

ifeq ($(CXX),clang++-13)
COMPILER_SUITE=clang
LIBS+=-fuse-ld=lld-13
endif

ifeq ($(CXX),clang++)
COMPILER_SUITE=clang
LIBS+=-fuse-ld=lld
endif

LDLIBS+=\
-lboost_context \
-lboost_filesystem \
-lboost_timer \
-lboost_system \

ifeq ($(COMPILER_SUITE),clang)
# libc++ is buggy for C++20: std::hash<char8_t> not implemented. Fixed in LLVM-12
CXXFLAGS+=-stdlib=libc++
LIBS+= \
-lc++ \
-lc++abi
#-lc++fs
#-lstdc++ \
#-lstdc++fs
else
LIBS+= \
-lstdc++ \
-lstdc++fs
endif

SRC=\
    src/file.cpp \
    src/recode.cpp \
    src/validate.cpp \
    src/test-unicode.cpp

all: src/recode src/test-unicode src/validate

test: src/test-unicode
	src/test-unicode

src/recode: src/recode.o src/file.o dep
	$(CXX) $(LDFLAGS) src/recode.o src/file.o $(LDLIBS) $(LIBS) -o $@

src/validate: src/validate.o src/file.o dep
	$(CXX) $(LDFLAGS) src/validate.o src/file.o $(LDLIBS) $(LIBS) -o $@

src/test-unicode: src/test-unicode.o src/file.o dep
	$(CXX) $(LDFLAGS) $< $(LDLIBS) $(LIBS) -o $@

dep: $(SRC:.cpp=.d)

%.d: %.cpp
	$(CXX) $(CXXFLAGS) -MM -MP -MF $@ -MT $(*D)/$(*F).o -c $<

%.o: %.cpp %.d
	$(CXX) $(CXXFLAGS) -c $< -o $@

clean:
	-rm -f src/recode src/test-unicode src/validate src/*.tmp
	-rm -rf result
	-find . -name '*.o' -o -name '*.d' -o -name '*.gcno' -o -name '*.gcda' | xargs rm -f

install:
	mkdir -p $(DESTDIR)/usr/include
	cp include/unicode.h $(DESTDIR)/usr/include
	mkdir -p $(DESTDIR)/usr/bin
	cp src/recode $(DESTDIR)/usr/bin/unicode-recode
	cp src/validate $(DESTDIR)/usr/bin/unicode-validate

deb:
	# build binary deb package
	dpkg-buildpackage -rfakeroot

deb-src:
	dh_clean
	dh_auto_clean
	dpkg-source -b -I.git -Iresult .

$(DISTROS): deb-src
	sudo pbuilder build --basetgz /var/cache/pbuilder/$@.tgz --buildresult result/$@ ../$(PROJECTNAME)_$(VERSION).dsc
	debsign result/$@/$(PROJECTNAME)_$(VERSION)_amd64.changes

debs: $(DISTROS)

DISTFILES= \
	   $(SRC) \
	   src/file.h \
	   Makefile \
	   include/unicode.h \
           debian/control \
           debian/compat \
           debian/copyright \
           debian/source \
           debian/source/format \
           debian/changelog \
           debian/README.Debian \
           debian/rules \
           debian/unicode-tools.install \
           debian/libunicode-dev.install \
	   msbuild/compiler.props \
	   msbuild/libunicode.vcxproj \
	   msbuild/libunicode.vcxproj.filters \
	   msbuild/recode.vcxproj \
	   msbuild/recode.vcxproj.filters \
	   msbuild/test-unicode.vcxproj \
	   msbuild/test-unicode.vcxproj.filters \
	   msbuild/unicode.sln \
	   msbuild/validate.vcxproj \
	   msbuild/validate.vcxproj.filters

dist: clean
	rm -rf $(PROJECTNAME)-$(VERSION)
	mkdir $(PROJECTNAME)-$(VERSION)
	cp --parents -r $(DISTFILES) $(PROJECTNAME)-$(VERSION)
	tar cfJ ../$(PROJECTNAME)-$(VERSION).tar.xz $(PROJECTNAME)-$(VERSION)
	rm -rf $(PROJECTNAME)-$(VERSION)
	ls -l ../$(PROJECTNAME)-$(VERSION).tar.xz

.PHONY: all test clean install dep deb debs deb-src dist $(DISTROS)

-include $(wildcard $(SRC:.cpp=.d))