-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile.main
171 lines (134 loc) · 4.38 KB
/
Makefile.main
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
############################# configurable section #############################
#
# Copyright © 2015-2023 Boian Bonev ([email protected]) {{{
#
# SPDX-License-Identifer: LGPL-3.0-or-later
#
# This file is part of yascreen - yet another screen library.
#
# yascreen is free software, released under the terms of GNU Lesser General Public License v3.0 or later
#
# }}}
# configure install path
PREFIX?=/usr/local
LIBDIR?=/lib/
INCDIR?=/include/
# configure debug or release build
# for debug build, uncomment the line below
#DEBUG?=-DDEBUG=1 -O0 -g3 -fno-inline -fstack-protector-all
DEBUG?=-O3
# configure default tools
# make defines AR, so we have to override to gcc-ar, so -flto works
AR=gcc-ar
RANLIB?=gcc-ranlib
INSTALL?=install
########################## end of configurable section #########################
VER=$(shell grep Revision yascreen.c|head -n1|sed -e 's/.\+Revision: \([0-9.]\+\) \+.\+/\1/'|tr . ' '|awk '{printf "%i.%02u\n",$$1+$$2/100,$$2%100}')
# shared library version
SOVERM:=0
SOVERF:=0.0.0
SONAME:=-Wl,-soname,libyascreen.so.$(SOVERM)
ifeq ($(shell uname -s),Darwin) # tested on 17.7
AR=ar
RANLIB=ranlib
NO_VERSIONED:=1
NO_FLTO:=1
SONAME:=
endif
ifeq ($(shell uname -s),FreeBSD) # tested on 14.0
AR=ar
RANLIB=ranlib
endif
ifeq ($(shell uname -s),OpenBSD) # tested on 7.2
AR=ar
RANLIB=ranlib
NO_VERSIONED:=1
endif
ifeq ($(shell uname -s),NetBSD) # tested on 9.3
AR=ar
RANLIB=ranlib
NO_VERSIONED:=1
NO_FLTO:=1
endif
ifndef NO_FLTO
CHECK_CC_FLAGS:=-Wall -Wextra -I. --std=gnu89 -fPIC -flto=auto
else
CHECK_CC_FLAGS:=-Wall -Wextra -I. --std=gnu89 -fPIC
endif
# remove unsupported flags from CCOPT
define check_cc_flag
$(shell echo 'int main(){return 0;}'|$(CC) $(1) -xc - -o /dev/null 2>/dev/null && echo $(1))
endef
HAVE_FLAGS+=$(foreach flag,$(CHECK_CC_FLAGS),$(call check_cc_flag,$(flag)))
CCOPT:=$(HAVE_FLAGS)
# build versioned library by default
ifndef NO_VERSIONED
CCOPT+=-DYASCREEN_VERSIONED=1
LDOPT:=-Wl,--version-script,yascreen.vers
else
CCOPT+=-DYASCREEN_VERSIONED=0
endif
# allow to pass additional compiler flags
MYCFLAGS=$(DEBUG) $(CPPFLAGS) $(CFLAGS) $(CCOPT)
MYLDFLAGS=$(LDFLAGS) $(LDOPT)
all: libyascreen.a libyascreen.so yascreen.pc
yascreen.o: yascreen.c yascreen.h yascreen_feed.c
$(CC) $(MYCFLAGS) -o $@ -c $<
yastest.o: yastest.c yascreen.h
$(CC) $(MYCFLAGS) -o $@ -c $<
yastest: yastest.o yascreen.o
$(CC) $(MYCFLAGS) -o $@ $^
yastest.shared: yastest.o libyascreen.so
$(CC) $(MYCFLAGS) -o $@ $^ -L. -lyascreen
libyascreen.a: yascreen.o
$(AR) r $@ $^
$(RANLIB) $@
libyascreen.so: libyascreen.so.$(SOVERM)
ln -fs $^ $@
libyascreen.so.$(SOVERM): libyascreen.so.$(SOVERF)
ln -fs $^ $@
libyascreen.so.$(SOVERF): yascreen.o yascreen.vers
$(CC) $(MYCFLAGS) $(MYLDFLAGS) -o $@ $< -fPIC -shared $(SONAME)
yascreen.pc: yascreen.pc.in
sed \
-e 's|YASCREENVERSION|$(VER)|' \
-e 's|YASCREENPREFIX|$(PREFIX)|' \
-e 's|YASCREENLIBDIR|$(PREFIX)$(LIBDIR)|' \
-e 's|YASCREENINCDIR|$(PREFIX)$(INCDIR)|' \
< $< > $@
install: libyascreen.a libyascreen.so yascreen.pc yascreen.3
$(INSTALL) -Ds -m 0644 -t $(DESTDIR)$(PREFIX)$(LIBDIR) libyascreen.a
$(INSTALL) -D -m 0644 -t $(DESTDIR)$(PREFIX)$(LIBDIR)/pkgconfig/ yascreen.pc
ln -fs libyascreen.so.$(SOVERF) $(DESTDIR)$(PREFIX)$(LIBDIR)libyascreen.so.$(SOVERM)
ln -fs libyascreen.so.$(SOVERM) $(DESTDIR)$(PREFIX)$(LIBDIR)libyascreen.so
$(INSTALL) -Ds -m 0644 -t $(DESTDIR)$(PREFIX)$(LIBDIR) libyascreen.so.$(SOVERF)
$(INSTALL) -D -m 0644 -t $(DESTDIR)$(PREFIX)$(INCDIR) yascreen.h
$(INSTALL) -D -m 0644 yascreen.3 $(DESTDIR)$(PREFIX)/share/man/man3/yascreen.3
clean:
rm -f yastest yastest.shared yastest.o yascreen.o libyascreen.a libyascreen.so libyascreen.so.$(SOVERM) libyascreen.so.$(SOVERF) yascreen.pc
re: rebuild
rebuild:
$(MAKE) clean
$(MAKE) -j all
mkotar:
$(MAKE) clean
dh_clean
$(MAKE) yascreen.3
tar \
--xform 's,^[.],yascreen-$(VER),' \
--exclude ./.git \
--exclude ./.github/CVS \
--exclude ./.github/workflows/CVS \
--exclude ./.gitignore \
--exclude ./.cvsignore \
--exclude ./CVS \
--exclude ./debian \
--exclude ./fedora/CVS \
-Jcvf ../yascreen_$(VER).orig.tar.xz .
-rm -f ../yascreen_$(VER).orig.tar.xz.asc
gpg -a --detach-sign ../yascreen_$(VER).orig.tar.xz
cp -fa ../yascreen_$(VER).orig.tar.xz ../yascreen-$(VER).tar.xz
cp -fa ../yascreen_$(VER).orig.tar.xz.asc ../yascreen-$(VER).tar.xz.asc
yascreen.3: README.md
go-md2man < README.md > yascreen.3
.PHONY: install clean rebuild re all mkotar