blob: f8c1cc1f86dff9a26640f0aded66ba76df277bcf [file] [log] [blame]
Patrick Georgi1afe2862020-05-10 17:34:15 +02001# SPDX-License-Identifier: GPL-2.0-or-later
Uwe Hermann1ae8e832007-09-01 20:20:41 +00002
3PROGRAM = superiotool
4
Paul Menzelbe2c6342013-03-28 11:44:19 +01005CC ?= gcc
Yegor Timoshenkoc2e49412018-10-07 01:58:27 +00006INSTALL ?= /usr/bin/env install
Paul Menzelbe2c6342013-03-28 11:44:19 +01007PREFIX ?= /usr/local
Uwe Hermann1ae8e832007-09-01 20:20:41 +00008
Guenter Roeck3397cef2012-06-29 12:25:46 -07009# Set the superiotool version string to the output of 'git describe'.
10
11VERSION := -D'SUPERIOTOOL_VERSION="$(shell git describe 2>/dev/null)"'
Ulf Jordan39a5bf72007-10-13 18:06:12 +000012
Mathias Krause14b67f72011-03-09 11:37:16 +010013CFLAGS += -O2 -Wall -Wstrict-prototypes -Wundef -Wstrict-aliasing \
Guenter Roeck3397cef2012-06-29 12:25:46 -070014 -Werror-implicit-function-declaration -ansi -pedantic $(VERSION)
Anders Juel Jensen280275d2010-08-22 19:39:04 +000015LDFLAGS += -lz
Uwe Hermann1ae8e832007-09-01 20:20:41 +000016
Derek Waldner3b421192016-04-14 12:13:48 -050017OBJS = superiotool.o serverengines.o ali.o exar.o fintek.o ite.o nsc.o \
Patrick Rudolph674bb3b2019-05-24 09:07:04 +020018 nuvoton.o smsc.o winbond.o infineon.o aspeed.o
Uwe Hermann0120e1a2007-09-16 18:11:03 +000019
Maciej Gabryelski1fc12db2022-04-21 08:28:01 +020020OS_ARCH ?= $(shell uname)
Stefan Reinauere95eb612009-09-01 09:57:55 +000021ifeq ($(OS_ARCH), Darwin)
Stefan Reinauercff573d2011-03-18 22:08:39 +000022LIBS = -framework IOKit -framework DirectHW -lpci -lz
Stefan Reinauere95eb612009-09-01 09:57:55 +000023endif
Idwer Volleringa4d77dc2010-10-24 13:42:32 +000024ifeq ($(OS_ARCH), FreeBSD)
25CFLAGS = -O2 -Wall -Werror -Wstrict-prototypes -Wundef -Wstrict-aliasing \
Andriy Gapon89397fc2012-10-03 08:19:34 +020026 -Werror-implicit-function-declaration -ansi $(VERSION) \
Idwer Volleringa4d77dc2010-10-24 13:42:32 +000027 -I/usr/local/include
28LDFLAGS += -L/usr/local/lib
29LIBS = -lz
30endif
Jonathan Kollasch51ac8382010-10-24 14:10:35 +000031ifeq ($(OS_ARCH), NetBSD)
Andrey Korolyovdecefea2016-01-04 02:20:04 +030032CFLAGS += -I/usr/pkg/include
33LDFLAGS += -L/usr/pkg/lib -Wl,-rpath-link,/usr/pkg/lib
34LIBS = -lz -l$(shell uname -p)
Jonathan Kollasch51ac8382010-10-24 14:10:35 +000035endif
Stefan Reinauere95eb612009-09-01 09:57:55 +000036
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +000037# Support for PCI-attached "Super I/Os" (e.g. in VIA VT82686A/B).
38CONFIG_PCI = yes
39
40ifeq ($(CONFIG_PCI), yes)
41CFLAGS += -DPCI_SUPPORT
Rudolf Marek113c3492011-10-27 20:42:11 +020042OBJS += pci.o via.o amd.o
Andrey Korolyovdecefea2016-01-04 02:20:04 +030043LIBS += -lpci
44ifeq ($(OS_ARCH),NetBSD)
45LIBS += -lpciutils
46endif
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +000047endif
48
Arthur Heymans4988af82017-04-02 23:21:53 +020049all: pciutils $(PROGRAM)
Uwe Hermann1ae8e832007-09-01 20:20:41 +000050
Ulf Jordan39a5bf72007-10-13 18:06:12 +000051superiotool.o: *.c superiotool.h
52
Uwe Hermannd754d2c2007-09-18 23:30:24 +000053$(PROGRAM): $(OBJS) superiotool.h
Christian Ruppert121f0b82010-03-21 21:22:51 +000054 $(CC) $(LDFLAGS) -o $(PROGRAM) $(OBJS) $(LIBS)
Uwe Hermann1ae8e832007-09-01 20:20:41 +000055
56install: $(PROGRAM)
Maciej Gabryelski1fc12db2022-04-21 08:28:01 +020057 $(INSTALL) -d $(DESTDIR)$(PREFIX)/sbin
Stefan Reinauere95eb612009-09-01 09:57:55 +000058 $(INSTALL) $(PROGRAM) $(DESTDIR)$(PREFIX)/sbin
Maciej Gabryelski1fc12db2022-04-21 08:28:01 +020059 $(INSTALL) -d $(DESTDIR)$(PREFIX)/share/man/man8
Lubomir Rintelba1f9aa2014-01-28 16:52:48 +000060 $(INSTALL) -p -m644 $(PROGRAM).8 $(DESTDIR)$(PREFIX)/share/man/man8
Uwe Hermann1ae8e832007-09-01 20:20:41 +000061
Stefan Reinauer6a5bc462007-01-17 10:57:42 +000062clean:
Martin Roth0be83c02015-10-21 14:50:00 -060063 rm -f $(PROGRAM) *.o junit.xml
Uwe Hermann1ae8e832007-09-01 20:20:41 +000064
Martin Roth0be83c02015-10-21 14:50:00 -060065distclean: clean
66
67.PHONY: all install clean distclean
Arthur Heymans4988af82017-04-02 23:21:53 +020068
69ifeq ($(CONFIG_PCI), yes)
70define LIBPCI_TEST
71/* Avoid a failing test due to libpci header symbol shadowing breakage */
72#define index shadow_workaround_index
73#ifdef __NetBSD__
74#include <pciutils/pci.h>
75#else
76#include <pci/pci.h>
77#endif
78struct pci_access *pacc;
79int main(int argc, char **argv)
80{
81 (void) argc;
82 (void) argv;
83 pacc = pci_alloc();
84 return 0;
85}
86endef
87export LIBPCI_TEST
88
89pciutils:
90 @printf "\nChecking for pciutils and zlib... "
91 @echo "$$LIBPCI_TEST" > .test.c
Idwer Vollering7abc0372019-12-16 15:39:00 +010092 @$(CC) $(CFLAGS) .test.c -o .test $(LIBS) $(LDFLAGS) >/dev/null 2>&1 && \
Elyes HAOUASb9585c52018-05-29 22:23:48 +020093 printf "found.\n" || ( printf "not found.\n\n"; \
Arthur Heymans4988af82017-04-02 23:21:53 +020094 printf "Please install pciutils-devel and zlib-devel.\n"; \
95 printf "See README for more information.\n\n"; \
96 rm -f .test.c .test; exit 1)
97 @rm -rf .test.c .test .test.dSYM
98endif