xref: /aosp_15_r20/external/coreboot/util/superiotool/Makefile (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1# SPDX-License-Identifier: GPL-2.0-or-later
2
3PROGRAM = superiotool
4
5TOP     ?= $(abspath ../..)
6CC      ?= gcc
7INSTALL ?= /usr/bin/env install
8PREFIX  ?= /usr/local
9
10# Set the superiotool version string to the output of 'git describe'.
11
12VERSION := -D'SUPERIOTOOL_VERSION="$(shell git describe 2>/dev/null)"'
13
14CFLAGS += -O2 -Wall -Wstrict-prototypes -Wundef -Wstrict-aliasing \
15         -Werror-implicit-function-declaration -std=c11 -pedantic $(VERSION) \
16         -Wno-variadic-macros -I $(TOP)/src/commonlib/bsd/include
17LDFLAGS += -lz
18
19OBJS = superiotool.o serverengines.o ali.o exar.o fintek.o ite.o nsc.o \
20       nuvoton.o smsc.o winbond.o infineon.o aspeed.o
21
22OS_ARCH ?= $(shell uname)
23ifeq ($(OS_ARCH), Darwin)
24LIBS = -framework IOKit -framework DirectHW -lpci -lz
25endif
26ifeq ($(OS_ARCH), FreeBSD)
27CFLAGS = -O2 -Wall -Werror -Wstrict-prototypes -Wundef -Wstrict-aliasing \
28         -Werror-implicit-function-declaration -std=c11 $(VERSION) \
29         -I/usr/local/include
30LDFLAGS += -L/usr/local/lib
31LIBS = -lz
32endif
33ifeq ($(OS_ARCH), NetBSD)
34CFLAGS += -I/usr/pkg/include
35LDFLAGS += -L/usr/pkg/lib -Wl,-rpath-link,/usr/pkg/lib
36LIBS = -lz -l$(shell uname -p)
37endif
38
39# Support for PCI-attached "Super I/Os" (e.g. in VIA VT82686A/B).
40CONFIG_PCI = yes
41
42ifeq ($(CONFIG_PCI), yes)
43CFLAGS += -DPCI_SUPPORT
44OBJS += pci.o via.o amd.o
45LIBS += -lpci
46ifeq ($(OS_ARCH),NetBSD)
47LIBS += -lpciutils
48endif
49endif
50
51all: pciutils $(PROGRAM)
52
53superiotool.o: *.c superiotool.h
54
55$(PROGRAM): $(OBJS) superiotool.h
56	$(CC) $(LDFLAGS) -o $(PROGRAM) $(OBJS) $(LIBS)
57
58install: $(PROGRAM)
59	$(INSTALL) -d $(DESTDIR)$(PREFIX)/sbin
60	$(INSTALL) $(PROGRAM) $(DESTDIR)$(PREFIX)/sbin
61	$(INSTALL) -d $(DESTDIR)$(PREFIX)/share/man/man8
62	$(INSTALL) -p -m644 $(PROGRAM).8 $(DESTDIR)$(PREFIX)/share/man/man8
63
64clean:
65	rm -f $(PROGRAM) *.o junit.xml
66
67distclean: clean
68
69.PHONY: all install clean distclean
70
71ifeq ($(CONFIG_PCI), yes)
72define LIBPCI_TEST
73/* Avoid a failing test due to libpci header symbol shadowing breakage */
74#define index shadow_workaround_index
75#ifdef __NetBSD__
76#include <pciutils/pci.h>
77#else
78#include <pci/pci.h>
79#endif
80struct pci_access *pacc;
81int main(int argc, char **argv)
82{
83	(void) argc;
84	(void) argv;
85	pacc = pci_alloc();
86	return 0;
87}
88endef
89export LIBPCI_TEST
90
91pciutils:
92	@printf "\nChecking for pciutils and zlib... "
93	@echo "$$LIBPCI_TEST" > .test.c
94	@$(CC) $(CFLAGS) .test.c -o .test $(LIBS) $(LDFLAGS) >/dev/null 2>&1 &&	  \
95		printf "found.\n" || ( printf "not found.\n\n";		  \
96		printf "Please install pciutils-devel and zlib-devel.\n"; \
97		printf "See README for more information.\n\n";		  \
98		rm -f .test.c .test; exit 1)
99	@rm -rf .test.c .test .test.dSYM
100endif
101