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 | # |
| 18 | # You should have received a copy of the GNU General Public License |
| 19 | # along with this program; if not, write to the Free Software |
| 20 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 21 | # |
| 22 | |
| 23 | PROGRAM = viatool |
| 24 | |
| 25 | CC ?= gcc |
| 26 | INSTALL ?= /usr/bin/install |
| 27 | PREFIX ?= /usr/local |
| 28 | CFLAGS ?= -O2 -g -Wall -W -I$(shell pwd) |
| 29 | LDFLAGS += -lpci -lz |
| 30 | |
| 31 | SRCS = viatool.c \ |
| 32 | cpu.c \ |
| 33 | quirks/quirks.c \ |
| 34 | quirks/vx900_quirks.c |
| 35 | |
| 36 | OBJS = $(sort ${SRCS:.c=.o}) |
| 37 | |
| 38 | OS_ARCH = $(shell uname) |
| 39 | ifeq ($(OS_ARCH), Darwin) |
| 40 | LDFLAGS += -framework DirectHW |
| 41 | endif |
| 42 | ifeq ($(OS_ARCH), FreeBSD) |
| 43 | CFLAGS += -I/usr/local/include |
| 44 | LDFLAGS += -L/usr/local/lib |
| 45 | LIBS = -lz |
| 46 | endif |
| 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 |
| 58 | |
| 59 | distclean: clean |
| 60 | rm -f .dependencies |
| 61 | |
| 62 | dep: |
| 63 | @$(CC) $(CFLAGS) -MM *.c > .dependencies |
| 64 | |
| 65 | define LIBPCI_TEST |
| 66 | /* Avoid a failing test due to libpci header symbol shadowing breakage */ |
| 67 | #define index shadow_workaround_index |
| 68 | #include <pci/pci.h> |
| 69 | struct pci_access *pacc; |
| 70 | int main(int argc, char **argv) |
| 71 | { |
| 72 | (void) argc; |
| 73 | (void) argv; |
| 74 | pacc = pci_alloc(); |
| 75 | return 0; |
| 76 | } |
| 77 | endef |
| 78 | export LIBPCI_TEST |
| 79 | |
| 80 | pciutils: |
| 81 | @printf "\nChecking for pciutils and zlib... " |
| 82 | @echo "$$LIBPCI_TEST" > .test.c |
| 83 | @$(CC) $(CFLAGS) .test.c -o .test $(LDFLAGS) >/dev/null 2>&1 && \ |
| 84 | printf "found.\n" || ( printf "not found.\n\n"; \ |
| 85 | printf "Please install pciutils-devel and zlib-devel.\n"; \ |
| 86 | printf "See README for more information.\n\n"; \ |
| 87 | rm -f .test.c .test; exit 1) |
| 88 | @rm -rf .test.c .test .test.dSYM |
| 89 | |
| 90 | install: $(PROGRAM) |
| 91 | mkdir -p $(DESTDIR)$(PREFIX)/sbin |
| 92 | $(INSTALL) $(PROGRAM) $(DESTDIR)$(PREFIX)/sbin |
| 93 | mkdir -p $(DESTDIR)$(PREFIX)/share/man/man8 |
| 94 | $(INSTALL) $(PROGRAM).8 $(DESTDIR)$(PREFIX)/share/man/man8 |
| 95 | |
| 96 | .PHONY: all clean distclean dep pciutils |
| 97 | |
| 98 | -include .dependencies |
| 99 | |