#
# GNU PIC Programmer & Debugger
# The RPM builder
#
# Copyright (C) 2003 Sylvain Giroudon
# Creation: 08-JUN-2003
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.  
#

#
# $Revision: 1.3 $
# $Date: 2004/05/26 09:47:33 $
#

PACKAGE = gpicd

ifndef INSTALLDIR
INSTALLDIR = INSTALL/usr
endif

-include ../Makefile.defs

RPMMACROS = $(HOME)/.rpmmacros
KEY := $(shell echo $$$$)
ifneq ($(wildcard $(RPMMACROS)),)
RPMMACROS_BAK = $(RPMMACROS).bak$(KEY)
endif

all:
ifneq ($(RPMMACROS_BAK),)
	$(MV) $(RPMMACROS) $(RPMMACROS_BAK)
endif
	echo '%_topdir $(PWD)' > $(RPMMACROS)
	$(MKDIR) BUILD $(INSTALLDIR) RPMS/$(MACHINE)

	find INSTALL -type f | sed 's|^INSTALL||g' > BUILD/$(PACKAGE).files
	$(RPMBUILD) -bb $(PACKAGE).spec --buildroot $(PWD)/INSTALL --target $(MACHINE)

	@find RPMS -name '*.rpm' -type f -exec $(MV) -v '{}' $(PWD) ';'
	$(RM) $(RPMMACROS)
ifneq ($(RPMMACROS_BAK),)
	$(MV) $(RPMMACROS_BAK) $(RPMMACROS)
endif

clean:
	$(RM) -r BUILD INSTALL RPMS *.rpm *~
