Debian Codegraph @

Makefile

raw
1 # use this to disable flto optimizations:
2 # make NO_FLTO=1
3 # and this to enable verbose mode:
4 # make V=1
5 # an example how to build with CFI (https://en.wikipedia.org/wiki/Control-flow_integrity)
6 # CC=clang-17 CFLAGS="-fsanitize=cfi -fno-sanitize-trap -fvisibility=hidden" make
7
8 #
9 # SPDX-License-Identifier: GPL-2.0-or-later
10 #
11 # Copyright (C) 2014 Vyacheslav Trushkin
12 # Copyright (C) 2020-2026 Boian Bonev
13 #
14 # This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
15 #
16 # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #
20
21 TARGET=iotop
22
23 SRCS:=$(wildcard src/*.c)
24 OBJS:=$(patsubst %c,%o,$(patsubst src/%,bld/%,$(SRCS)))
25 DEPS:=$(OBJS:.o=.d)
26
27 ifndef NO_FLTO
28 CFLAGS?=-O3 -fno-stack-protector -mno-stackrealign
29 CFLAGS+=-flto=auto
30 else
31 CFLAGS?=-O3 -fno-stack-protector -mno-stackrealign
32 endif
33
34 ifdef GCCFANALIZER
35 CFLAGS+=-fanalyzer
36 endif
37
38 PREFIX?=$(DESTDIR)/usr
39 BINDIR?=$(PREFIX)/sbin
40 INSTALL?=install
41 STRIP?=strip
42
43 PKG_CONFIG?=pkg-config
44 NCCC?=$(shell $(PKG_CONFIG) --cflags ncursesw)
45 NCLD?=$(shell $(PKG_CONFIG) --libs ncursesw)
46 ifeq ("$(NCLD)","")
47 NCCC:=$(shell $(PKG_CONFIG) --cflags ncurses)
48 NCLD:=$(shell $(PKG_CONFIG) --libs ncurses)
49 endif
50 ifeq ("$(NCLD)","")
51 NCCC:=
52 NCLD:=-lncursesw
53 endif
54
55 # for glibc < 2.17, -lrt is required for clock_gettime
56 NEEDLRT:=$(shell if $(CC) -E glibcvertest.h -o -|grep IOTOP_NEED_LRT|grep -q yes;then echo need; fi)
57 # some architectures do not have -mno-stackrealign
58 HAVESREA:=$(shell if $(CC) -mno-stackrealign -xc -c /dev/null -o /dev/null >/dev/null 2>/dev/null;then echo yes;else echo no;fi)
59 # old comiplers do not have -Wdate-time
60 HAVEWDTI:=$(shell if $(CC) -Wdate-time -xc -c /dev/null -o /dev/null >/dev/null 2>/dev/null;then echo yes;else echo no;fi)
61 # old compilers can not generate dependencies
62 HAVEDEPS:=$(shell if $(CC) -MM -MT /dev/null -MF /dev/null /dev/null >/dev/null 2>/dev/null;then echo yes;else echo no;fi)
63 # old compilers do not understand C standard
64 HAVECSTD:=$(shell if $(CC) --std=gnu89 -xc -c /dev/null -o /dev/null >/dev/null 2>/dev/null;then echo yes;else echo no;fi)
65 # old compilers do not understand -flto=auto
66 HAVEFLTA:=$(shell if $(CC) -flto=auto -xc -c /dev/null -o /dev/null >/dev/null 2>/dev/null;then echo yes;else echo no;fi)
67 # old compilers do not understand -flto at all
68 HAVEFLTO:=$(shell if $(CC) -flto -xc -c /dev/null -o /dev/null >/dev/null 2>/dev/null;then echo yes;else echo no;fi)
69 # old compilers do not understand -pie; clang yields error when stderr is redirected :(
70 HAVELPIE:=$(shell if $(CC) -Wno-unused-command-line-argument -pie -xc -c /dev/null -o /dev/null >/dev/null 2>/dev/null;then echo yes;else echo no;fi)
71
72 MYCFLAGS:=$(CPPFLAGS) $(CFLAGS) $(NCCC) -Wall -Wextra -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 --std=gnu89 -fPIE
73 MYLIBS:=$(NCLD) $(LIBS)
74 MYLDFLAGS:=$(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -fPIE -pie
75
76 ifeq ("$(HAVESREA)","no")
77 MYCFLAGS:=$(filter-out -mno-stackrealign,$(MYCFLAGS))
78 MYLDFLAGS:=$(filter-out -mno-stackrealign,$(MYLDFLAGS))
79 endif
80
81 ifeq ("$(HAVEWDTI)","no")
82 MYCFLAGS:=$(filter-out -Wdate-time,$(MYCFLAGS))
83 MYLDFLAGS:=$(filter-out -Wdate-time,$(MYLDFLAGS))
84 endif
85
86 ifeq ("$(HAVECSTD)","no")
87 MYCFLAGS:=$(filter-out --std=gnu89,$(MYCFLAGS))
88 MYLDFLAGS:=$(filter-out --std=gnu89,$(MYLDFLAGS))
89 MYCFLAGS:=$(filter-out -D_FORTIFY_SOURCE=2,$(MYCFLAGS))
90 MYLDFLAGS:=$(filter-out -D_FORTIFY_SOURCE=2,$(MYLDFLAGS))
91 endif
92
93 ifeq ("$(HAVEFLTA)","no")
94 ifndef NO_FLTO
95 ifeq ("$(HAVEFLTA)","no")
96 MYCFLAGS:=$(filter-out -flto=auto,$(MYCFLAGS))
97 MYLDFLAGS:=$(filter-out -flto=auto,$(MYLDFLAGS))
98 else
99 MYCFLAGS:=$(filter-out -flto=auto,$(MYCFLAGS))
100 MYLDFLAGS:=$(filter-out -flto=auto,$(MYLDFLAGS))
101 MYCFLAGS+=-flto
102 MYLDFLAGS+=-flto
103 endif
104 endif
105 endif
106
107 ifeq ("$(HAVELPIE)","no")
108 MYLDFLAGS:=$(filter-out -pie,$(MYLDFLAGS))
109 endif
110
111 ifeq ("$(NEEDLRT)","need")
112 MYLDFLAGS+=-lrt
113 endif
114
115 ifeq ("$(V)","1")
116 Q:=
117 E:=@true
118 else
119 Q:=@
120 E:=@echo
121 endif
122
123 ifeq ("$(HAVEDEPS)","no")
124 NDEP:=@true
125 else
126 NDEP:=
127 endif
128
129 all: $(TARGET)
130
131 $(TARGET): $(OBJS)
132 $(E) LD $@
133 $(Q)$(CC) -o $@ $(MYLDFLAGS) $^ $(MYLIBS)
134
135 bld/%.o: src/%.c bld/.mkdir
136 $(NDEP) $(E) DE $@
137 $(NDEP) $(Q)$(CC) $(MYCFLAGS) -MM -MT $@ -MF $(patsubst %.o,%.d,$@) $<
138 $(E) CC $@
139 $(Q)$(CC) $(MYCFLAGS) -c -o $@ $<
140
141 clean:
142 $(E) CLEAN
143 $(Q)rm -rf ./bld $(TARGET)
144
145 install: $(TARGET)
146 $(E) STRIP $(TARGET)
147 $(Q)$(STRIP) $(TARGET)
148 $(E) INSTALL $(TARGET)
149 $(Q)$(INSTALL) -D -m 0755 $(TARGET) $(BINDIR)/$(TARGET)
150 $(Q)$(INSTALL) -D -m 0644 iotop.8 $(PREFIX)/share/man/man8/iotop.8
151
152 uninstall:
153 $(E) UNINSTALL $(TARGET)
154 $(Q)rm -f $(BINDIR)/$(TARGET)
155 $(Q)rm -f $(PREFIX)/share/man/man8/iotop.8
156
157 bld/.mkdir:
158 $(Q)mkdir -p bld
159 $(Q)touch bld/.mkdir
160
161 VER:=$(shell grep ' VERSION ' src/iotop.h|tr -d '\"'|awk '{print $$3}')
162 mkotar:
163 $(MAKE) clean
164 -dh_clean
165 tar \
166 --xform 's,^[.],iotop-$(VER),' \
167 --exclude ./.git \
168 --exclude ./.gitignore \
169 --exclude ./debian \
170 -Jcvf ../iotop-c_$(VER).orig.tar.xz .
171 -rm -f ../iotop-c_$(VER).orig.tar.xz.asc
172 gpg -a --detach-sign ../iotop-c_$(VER).orig.tar.xz
173 cp -fa ../iotop-c_$(VER).orig.tar.xz ../iotop-$(VER).tar.xz
174 cp -fa ../iotop-c_$(VER).orig.tar.xz.asc ../iotop-$(VER).tar.xz.asc
175
176 re:
177 $(Q)$(MAKE) --no-print-directory clean
178 $(Q)$(MAKE) --no-print-directory -j
179
180 pv:
181 @echo CFLAGS: $(CFLAGS)
182 @echo LDFLAGS: $(LDFLAGS)
183 @echo LIBS: $(LIBS)
184 @echo NCCC: $(NCCC)
185 @echo NCLD: $(NCLD)
186 @echo NEEDLRT: $(NEEDLRT)
187 @echo HAVESREA: $(HAVESREA)
188 @echo HAVEWDTI: $(HAVEWDTI)
189 @echo HAVEDEPS: $(HAVEDEPS)
190 @echo HAVECSTD: $(HAVECSTD)
191 @echo HAVEFLTA: $(HAVEFLTA)
192 @echo HAVEFLTO: $(HAVEFLTO)
193 @echo HAVELPIE: $(HAVELPIE)
194 @echo MYCFLAGS: $(MYCFLAGS)
195 @echo MYLDFLAGS: $(MYLDFLAGS)
196 @echo MYLIBS: $(MYLIBS)
197
198 -include $(DEPS)
199
200 .PHONY: all clean install uninstall mkotar re pv