blob: 5124a73dc3bc6cad1853d327ca07c2fe17fc1413 [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#
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
23PROGRAM = viatool
24
25CC ?= gcc
26INSTALL ?= /usr/bin/install
27PREFIX ?= /usr/local
28CFLAGS ?= -O2 -g -Wall -W -I$(shell pwd)
29LDFLAGS += -lpci -lz
30
31SRCS = viatool.c \
32 cpu.c \
33 quirks/quirks.c \
34 quirks/vx900_quirks.c
35
36OBJS = $(sort ${SRCS:.c=.o})
37
38OS_ARCH = $(shell uname)
39ifeq ($(OS_ARCH), Darwin)
40LDFLAGS += -framework DirectHW
41endif
42ifeq ($(OS_ARCH), FreeBSD)
43CFLAGS += -I/usr/local/include
44LDFLAGS += -L/usr/local/lib
45LIBS = -lz
46endif
47
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
58
59distclean: clean
60 rm -f .dependencies
61
62dep:
63 @$(CC) $(CFLAGS) -MM *.c > .dependencies
64
65define 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>
69struct pci_access *pacc;
70int main(int argc, char **argv)
71{
72 (void) argc;
73 (void) argv;
74 pacc = pci_alloc();
75 return 0;
76}
77endef
78export LIBPCI_TEST
79
80pciutils:
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
90install: $(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