| 1 |
# SPDX-License-Identifier: GPL-2.0-or-later |
| 2 |
|
| 3 |
PROGRAM = intelmetool |
| 4 |
|
| 5 |
TOP ?= $(abspath ../..) |
| 6 |
CC ?= gcc |
| 7 |
INSTALL ?= /usr/bin/env install |
| 8 |
PREFIX ?= /usr/local |
| 9 |
CFLAGS ?= -O0 -g -Wall -Wextra -Wno-unused-parameter -Wno-sign-compare -Wno-unused-function \ |
| 10 |
-I $(TOP)/src/commonlib/bsd/include |
| 11 |
LDFLAGS += -lpci -lz |
| 12 |
|
| 13 |
OBJS = intelmetool.o me.o me_status.o mmap.o rcba.o msr.o |
| 14 |
|
| 15 |
OS_ARCH = $(shell uname) |
| 16 |
ifeq ($(OS_ARCH), Darwin) |
| 17 |
LDFLAGS += -framework DirectHW |
| 18 |
endif |
| 19 |
ifeq ($(OS_ARCH), FreeBSD) |
| 20 |
CFLAGS += -I/usr/local/include |
| 21 |
LDFLAGS += -L/usr/local/lib |
| 22 |
LIBS = -lz |
| 23 |
endif |
| 24 |
ifeq ($(OS_ARCH), NetBSD) |
| 25 |
CFLAGS += -I/usr/pkg/include |
| 26 |
LDFLAGS += -L/usr/pkg/lib -Wl,-rpath-link,/usr/pkg/lib -lz -lpciutils -lpci -l$(shell uname -p) |
| 27 |
endif |
| 28 |
|
| 29 |
all: pciutils dep $(PROGRAM) |
| 30 |
|
| 31 |
oldarc: CFLAGS += -DOLDARC |
| 32 |
oldarc: all |
| 33 |
|
| 34 |
$(PROGRAM): $(OBJS) |
| 35 |
$(CC) $(CFLAGS) -o $(PROGRAM) $(OBJS) $(LDFLAGS) |
| 36 |
|
| 37 |
clean: |
| 38 |
rm -f $(PROGRAM) *.o *~ junit.xml |
| 39 |
|
| 40 |
distclean: clean |
| 41 |
rm -f .dependencies |
| 42 |
|
| 43 |
dep: |
| 44 |
@$(CC) $(CFLAGS) -MM *.c > .dependencies |
| 45 |
|
| 46 |
define 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 |
| 54 |
struct pci_access *pacc; |
| 55 |
int main(int argc, char **argv) |
| 56 |
{ |
| 57 |
(void) argc; |
| 58 |
(void) argv; |
| 59 |
pacc = pci_alloc(); |
| 60 |
return 0; |
| 61 |
} |
| 62 |
endef |
| 63 |
export LIBPCI_TEST |
| 64 |
|
| 65 |
pciutils: |
| 66 |
@printf "\nChecking for development libraries: pci and zlib... " |
| 67 |
@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"; \ |
| 70 |
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"; \ |
| 72 |
rm -f .test.c .test; exit 1) |
| 73 |
@rm -rf .test.c .test .test.dSYM |
| 74 |
|
| 75 |
install: $(PROGRAM) |
| 76 |
mkdir -p $(DESTDIR)$(PREFIX)/sbin |
| 77 |
$(INSTALL) $(PROGRAM) $(DESTDIR)$(PREFIX)/sbin |
| 78 |
|
| 79 |
.PHONY: all clean distclean dep pciutils oldarc |
| 80 |
|
| 81 |
-include .dependencies |