# Makefile for The PCI Utilities
# (c) 1998--2008 Martin Mares <mj@ucw.cz>

OPT=-O2
CFLAGS=$(OPT) -g -Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes

VERSION=3.0.0
DATE=2008-04-10

# Host OS and release (override if you are cross-compiling)
HOST=
RELEASE=

# Support for compressed pci.ids (yes/no, default: detect)
ZLIB=

# Support for resolving ID's by DNS (yes/no, default: detect)
DNS=

# Build libpci as a shared library (yes/no; or local for testing; requires GCC)
SHARED=no

# ABI version suffix in the name of the shared library
ABI_VERSION=.3

# Installation directories
PREFIX=/usr/local
SBINDIR=$(PREFIX)/sbin
SHAREDIR=$(PREFIX)/share
IDSDIR=$(SHAREDIR)
MANDIR:=$(shell if [ -d $(PREFIX)/share/man ] ; then echo $(PREFIX)/share/man ; else echo $(PREFIX)/man ; fi)
INCDIR=$(PREFIX)/include
LIBDIR=$(PREFIX)/lib
PKGCFDIR=$(LIBDIR)/pkgconfig

# Commands
INSTALL=install
DIRINSTALL=install -d
STRIP=-s
AR=ar
RANLIB=ranlib

# Base name of the library (overriden on NetBSD, which has its own libpci)
LIBNAME=libpci

-include lib/config.mk

PCIINC=lib/config.h lib/header.h lib/pci.h lib/types.h lib/sysdep.h
PCIINC_INS=lib/config.h lib/header.h lib/pci.h lib/types.h

export

all: lib/$(PCILIB) openvox-update 

lib/$(PCILIB): $(PCIINC) force
	$(MAKE) -C lib all

force:

lib/config.h lib/config.mk:
	cd lib && ./configure

################################################################################
#
# epcs
# cc -O2 -Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes -c -o epcs.o epcs.c
# cc epcs.o lib/libpci.a -lz -lresolv -I ./include -o epcs
#
################################################################################
openvox-update: epcs.o  lib/$(PCILIB) menu.o 
	cc epcs.o menu.o  lib/libpci.a -lz -lresolv -I ./include  -lpthread   -o openvox-update
	
epcs.o: epcs.c $(PCIINC) cards.h

menu.o: menu.c menu.h 


###############################################################################################
# 
# $(LDFLAGS) = 
# $(TARGET_ARCH) =
# $(LDLIBS) = -lz -lresolv
#
###############################################################################################
%: %.o
	$(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@

clean:
	rm -f `find . -name "*~" -o -name "*.[oa]" -o -name "\#*\#" -o -name TAGS -o -name core -o -name "*.orig"`
	rm -f update-pciids lspci setpci example openvox-update lib/config.* *.[78] pci.ids.* lib/*.pc lib/*.so lib/*.so.*
	rm -rf maint/dist

distclean: clean

ifeq ($(SHARED),yes)
	$(DIRINSTALL) -m 755 $(DESTDIR)$(LIBDIR)
	$(INSTALL) -c -m 644 lib/$(PCILIB) $(DESTDIR)$(LIBDIR)
	ln -sf $(PCILIB) $(DESTDIR)$(LIBDIR)/$(LIBNAME).so$(ABI_VERSION)
endif

ASCIIDOC		:= asciidoc 
README.html: README
	$(ASCIIDOC) -n -a toc $<

.PHONY: all clean distclean install install-lib uninstall force

