#
# Makefile
#
# Copyright 2007-2008 Red Hat, Inc.  All rights reserved.
#
# 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, see <http://www.gnu.org/licenses/>.
#

TOPDIR ?= $(shell pwd)/../../
export TOPDIR

TARGETS = pybdevid.so

include $(TOPDIR)/Makefile.inc

SITELIB := $(shell python -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)[1:]")
PYVER := $(shell python -c "import sys; print sys.version[0:3]")
CFLAGS += -I/usr/include/python$(PYVER)
CFLAGS += -I$(TOPDIR)/nash/include -I$(TOPDIR)/bdevid/include
LDFLAGS = -shared -L$(TOPDIR)/nash -L$(TOPDIR)/bdevid
LDFLAGS += -Wl,-soname="pybdevid.so.$(VERSION)",--as-needed
LDFLAGS += -lpython$(PYVER) -ldl

pybdevid_OBJECTS = pybdevid.o
pybdevid_LIBS = -lbdevid -lnash -ldevmapper -lparted -lblkid

pybdevid.so :: $(pybdevid_OBJECTS)
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ -lbdevid $(pybdevid_LIBS)

install : all
	@install -m 0755 -d $(DESTDIR)/$(SITELIB)
	@cp -av pybdevid.so $(DESTDIR)/$(SITELIB)/bdevid.so

clean ::
	@rm -vf $(pybdevid_OBJECTS) pybdevid.so
