###############################################################################
# $Id: Makefile,v 1.6 2010/12/31 02:38:03 tw Exp $
#
# Install rules for creating unique symlinks with reproducible device names
# for GW Instek GDS oscilloscopes.
#
# Copyright (C) 2010 Thomas Weidenfeller
# 
# This file is part of gds2000tools.
# 
# gds2000tools is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License
# version 3 as published by the Free Software Foundation.
# 
# gds2000tools is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with gds2000tools.  If not, see <http://www.gnu.org/licenses/>.
###############################################################################

TOP	= ..
include $(TOP)/config.mk

INSTALL_FLAGS =

TARGET	= 80-instek-gds.rules
MANS	= gds-udev.7# TODO: or .4?

default: all
all:
.PHONY: default all

clean::
	-$(RM) -f *~ *.bak

###############################################################################
# Installation
#
ifeq ($(strip $(HAS_UDEV)),1)
install: install-rules install-man
install-rules: $(TARGET)
	if [ `id -u` -eq 0 ] ;					\
	then	 						\
		UG="-o bin -g bin";				\
	else 							\
		UG="" ;						\
	fi;							\
	install $(INSTALL_FLAGS) -m 755 $$UG -d $(UDEVDIR);     \
	install $(INSTALL_FLAGS) -m 755 $$UG -d $(UDEVDIR)/rules.d; \
	install $(INSTALL_FLAGS) -m 644 $$UG $(TARGET)		\
					$(UDEVDIR)/rules.d/$(TARGET)
	-udevadm control --reload-rules

install-man: $(MANS)
	if [ `id -u` -eq 0 ] ;					\
	then	 						\
		UG="-o bin -g bin";				\
	else 							\
		UG="" ;						\
	fi;							\
	install $(INSTALL_FLAGS) -m 755 $$UG -d $(MAN7DIR);     \
	install $(INSTALL_FLAGS) -m 644 $$UG $(MANS) $(MAN7DIR)/$(MANS)
	-( cd $(MAN7DIR) && ln -s $(MAN7DIR)/$(MANS) $(TARGET).7; )
else
install:
install-rules:
install-man:
endif

.PHONY: install install-rules install-man
