blob: 375118576aa8e3cacfd413a77b643e6275e6bd53 [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
Konrad Adamczykd6b4db12023-04-11 10:26:12 +00005TOP ?= $(abspath ../..)
Philipp Deppenwiesed8fe4432016-03-18 00:52:54 +01006CC ?= gcc
Yegor Timoshenkoc2e49412018-10-07 01:58:27 +00007INSTALL ?= /usr/bin/env install
Philipp Deppenwiesed8fe4432016-03-18 00:52:54 +01008PREFIX ?= /usr/local
Konrad Adamczykd6b4db12023-04-11 10:26:12 +00009CFLAGS ?= -O0 -g -Wall -Wextra -Wno-unused-parameter -Wno-sign-compare -Wno-unused-function \
10 -I $(TOP)/src/commonlib/bsd/include
Philipp Deppenwiesed8fe4432016-03-18 00:52:54 +010011LDFLAGS += -lpci -lz
12
Philipp Deppenwiese73add172016-08-26 02:10:51 +020013OBJS = intelmetool.o me.o me_status.o mmap.o rcba.o msr.o
Philipp Deppenwiesed8fe4432016-03-18 00:52:54 +010014
15OS_ARCH = $(shell uname)
16ifeq ($(OS_ARCH), Darwin)
17LDFLAGS += -framework DirectHW
18endif
19ifeq ($(OS_ARCH), FreeBSD)
20CFLAGS += -I/usr/local/include
21LDFLAGS += -L/usr/local/lib
22LIBS = -lz
23endif
24ifeq ($(OS_ARCH), NetBSD)
25CFLAGS += -I/usr/pkg/include
26LDFLAGS += -L/usr/pkg/lib -Wl,-rpath-link,/usr/pkg/lib -lz -lpciutils -lpci -l$(shell uname -p)
27endif
28
29all: pciutils dep $(PROGRAM)
30
Matthias Gazzarid88cd702018-05-21 20:54:41 +020031oldarc: CFLAGS += -DOLDARC
32oldarc: all
33
Philipp Deppenwiesed8fe4432016-03-18 00:52:54 +010034$(PROGRAM): $(OBJS)
35 $(CC) $(CFLAGS) -o $(PROGRAM) $(OBJS) $(LDFLAGS)
36
37clean:
38 rm -f $(PROGRAM) *.o *~ junit.xml
39
40distclean: clean
41 rm -f .dependencies
42
43dep:
44 @$(CC) $(CFLAGS) -MM *.c > .dependencies
45
46define LIBPCI_TEST
47/* Avoid a failing test due to libpci header symbol shadowing breakage */
48#define index shadow_workaround_index
49#ifdef __NetBSD__
50#include <pciutils/pci.h>
51#else
52#include <pci/pci.h>
53#endif
54struct pci_access *pacc;
55int main(int argc, char **argv)
56{
57 (void) argc;
58 (void) argv;
59 pacc = pci_alloc();
60 return 0;
61}
62endef
63export LIBPCI_TEST
64
65pciutils:
Vincent Legoll0d2ff132017-05-07 17:51:25 +020066 @printf "\nChecking for development libraries: pci and zlib... "
Philipp Deppenwiesed8fe4432016-03-18 00:52:54 +010067 @echo "$$LIBPCI_TEST" > .test.c
68 @$(CC) $(CFLAGS) .test.c -o .test $(LDFLAGS) >/dev/null 2>&1 && \
69 printf "found.\n" || ( printf "not found.\n\n"; \
Vincent Legoll0d2ff132017-05-07 17:51:25 +020070 printf "For RPM based distributions like Fedora, please install pciutils-devel and zlib-devel.\n"; \
71 printf "For DEB based distributions, please install libpci-dev and zlib1g-dev.\n"; \
Philipp Deppenwiesed8fe4432016-03-18 00:52:54 +010072 rm -f .test.c .test; exit 1)
73 @rm -rf .test.c .test .test.dSYM
74
75install: $(PROGRAM)
76 mkdir -p $(DESTDIR)$(PREFIX)/sbin
77 $(INSTALL) $(PROGRAM) $(DESTDIR)$(PREFIX)/sbin
78
Matthias Gazzarid88cd702018-05-21 20:54:41 +020079.PHONY: all clean distclean dep pciutils oldarc
Philipp Deppenwiesed8fe4432016-03-18 00:52:54 +010080
81-include .dependencies