blob: de3bfdd515595d9a5a14e44c76b3182e0c5e2172 [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
24CFLAGS ?= -O2 -g -Wall -W -I$(shell pwd)
25LDFLAGS += -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
43
44all: pciutils dep $(PROGRAM)
45
46$(PROGRAM): $(OBJS)
47 $(CC) $(CFLAGS) -o $(PROGRAM) $(OBJS) $(LDFLAGS)
48
49clean:
50 # Remove build results
51 rm -f $(PROGRAM) $(OBJS)
52 # Remove backup files created by some editors
53 find ./ |grep *~ |xargs rm -f
Martin Roth0be83c02015-10-21 14:50:00 -060054 rm -f junit.xml
Alexandru Gagniuc67f556c2012-08-10 03:55:42 -050055
56distclean: clean
57 rm -f .dependencies
58
59dep:
60 @$(CC) $(CFLAGS) -MM *.c > .dependencies
61
62define LIBPCI_TEST
63/* Avoid a failing test due to libpci header symbol shadowing breakage */
64#define index shadow_workaround_index
65#include <pci/pci.h>
66struct pci_access *pacc;
67int main(int argc, char **argv)
68{
69 (void) argc;
70 (void) argv;
71 pacc = pci_alloc();
72 return 0;
73}
74endef
75export LIBPCI_TEST
76
77pciutils:
78 @printf "\nChecking for pciutils and zlib... "
79 @echo "$$LIBPCI_TEST" > .test.c
80 @$(CC) $(CFLAGS) .test.c -o .test $(LDFLAGS) >/dev/null 2>&1 && \
81 printf "found.\n" || ( printf "not found.\n\n"; \
82 printf "Please install pciutils-devel and zlib-devel.\n"; \
83 printf "See README for more information.\n\n"; \
84 rm -f .test.c .test; exit 1)
85 @rm -rf .test.c .test .test.dSYM
86
87install: $(PROGRAM)
88 mkdir -p $(DESTDIR)$(PREFIX)/sbin
89 $(INSTALL) $(PROGRAM) $(DESTDIR)$(PREFIX)/sbin
90 mkdir -p $(DESTDIR)$(PREFIX)/share/man/man8
91 $(INSTALL) $(PROGRAM).8 $(DESTDIR)$(PREFIX)/share/man/man8
92
93.PHONY: all clean distclean dep pciutils
94
95-include .dependencies