buildtopdir = .

prefix =	/opt/osstech
exec_prefix =	$(prefix)
bindir =	$(exec_prefix)/bin
sbindir =	$(exec_prefix)/sbin
libexecdir =	$(exec_prefix)/libexec
sysconfdir =	$(exec_prefix)/etc
libdir =	$(exec_prefix)/lib/ssbuild
localstetedir =	$(exec_prefix)/var

srcdir =	$(exec_prefix)/src

DESTDIR = $(buildtopdir)/dest

INSTALL = $(buildtopdir)/install-sh
INSTALL_HIER = $(buildtopdir)/install-hier-sh

PKG_NAME = osstech-ssbuild
PKG_VERSION = 1.5.6
PKG_REVISION = 
PKG_VENDOR = OSS Technology Co., Japan <http://www.osstech.co.jp/>

RPM_LIB_DIR = $(libdir)/rpm

GNU_USRLOCALBIN_CMDS = autoconf autoheader automake m4

DIRS = $(bindir)

default: install pkg

build:

install: install-clean install-dir install-file install-symlink

install-clean:
	$(RM) -r $(DESTDIR)

install-dir:
	$(INSTALL) -d -m 755 "$(DESTDIR)"
	chmod g-s $(DESTDIR)
	for dir in $(DIRS); do \
	    $(INSTALL) -d -m 755 "$(DESTDIR)/$$dir"; \
	done;

install-file:
	$(INSTALL_HIER) "$(buildtopdir)/bin" "$(DESTDIR)$(bindir)" 
	$(INSTALL_HIER) "$(buildtopdir)/lib" "$(DESTDIR)$(libdir)" 

install-symlink:
	ln -s ssbuild-rpm "$(DESTDIR)$(bindir)/ssbuild-rpmbuild"
	ln -s ssbuild-rpm "$(DESTDIR)$(bindir)/rpm-ssbuild"
	ln -s ssbuild-rpm "$(DESTDIR)$(bindir)/rpmbuild-ssbuild"
	##
	rootdir="`echo "$(bindir)" |sed 's#/[^/]*#../#g;s#/$$##'`"; \
	for cmd in $(GNU_USRLOCALBIN_CMDS); do \
	    ln -s "$$rootdir/usr/local/bin/$$cmd" "$(DESTDIR)$(bindir)/$$cmd"; \
	done;

pkg: pkg-file

pkg-file:
	mkdir -p pkg
	$(buildtopdir)/bin/ssbuild-pkgmk \
	    --revision "$(PKG_REVISION)" \
	    --vendor "$(PKG_VENDOR)" \
	    --arch "all" \
	    --pre-install "$(buildtopdir)/preinstall.sh" \
	    --post-install "$(buildtopdir)/postinstall.sh" \
	    --pre-remove "$(buildtopdir)/preremove.sh" \
	    "$(DESTDIR)" \
	    "$(PKG_NAME)" \
	    "$(PKG_VERSION)" \
	    "$(buildtopdir)/pkg"

clean:
	$(RM) -r dest pkg

dist: clean
	d="`pwd |sed 's#^.*/##'`"; cd .. && (tar cf - "$$d" |bzip2 >"$$d.tar.bz2")

