blob: a97f380d60f198c1ee988e3f93402e6273b25ccb [file] [log] [blame]
Patrick Georgi593124d2020-05-10 19:44:08 +02001# SPDX-License-Identifier: GPL-2.0-or-later
Philipp Deppenwiesed8fe4432016-03-18 00:52:54 +01002
3PROGRAM = intelmetool
4
5CC ?= gcc
Yegor Timoshenkoc2e49412018-10-07 01:58:27 +00006INSTALL ?= /usr/bin/env install
Philipp Deppenwiesed8fe4432016-03-18 00:52:54 +01007PREFIX ?= /usr/local
Jacob Garber52f0e842019-07-19 12:27:27 -06008CFLAGS ?= -O0 -g -Wall -Wextra -Wno-unused-parameter -Wno-sign-compare -Wno-unused-function
Philipp Deppenwiesed8fe4432016-03-18 00:52:54 +01009LDFLAGS += -lpci -lz
10
Philipp Deppenwiese73add172016-08-26 02:10:51 +020011OBJS = intelmetool.o me.o me_status.o mmap.o rcba.o msr.o
Philipp Deppenwiesed8fe4432016-03-18 00:52:54 +010012
13OS_ARCH = $(shell uname)
14ifeq ($(OS_ARCH), Darwin)
15LDFLAGS += -framework DirectHW
16endif
17ifeq ($(OS_ARCH), FreeBSD)
18CFLAGS += -I/usr/local/include
19LDFLAGS += -L/usr/local/lib
20LIBS = -lz
21endif
22ifeq ($(OS_ARCH), NetBSD)
23CFLAGS += -I/usr/pkg/include
24LDFLAGS += -L/usr/pkg/lib -Wl,-rpath-link,/usr/pkg/lib -lz -lpciutils -lpci -l$(shell uname -p)
25endif
26
27all: pciutils dep $(PROGRAM)
28
Matthias Gazzarid88cd702018-05-21 20:54:41 +020029oldarc: CFLAGS += -DOLDARC
30oldarc: all
31
Philipp Deppenwiesed8fe4432016-03-18 00:52:54 +010032$(PROGRAM): $(OBJS)
33 $(CC) $(CFLAGS) -o $(PROGRAM) $(OBJS) $(LDFLAGS)
34
35clean:
36 rm -f $(PROGRAM) *.o *~ junit.xml
37
38distclean: clean
39 rm -f .dependencies
40
41dep:
42 @$(CC) $(CFLAGS) -MM *.c > .dependencies
43
44define LIBPCI_TEST
45/* Avoid a failing test due to libpci header symbol shadowing breakage */
46#define index shadow_workaround_index
47#ifdef __NetBSD__
48#include <pciutils/pci.h>
49#else
50#include <pci/pci.h>
51#endif
52struct pci_access *pacc;
53int main(int argc, char **argv)
54{
55 (void) argc;
56 (void) argv;
57 pacc = pci_alloc();
58 return 0;
59}
60endef
61export LIBPCI_TEST
62
63pciutils:
Vincent Legoll0d2ff132017-05-07 17:51:25 +020064 @printf "\nChecking for development libraries: pci and zlib... "
Philipp Deppenwiesed8fe4432016-03-18 00:52:54 +010065 @echo "$$LIBPCI_TEST" > .test.c
66 @$(CC) $(CFLAGS) .test.c -o .test $(LDFLAGS) >/dev/null 2>&1 && \
67 printf "found.\n" || ( printf "not found.\n\n"; \
Vincent Legoll0d2ff132017-05-07 17:51:25 +020068 printf "For RPM based distributions like Fedora, please install pciutils-devel and zlib-devel.\n"; \
69 printf "For DEB based distributions, please install libpci-dev and zlib1g-dev.\n"; \
Philipp Deppenwiesed8fe4432016-03-18 00:52:54 +010070 rm -f .test.c .test; exit 1)
71 @rm -rf .test.c .test .test.dSYM
72
73install: $(PROGRAM)
74 mkdir -p $(DESTDIR)$(PREFIX)/sbin
75 $(INSTALL) $(PROGRAM) $(DESTDIR)$(PREFIX)/sbin
76
Matthias Gazzarid88cd702018-05-21 20:54:41 +020077.PHONY: all clean distclean dep pciutils oldarc
Philipp Deppenwiesed8fe4432016-03-18 00:52:54 +010078
79-include .dependencies