1# SPDX-License-Identifier: GPL-2.0-or-later 2 3PROGRAM = inteltool 4 5top ?= $(abspath ../..) 6 7CC ?= gcc 8INSTALL ?= /usr/bin/env install 9PREFIX ?= /usr/local 10CFLAGS ?= -O2 -g -Wall -Wextra -Wmissing-prototypes 11LDFLAGS += -lpci -lz 12 13CPPFLAGS += -I$(top)/util/inteltool 14CPPFLAGS += -I$(top)/src/commonlib/include -I$(top)/src/commonlib/bsd/include 15CPPFLAGS += -I$(top)/src/arch/x86/include 16 17 18OBJS = inteltool.o pcr.o cpu.o gpio.o gpio_groups.o rootcmplx.o powermgt.o \ 19 memory.o pcie.o amb.o ivy_memory.o spi.o gfx.o ahci.o lpc.o iobp.o 20 21OS_ARCH = $(shell uname) 22ifeq ($(OS_ARCH), Darwin) 23LDFLAGS += -framework DirectHW 24endif 25ifeq ($(OS_ARCH), FreeBSD) 26CPPFLAGS += -I/usr/local/include 27LDFLAGS += -L/usr/local/lib 28LIBS = -lz 29endif 30ifeq ($(OS_ARCH), NetBSD) 31CPPFLAGS += -I/usr/pkg/include 32LDFLAGS += -L/usr/pkg/lib -Wl,-rpath-link,/usr/pkg/lib -lz -lpciutils -lpci -l$(shell uname -p) 33endif 34 35all: pciutils dep $(PROGRAM) 36 37$(PROGRAM): $(OBJS) 38 $(CC) $(CFLAGS) $(CPPFLAGS) -o $(PROGRAM) $(OBJS) $(LDFLAGS) 39 40clean: 41 rm -f $(PROGRAM) *.o *~ junit.xml .dependencies 42 43distclean: clean 44 rm -f .dependencies 45 46dep: 47 @$(CC) $(CFLAGS) $(CPPFLAGS) -MM *.c > .dependencies 48 49define LIBPCI_TEST 50/* Avoid a failing test due to libpci header symbol shadowing breakage */ 51#define index shadow_workaround_index 52#ifdef __NetBSD__ 53#include <pciutils/pci.h> 54#else 55#include <pci/pci.h> 56#endif 57struct pci_access *pacc; 58int main(int argc, char **argv) 59{ 60 (void) argc; 61 (void) argv; 62 pacc = pci_alloc(); 63 return 0; 64} 65endef 66export LIBPCI_TEST 67 68pciutils: 69 @printf "\nChecking for pciutils and zlib... " 70 @echo "$$LIBPCI_TEST" > .test.c 71 @$(CC) $(CFLAGS) $(CPPFLAGS) .test.c -o .test $(LDFLAGS) \ 72 >/dev/null 2>&1 && \ 73 printf "found.\n" || ( printf "not found.\n\n"; \ 74 printf "Please install pciutils-devel and zlib-devel.\n"; \ 75 printf "See README for more information.\n\n"; \ 76 rm -f .test.c .test; exit 1) 77 @rm -rf .test.c .test .test.dSYM 78 79install: $(PROGRAM) 80 $(INSTALL) -d $(DESTDIR)$(PREFIX)/sbin 81 $(INSTALL) $(PROGRAM) $(DESTDIR)$(PREFIX)/sbin 82 $(INSTALL) -d $(DESTDIR)$(PREFIX)/share/man/man8 83 $(INSTALL) -p -m644 $(PROGRAM).8 $(DESTDIR)$(PREFIX)/share/man/man8 84 85.PHONY: all clean distclean dep pciutils 86 87-include .dependencies 88