summaryrefslogtreecommitdiff
path: root/util/superiotool/Makefile
blob: 39839d9aa64752e8653654540008971eb732b751 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# SPDX-License-Identifier: GPL-2.0-or-later

PROGRAM = superiotool

TOP     ?= $(abspath ../..)
CC      ?= gcc
INSTALL ?= /usr/bin/env install
PREFIX  ?= /usr/local

# Set the superiotool version string to the output of 'git describe'.

VERSION := -D'SUPERIOTOOL_VERSION="$(shell git describe 2>/dev/null)"'

CFLAGS += -O2 -Wall -Wstrict-prototypes -Wundef -Wstrict-aliasing \
         -Werror-implicit-function-declaration -std=c11 -pedantic $(VERSION) \
         -Wno-variadic-macros -I $(TOP)/src/commonlib/bsd/include
LDFLAGS += -lz

OBJS = superiotool.o serverengines.o ali.o exar.o fintek.o ite.o nsc.o \
       nuvoton.o smsc.o winbond.o infineon.o aspeed.o

OS_ARCH ?= $(shell uname)
ifeq ($(OS_ARCH), Darwin)
LIBS = -framework IOKit -framework DirectHW -lpci -lz
endif
ifeq ($(OS_ARCH), FreeBSD)
CFLAGS = -O2 -Wall -Werror -Wstrict-prototypes -Wundef -Wstrict-aliasing \
         -Werror-implicit-function-declaration -std=c11 $(VERSION) \
         -I/usr/local/include
LDFLAGS += -L/usr/local/lib
LIBS = -lz
endif
ifeq ($(OS_ARCH), NetBSD)
CFLAGS += -I/usr/pkg/include
LDFLAGS += -L/usr/pkg/lib -Wl,-rpath-link,/usr/pkg/lib
LIBS = -lz -l$(shell uname -p)
endif

# Support for PCI-attached "Super I/Os" (e.g. in VIA VT82686A/B).
CONFIG_PCI = yes

ifeq ($(CONFIG_PCI), yes)
CFLAGS += -DPCI_SUPPORT
OBJS += pci.o via.o amd.o
LIBS += -lpci
ifeq ($(OS_ARCH),NetBSD)
LIBS += -lpciutils
endif
endif

all: pciutils $(PROGRAM)

superiotool.o: *.c superiotool.h

$(PROGRAM): $(OBJS) superiotool.h
	$(CC) $(LDFLAGS) -o $(PROGRAM) $(OBJS) $(LIBS)

install: $(PROGRAM)
	$(INSTALL) -d $(DESTDIR)$(PREFIX)/sbin
	$(INSTALL) $(PROGRAM) $(DESTDIR)$(PREFIX)/sbin
	$(INSTALL) -d $(DESTDIR)$(PREFIX)/share/man/man8
	$(INSTALL) -p -m644 $(PROGRAM).8 $(DESTDIR)$(PREFIX)/share/man/man8

clean:
	rm -f $(PROGRAM) *.o junit.xml

distclean: clean

.PHONY: all install clean distclean

ifeq ($(CONFIG_PCI), yes)
define LIBPCI_TEST
/* Avoid a failing test due to libpci header symbol shadowing breakage */
#define index shadow_workaround_index
#ifdef __NetBSD__
#include <pciutils/pci.h>
#else
#include <pci/pci.h>
#endif
struct pci_access *pacc;
int main(int argc, char **argv)
{
	(void) argc;
	(void) argv;
	pacc = pci_alloc();
	return 0;
}
endef
export LIBPCI_TEST

pciutils:
	@printf "\nChecking for pciutils and zlib... "
	@echo "$$LIBPCI_TEST" > .test.c
	@$(CC) $(CFLAGS) .test.c -o .test $(LIBS) $(LDFLAGS) >/dev/null 2>&1 &&	  \
		printf "found.\n" || ( printf "not found.\n\n";		  \
		printf "Please install pciutils-devel and zlib-devel.\n"; \
		printf "See README for more information.\n\n";		  \
		rm -f .test.c .test; exit 1)
	@rm -rf .test.c .test .test.dSYM
endif