Alexandru Gagniuc | 67f556c | 2012-08-10 03:55:42 -0500 | [diff] [blame] | 1 | # |
| 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 Gagniuc | 67f556c | 2012-08-10 03:55:42 -0500 | [diff] [blame] | 18 | |
| 19 | PROGRAM = viatool |
| 20 | |
| 21 | CC ?= gcc |
| 22 | INSTALL ?= /usr/bin/install |
| 23 | PREFIX ?= /usr/local |
Martin Roth | 6116f36 | 2016-03-08 12:32:40 -0700 | [diff] [blame] | 24 | CFLAGS ?= -O2 -g -Wall -W -I$(CURDIR) |
Alexandru Gagniuc | 67f556c | 2012-08-10 03:55:42 -0500 | [diff] [blame] | 25 | LDFLAGS += -lpci -lz |
| 26 | |
| 27 | SRCS = viatool.c \ |
| 28 | cpu.c \ |
| 29 | quirks/quirks.c \ |
| 30 | quirks/vx900_quirks.c |
| 31 | |
| 32 | OBJS = $(sort ${SRCS:.c=.o}) |
| 33 | |
| 34 | OS_ARCH = $(shell uname) |
| 35 | ifeq ($(OS_ARCH), Darwin) |
| 36 | LDFLAGS += -framework DirectHW |
| 37 | endif |
| 38 | ifeq ($(OS_ARCH), FreeBSD) |
| 39 | CFLAGS += -I/usr/local/include |
| 40 | LDFLAGS += -L/usr/local/lib |
| 41 | LIBS = -lz |
| 42 | endif |
Andrey Korolyov | 0ff8f90 | 2016-01-05 20:09:02 +0300 | [diff] [blame] | 43 | ifeq ($(OS_ARCH), NetBSD) |
| 44 | CFLAGS += -I/usr/pkg/include |
| 45 | LDFLAGS += -L/usr/pkg/lib -Wl,-rpath-link,/usr/pkg/lib -lz -lpciutils -lpci -l$(shell uname -p) |
| 46 | endif |
Alexandru Gagniuc | 67f556c | 2012-08-10 03:55:42 -0500 | [diff] [blame] | 47 | |
| 48 | all: pciutils dep $(PROGRAM) |
| 49 | |
| 50 | $(PROGRAM): $(OBJS) |
| 51 | $(CC) $(CFLAGS) -o $(PROGRAM) $(OBJS) $(LDFLAGS) |
| 52 | |
| 53 | clean: |
| 54 | # Remove build results |
| 55 | rm -f $(PROGRAM) $(OBJS) |
| 56 | # Remove backup files created by some editors |
| 57 | find ./ |grep *~ |xargs rm -f |
Martin Roth | 0be83c0 | 2015-10-21 14:50:00 -0600 | [diff] [blame] | 58 | rm -f junit.xml |
Alexandru Gagniuc | 67f556c | 2012-08-10 03:55:42 -0500 | [diff] [blame] | 59 | |
| 60 | distclean: clean |
| 61 | rm -f .dependencies |
| 62 | |
| 63 | dep: |
| 64 | @$(CC) $(CFLAGS) -MM *.c > .dependencies |
| 65 | |
| 66 | define LIBPCI_TEST |
| 67 | /* Avoid a failing test due to libpci header symbol shadowing breakage */ |
| 68 | #define index shadow_workaround_index |
Andrey Korolyov | 0ff8f90 | 2016-01-05 20:09:02 +0300 | [diff] [blame] | 69 | #ifdef __NetBSD__ |
| 70 | #include <pciutils/pci.h> |
| 71 | #else |
Alexandru Gagniuc | 67f556c | 2012-08-10 03:55:42 -0500 | [diff] [blame] | 72 | #include <pci/pci.h> |
Andrey Korolyov | 0ff8f90 | 2016-01-05 20:09:02 +0300 | [diff] [blame] | 73 | #endif |
Alexandru Gagniuc | 67f556c | 2012-08-10 03:55:42 -0500 | [diff] [blame] | 74 | struct pci_access *pacc; |
| 75 | int main(int argc, char **argv) |
| 76 | { |
| 77 | (void) argc; |
| 78 | (void) argv; |
| 79 | pacc = pci_alloc(); |
| 80 | return 0; |
| 81 | } |
| 82 | endef |
| 83 | export LIBPCI_TEST |
| 84 | |
| 85 | pciutils: |
| 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 | |
| 95 | install: $(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 |