summaryrefslogtreecommitdiffhomepage
path: root/Makefile
blob: bb5033f3abaed0cb707c393b8260990493f2f8fa (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
150
include common.mk

VERSION=$(shell dpkg-parsechangelog --show-field Version)
DISTROS=base debian11 ubuntu2204 ubuntu2210

PROJECTNAME=libreichwein
TGZNAME=$(shell ls -t ../$(PROJECTNAME)-$(VERSION).tar.xz | head -n1 | sed -e 's,^../,,')

DESTDIR=/

SONAME1=libreichwein.so
SONAME2=libreichwein.so.0
SONAME3=libreichwein.so.0.0.0

# By default, don't export. Explicitly mark exports in C++ with:
# __attribute__((visibility("default")))
CXXFLAGS+=-fvisibility=hidden

CXXFLAGS+=-fPIC

PROGSRC=\
    base64.cpp \
    file.cpp \
    mime.cpp \
    os.cpp \
    process.cpp \
    stringhelper.cpp \
    tempfile.cpp \
    url.cpp

SRC=$(PROGSRC)
HEADERS=$(PROGSRC:.cpp=.h) archive.h

all: staticlib sharedlib
	
staticlib: $(PROJECTNAME).a

sharedlib: $(SONAME3)

$(SONAME3): $(PROGSRC:.cpp=.o)
	$(CXX) $(CXXFLAGS) -shared -Wl,-soname,$(SONAME2) -o $@ $^

install:
	mkdir -p $(DESTDIR)/usr/lib
	cp $(PROJECTNAME).a $(DESTDIR)/usr/lib/
	mkdir -p $(DESTDIR)/usr/include/libreichwein
	cp $(HEADERS) $(DESTDIR)/usr/include/libreichwein/
	install $(SONAME3) $(DESTDIR)/usr/lib/$(SONAME3)
	ln -sf $(SONAME3) $(DESTDIR)/usr/lib/$(SONAME2)
	ln -sf $(SONAME2) $(DESTDIR)/usr/lib/$(SONAME1)

$(PROJECTNAME).a: $(SRC:.cpp=.o)
	ar rcs $@ $^

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

%.d: %.cpp
	$(CXX) $(CXXFLAGS) -MM -MP -MF $@ -c $<

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

deb:
	dpkg-buildpackage -rfakeroot

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

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

debs: $(DISTROS)

upload:
	scp ../$(TGZNAME) antcom.de:/var/www/reichwein.it-download/
	scp -r result antcom.de:
	scp -r remote-install.sh antcom.de:
	ssh antcom.de ./remote-install.sh $(PROJECTNAME) $(VERSION)
	ssh antcom.de rm -rf remote-install.sh result

test:
	$(MAKE) -C tests

# dependencies

ADD_DEP=Makefile

DISTFILES=$(shell git ls-files 2>/dev/null)
ifeq ($(DISTFILES),)
DISTFILES= \
Makefile \
archive.h \
base64.cpp \
base64.h \
common.mk \
debian/README.Debian \
debian/changelog \
debian/compat \
debian/control \
debian/copyright \
debian/libreichwein-dev.install \
debian/libreichwein0.install \
debian/rules \
debian/source/format \
file.cpp \
file.h \
mime.cpp \
mime.h \
os.cpp \
os.h \
process.cpp \
process.h \
remote-install.sh \
stringhelper.cpp \
stringhelper.h \
tempfile.cpp \
tempfile.h \
tests/Makefile \
tests/test-archive.cpp \
tests/test-base64.cpp \
tests/test-file.cpp \
tests/test-mime.cpp \
tests/test-os.cpp \
tests/test-process.cpp \
tests/test-stringhelper.cpp \
tests/test-tempfile.cpp \
tests/test-url.cpp \
url.cpp \
url.h
endif

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

# misc ---------------------------------------------------
clean:
	-rm -f *.o *.a *.d $(SONAME1) $(SONAME2) $(SONAME3)
	$(MAKE) -C tests clean

.PHONY: clean all install test

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