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
|
# The make-provided flags like MAKE and CC aren't set, on purpose.
# This is Linux-specific software, so we can depend on GNU make.
# Options:
# nls enable translations, default on
# debug enable debug symbols, default off
# nostrip disable stripping, default off
# plain apply neither -g nor -s.
# xcb enable libxcb to run unprivileged in Xorg, default on
# amdgpu enable amdgpu usage reporting, default auto
# it requires libdrm >= 2.4.63
PREFIX ?= /usr
INSTALL ?= install
LIBDIR ?= lib
MANDIR ?= share/man
nls ?= 1
xcb ?= 1
bin = radeontop
xcblib = libradeontop_xcb.so
src = $(filter-out amdgpu.c auth_xcb.c,$(wildcard *.c))
verh = include/version.h
CFLAGS_SECTIONED = -ffunction-sections -fdata-sections
LDFLAGS_SECTIONED = -Wl,-gc-sections
CFLAGS ?= -Os
CFLAGS += -Wall -Wextra -pthread
CFLAGS += -Iinclude
CFLAGS += $(CFLAGS_SECTIONED)
CFLAGS += $(shell pkg-config --cflags pciaccess)
CFLAGS += $(shell pkg-config --cflags libdrm)
ifeq ($(xcb), 1)
CFLAGS += $(shell pkg-config --cflags xcb xcb-dri2)
CFLAGS += -DENABLE_XCB=1
endif
CFLAGS += $(shell pkg-config --cflags ncurses 2>/dev/null)
# Comment this if you don't want translations
ifeq ($(nls), 1)
CFLAGS += -DENABLE_NLS=1
endif
# autodetect libdrm features
ifeq ($(shell pkg-config --atleast-version=2.4.66 libdrm && echo ok), ok)
CFLAGS += -DHAS_DRMGETDEVICE=1
endif
ifeq ($(shell pkg-config --atleast-version=2 libdrm_amdgpu && echo ok), ok)
amdgpu ?= 1
else
amdgpu ?= 0
endif
ifeq ($(amdgpu), 1)
src += amdgpu.c
CFLAGS += -DENABLE_AMDGPU=1
LIBS += $(shell pkg-config --libs libdrm_amdgpu)
ifeq ($(shell pkg-config --atleast-version=2.4.79 libdrm_amdgpu && echo ok), ok)
CFLAGS += -DHAS_AMDGPU_QUERY_SENSOR_INFO=1
endif
endif
ifndef plain
ifdef debug
CFLAGS += -g
else ifndef nostrip
CFLAGS += -s
endif
endif
obj = $(src:.c=.o)
LDFLAGS ?= -Wl,-O1
LDFLAGS += $(LDFLAGS_SECTIONED)
LIBS += $(shell pkg-config --libs pciaccess)
LIBS += $(shell pkg-config --libs libdrm)
LIBS += -lm
ifeq ($(xcb), 1)
xcb_LIBS += $(shell pkg-config --libs xcb xcb-dri2)
LIBS += -ldl
endif
# On some distros, you might have to change this to ncursesw
LIBS += $(shell pkg-config --libs ncursesw 2>/dev/null || \
shell pkg-config --libs ncurses 2>/dev/null || \
echo "-lncurses")
.PHONY: all clean install man dist
all: $(bin)
ifeq ($(xcb), 1)
all: $(xcblib)
$(xcblib): auth_xcb.c $(wildcard include/*.h) $(verh)
$(CC) -shared -fPIC -Wl,-soname,$@ -o $@ $< $(CFLAGS) $(LDFLAGS) $(xcb_LIBS)
endif
$(obj): $(wildcard include/*.h) $(verh)
$(bin): $(obj)
$(CC) -o $(bin) $(obj) $(CFLAGS) $(LDFLAGS) $(LIBS)
clean:
rm -f *.o $(bin) $(xcblib)
.git:
$(verh): .git
./getver.sh
trans:
xgettext -o translations/radeontop.pot -k_ *.c \
--package-name radeontop
install: all
$(INSTALL) -D -m755 $(bin) $(DESTDIR)/$(PREFIX)/bin/$(bin)
ifeq ($(xcb), 1)
$(INSTALL) -D -m755 $(xcblib) $(DESTDIR)/$(PREFIX)/$(LIBDIR)/$(xcblib)
endif
$(INSTALL) -D -m644 radeontop.1 $(DESTDIR)/$(PREFIX)/$(MANDIR)/man1/radeontop.1
ifeq ($(nls), 1)
$(MAKE) -C translations install PREFIX=$(PREFIX)
endif
man:
a2x -f manpage radeontop.asc
dist: ver = $(shell git describe)
dist: name = $(bin)-$(ver)
dist: clean $(verh)
sed -i '/\t\.\/getver.sh/d' Makefile
cd .. && \
ln -s $(bin) $(name) && \
tar -h --numeric-owner --exclude-vcs -cvf - $(name) | pigz -9 > /tmp/$(name).tgz && \
rm $(name)
advdef -z4 /tmp/$(name).tgz
git checkout Makefile
cd /tmp && sha1sum $(name).tgz > $(name).tgz.sha1
|