blob: fe2a4cce001537d2bd451f85674ecd60b7989552 [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
Konrad Adamczykd6b4db12023-04-11 10:26:12 +00005TOP ?= $(abspath ../..)
Paul Menzelbe2c6342013-03-28 11:44:19 +01006CC ?= gcc
Yegor Timoshenkoc2e49412018-10-07 01:58:27 +00007INSTALL ?= /usr/bin/env install
Paul Menzelbe2c6342013-03-28 11:44:19 +01008PREFIX ?= /usr/local
Uwe Hermann1ae8e832007-09-01 20:20:41 +00009
Guenter Roeck3397cef2012-06-29 12:25:46 -070010# Set the superiotool version string to the output of 'git describe'.
11
12VERSION := -D'SUPERIOTOOL_VERSION="$(shell git describe 2>/dev/null)"'
Ulf Jordan39a5bf72007-10-13 18:06:12 +000013
Mathias Krause14b67f72011-03-09 11:37:16 +010014CFLAGS += -O2 -Wall -Wstrict-prototypes -Wundef -Wstrict-aliasing \
Nicholas Sudsgaard1dea2ca2023-09-11 19:25:08 +090015 -Werror-implicit-function-declaration -std=c99 -pedantic $(VERSION) \
Konrad Adamczykd6b4db12023-04-11 10:26:12 +000016 -Wno-variadic-macros -I $(TOP)/src/commonlib/bsd/include
Anders Juel Jensen280275d2010-08-22 19:39:04 +000017LDFLAGS += -lz
Uwe Hermann1ae8e832007-09-01 20:20:41 +000018
Derek Waldner3b421192016-04-14 12:13:48 -050019OBJS = superiotool.o serverengines.o ali.o exar.o fintek.o ite.o nsc.o \
Patrick Rudolph674bb3b2019-05-24 09:07:04 +020020 nuvoton.o smsc.o winbond.o infineon.o aspeed.o
Uwe Hermann0120e1a2007-09-16 18:11:03 +000021
Maciej Gabryelski1fc12db2022-04-21 08:28:01 +020022OS_ARCH ?= $(shell uname)
Stefan Reinauere95eb612009-09-01 09:57:55 +000023ifeq ($(OS_ARCH), Darwin)
Stefan Reinauercff573d2011-03-18 22:08:39 +000024LIBS = -framework IOKit -framework DirectHW -lpci -lz
Stefan Reinauere95eb612009-09-01 09:57:55 +000025endif
Idwer Volleringa4d77dc2010-10-24 13:42:32 +000026ifeq ($(OS_ARCH), FreeBSD)
27CFLAGS = -O2 -Wall -Werror -Wstrict-prototypes -Wundef -Wstrict-aliasing \
Nicholas Sudsgaard1dea2ca2023-09-11 19:25:08 +090028 -Werror-implicit-function-declaration -std=c99 $(VERSION) \
Idwer Volleringa4d77dc2010-10-24 13:42:32 +000029 -I/usr/local/include
30LDFLAGS += -L/usr/local/lib
31LIBS = -lz
32endif
Jonathan Kollasch51ac8382010-10-24 14:10:35 +000033ifeq ($(OS_ARCH), NetBSD)
Andrey Korolyovdecefea2016-01-04 02:20:04 +030034CFLAGS += -I/usr/pkg/include
35LDFLAGS += -L/usr/pkg/lib -Wl,-rpath-link,/usr/pkg/lib
36LIBS = -lz -l$(shell uname -p)
Jonathan Kollasch51ac8382010-10-24 14:10:35 +000037endif
Stefan Reinauere95eb612009-09-01 09:57:55 +000038
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +000039# Support for PCI-attached "Super I/Os" (e.g. in VIA VT82686A/B).
40CONFIG_PCI = yes
41
42ifeq ($(CONFIG_PCI), yes)
43CFLAGS += -DPCI_SUPPORT
Rudolf Marek113c3492011-10-27 20:42:11 +020044OBJS += pci.o via.o amd.o
Andrey Korolyovdecefea2016-01-04 02:20:04 +030045LIBS += -lpci
46ifeq ($(OS_ARCH),NetBSD)
47LIBS += -lpciutils
48endif
Carl-Daniel Hailfingerbb38f322010-01-24 01:40:46 +000049endif
50
Arthur Heymans4988af82017-04-02 23:21:53 +020051all: pciutils $(PROGRAM)
Uwe Hermann1ae8e832007-09-01 20:20:41 +000052
Ulf Jordan39a5bf72007-10-13 18:06:12 +000053superiotool.o: *.c superiotool.h
54
Uwe Hermannd754d2c2007-09-18 23:30:24 +000055$(PROGRAM): $(OBJS) superiotool.h
Christian Ruppert121f0b82010-03-21 21:22:51 +000056 $(CC) $(LDFLAGS) -o $(PROGRAM) $(OBJS) $(LIBS)
Uwe Hermann1ae8e832007-09-01 20:20:41 +000057
58install: $(PROGRAM)
Maciej Gabryelski1fc12db2022-04-21 08:28:01 +020059 $(INSTALL) -d $(DESTDIR)$(PREFIX)/sbin
Stefan Reinauere95eb612009-09-01 09:57:55 +000060 $(INSTALL) $(PROGRAM) $(DESTDIR)$(PREFIX)/sbin
Maciej Gabryelski1fc12db2022-04-21 08:28:01 +020061 $(INSTALL) -d $(DESTDIR)$(PREFIX)/share/man/man8
Lubomir Rintelba1f9aa2014-01-28 16:52:48 +000062 $(INSTALL) -p -m644 $(PROGRAM).8 $(DESTDIR)$(PREFIX)/share/man/man8
Uwe Hermann1ae8e832007-09-01 20:20:41 +000063
Stefan Reinauer6a5bc462007-01-17 10:57:42 +000064clean:
Martin Roth0be83c02015-10-21 14:50:00 -060065 rm -f $(PROGRAM) *.o junit.xml
Uwe Hermann1ae8e832007-09-01 20:20:41 +000066
Martin Roth0be83c02015-10-21 14:50:00 -060067distclean: clean
68
69.PHONY: all install clean distclean
Arthur Heymans4988af82017-04-02 23:21:53 +020070
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
Idwer Vollering7abc0372019-12-16 15:39:00 +010094 @$(CC) $(CFLAGS) .test.c -o .test $(LIBS) $(LDFLAGS) >/dev/null 2>&1 && \
Elyes HAOUASb9585c52018-05-29 22:23:48 +020095 printf "found.\n" || ( printf "not found.\n\n"; \
Arthur Heymans4988af82017-04-02 23:21:53 +020096 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