blob: 365497a308e2c02bb7ce0cdf27db957c3779518f [file] [log] [blame]
Alexandru Gagniuc67f556c2012-08-10 03:55:42 -05001#
2# Makefile for viatool utility
3#
4# Copyright (C) 2008 by coresystems GmbH
5# written by Stefan Reinauer <stepan@coresystems.de>
6# Copyright (C) 2013 Alexandru Gagniuc
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
Alexandru Gagniuc67f556c2012-08-10 03:55:42 -050018
19PROGRAM = viatool
20
21CC ?= gcc
22INSTALL ?= /usr/bin/install
23PREFIX ?= /usr/local
Martin Roth6116f362016-03-08 12:32:40 -070024CFLAGS ?= -O2 -g -Wall -W -I$(CURDIR)
Alexandru Gagniuc67f556c2012-08-10 03:55:42 -050025LDFLAGS += -lpci -lz
26
27SRCS = viatool.c \
28 cpu.c \
29 quirks/quirks.c \
30 quirks/vx900_quirks.c
31
32OBJS = $(sort ${SRCS:.c=.o})
33
34OS_ARCH = $(shell uname)
35ifeq ($(OS_ARCH), Darwin)
36LDFLAGS += -framework DirectHW
37endif
38ifeq ($(OS_ARCH), FreeBSD)
39CFLAGS += -I/usr/local/include
40LDFLAGS += -L/usr/local/lib
41LIBS = -lz
42endif
Andrey Korolyov0ff8f902016-01-05 20:09:02 +030043ifeq ($(OS_ARCH), NetBSD)
44CFLAGS += -I/usr/pkg/include
45LDFLAGS += -L/usr/pkg/lib -Wl,-rpath-link,/usr/pkg/lib -lz -lpciutils -lpci -l$(shell uname -p)
46endif
Alexandru Gagniuc67f556c2012-08-10 03:55:42 -050047
48all: pciutils dep $(PROGRAM)
49
50$(PROGRAM): $(OBJS)
51 $(CC) $(CFLAGS) -o $(PROGRAM) $(OBJS) $(LDFLAGS)
52
53clean:
54 # Remove build results
55 rm -f $(PROGRAM) $(OBJS)
56 # Remove backup files created by some editors
57 find ./ |grep *~ |xargs rm -f
Martin Roth0be83c02015-10-21 14:50:00 -060058 rm -f junit.xml
Alexandru Gagniuc67f556c2012-08-10 03:55:42 -050059
60distclean: clean
61 rm -f .dependencies
62
63dep:
64 @$(CC) $(CFLAGS) -MM *.c > .dependencies
65
66define LIBPCI_TEST
67/* Avoid a failing test due to libpci header symbol shadowing breakage */
68#define index shadow_workaround_index
Andrey Korolyov0ff8f902016-01-05 20:09:02 +030069#ifdef __NetBSD__
70#include <pciutils/pci.h>
71#else
Alexandru Gagniuc67f556c2012-08-10 03:55:42 -050072#include <pci/pci.h>
Andrey Korolyov0ff8f902016-01-05 20:09:02 +030073#endif
Alexandru Gagniuc67f556c2012-08-10 03:55:42 -050074struct pci_access *pacc;
75int main(int argc, char **argv)
76{
77 (void) argc;
78 (void) argv;
79 pacc = pci_alloc();
80 return 0;
81}
82endef
83export LIBPCI_TEST
84
85pciutils:
86 @printf "\nChecking for pciutils and zlib... "
87 @echo "$$LIBPCI_TEST" > .test.c
88 @$(CC) $(CFLAGS) .test.c -o .test $(LDFLAGS) >/dev/null 2>&1 && \
89 printf "found.\n" || ( printf "not found.\n\n"; \
90 printf "Please install pciutils-devel and zlib-devel.\n"; \
91 printf "See README for more information.\n\n"; \
92 rm -f .test.c .test; exit 1)
93 @rm -rf .test.c .test .test.dSYM
94
95install: $(PROGRAM)
96 mkdir -p $(DESTDIR)$(PREFIX)/sbin
97 $(INSTALL) $(PROGRAM) $(DESTDIR)$(PREFIX)/sbin
98 mkdir -p $(DESTDIR)$(PREFIX)/share/man/man8
99 $(INSTALL) $(PROGRAM).8 $(DESTDIR)$(PREFIX)/share/man/man8
100
101.PHONY: all clean distclean dep pciutils
102
103-include .dependencies