# Makefile for libblkid
#
# Copyright (C) 2001 Theodore Ts'o (tytso@mit.edu)
#
# This file can be redistributed under the terms of the
# GNU Lesser General Public License

srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
top_builddir = ../..
my_dir = lib/blkid
INSTALL = @INSTALL@

@MCONFIG@

all:: 

SMANPAGES=	libblkid.3

OBJS= cache.o dev.o devname.o devno.o getsize.o llseek.o probe.o \
 read.o resolve.o save.o tag.o version.o 

SRCS= $(srcdir)/cache.c $(srcdir)/dev.c $(srcdir)/devname.c $(srcdir)/devno.c \
 $(srcdir)/getsize.c $(srcdir)/llseek.c $(srcdir)/probe.c \
 $(srcdir)/read.c $(srcdir)/resolve.c $(srcdir)/save.c $(srcdir)/tag.c \
 $(srcdir)/version.c

HFILES_IN=	blkid.h blkid_types.h

LIBRARY= libblkid
LIBDIR= blkid

ELF_VERSION = 1.0
ELF_SO_VERSION = 1
ELF_IMAGE = libblkid
ELF_MYDIR = blkid
ELF_INSTALL_DIR = $(root_libdir)
ELF_OTHER_LIBS = -luuid

BSDLIB_VERSION = 2.0
BSDLIB_IMAGE = libblkid
BSDLIB_MYDIR = blkid
BSDLIB_INSTALL_DIR = $(root_libdir)

@MAKEFILE_LIBRARY@
@MAKEFILE_ELF@
@MAKEFILE_BSDLIB@
@MAKEFILE_PROFILE@

LIBS_BLKID=	$(STATIC_LIBBLKID) $(STATIC_LIBUUID)
DEPLIBS_BLKID=	$(DEPSTATIC_LIBBLKID) $(DEPSTATIC_LIBUUID)

.c.o:
	$(E) "	CC $<"
	$(Q) $(CC) $(ALL_CFLAGS_STLIB) -c $< -o $@
	$(Q) $(CHECK_CMD) $(ALL_CFLAGS) $<
	$(Q) $(CPPCHECK_CMD) $(CPPFLAGS) $<
@PROFILE_CMT@	$(Q) $(CC) $(ALL_CFLAGS_STLIB) -g -pg -o profiled/$*.o -c $<
@ELF_CMT@	$(Q) $(CC) $(ALL_CFLAGS_SHLIB) -fPIC -shared -o elfshared/$*.o -c $<
@BSDLIB_CMT@	$(Q) $(CC) $(ALL_CFLAGS_SHLIB) $(BSDLIB_PIC_FLAG) -o pic/$*.o -c $<

all:: $(SMANPAGES) blkid.pc

blkid_types.h: $(srcdir)/blkid_types.h.in $(top_builddir)/config.status
	$(E) "	CONFIG.STATUS $@"
	$(Q) cd $(top_builddir); \
		CONFIG_FILES=$(my_dir)/blkid_types.h ./config.status

blkid.h: $(srcdir)/blkid.h.in
	$(E) "	CP $@"
	$(Q) cp $(srcdir)/blkid.h.in blkid.h

libblkid.3: $(DEP_SUBSTITUTE) $(srcdir)/libblkid.3.in
	$(E) "	SUBST $@"
	$(Q) $(SUBSTITUTE_UPTIME) $(srcdir)/libblkid.3.in libblkid.3

tst_cache: $(srcdir)/cache.c $(DEPLIBS_BLKID)
	$(E) "	LD $@"
	$(Q) $(CC) -o tst_cache -DTEST_PROGRAM $(srcdir)/cache.c $(LIBS_BLKID) $(ALL_CFLAGS)

tst_dev: $(srcdir)/dev.c $(DEPLIBS_BLKID)
	$(E) "	LD $@"
	$(Q) $(CC) -o tst_dev -DTEST_PROGRAM $(srcdir)/dev.c $(LIBS_BLKID) $(ALL_CFLAGS)

tst_devname: $(srcdir)/devname.c $(DEPLIBS_BLKID)
	$(E) "	LD $@"
	$(Q) $(CC) -o tst_devname -DTEST_PROGRAM $(srcdir)/devname.c $(LIBS_BLKID) $(ALL_CFLAGS)

tst_devno: $(srcdir)/devno.c $(DEPLIBS_BLKID)
	$(E) "	LD $@"
	$(Q) $(CC) -o tst_devno -DTEST_PROGRAM $(srcdir)/devno.c $(LIBS_BLKID) $(ALL_CFLAGS)

tst_getsize: $(srcdir)/getsize.c $(DEPLIBS_BLKID)
	$(E) "	LD $@"
	$(Q) $(CC) -o tst_getsize -DTEST_PROGRAM $(srcdir)/getsize.c $(LIBS_BLKID) $(ALL_CFLAGS)

tst_probe: $(srcdir)/probe.c $(DEPLIBS_BLKID)
	$(E) "	LD $@"
	$(Q) $(CC) -o tst_probe -DTEST_PROGRAM $(srcdir)/probe.c $(LIBS_BLKID) $(ALL_CFLAGS)

tst_read: $(srcdir)/read.c $(DEPLIBS_BLKID)
	$(E) "	LD $@"
	$(Q) $(CC) -o tst_read -DTEST_PROGRAM $(srcdir)/read.c $(LIBS_BLKID) $(ALL_CFLAGS)

tst_resolve: $(srcdir)/resolve.c $(DEPLIBS_BLKID)
	$(E) "	LD $@"
	$(Q) $(CC) -o tst_resolve -DTEST_PROGRAM $(srcdir)/resolve.c $(LIBS_BLKID) $(ALL_CFLAGS)

tst_save: $(srcdir)/save.c $(DEPLIBS_BLKID)
	$(E) "	LD $@"
	$(Q) $(CC) -o tst_save -DTEST_PROGRAM $(srcdir)/save.c $(LIBS_BLKID) $(ALL_CFLAGS)

tst_tag: $(srcdir)/tag.c $(DEPLIBS_BLKID)
	$(E) "	LD $@"
	$(Q) $(CC) -o tst_tag -DTEST_PROGRAM $(srcdir)/tag.c $(LIBS_BLKID) $(ALL_CFLAGS)

tst_types: tst_types.o blkid_types.h 
	$(E) "	LD $@"
	$(Q) $(CC) -o tst_types $(ALL_LDFLAGS) tst_types.o

../../misc/blkid.o: $(top_srcdir)/misc/blkid.c blkid.h
	$(E) "	CC $@"
	$(Q) $(CC) $(ALL_CFLAGS) -c $(top_srcdir)/misc/blkid.c \
		-o ../../misc/blkid.o

blkid: ../../misc/blkid.o libblkid.a $(DEPLIBUUID)
	$(E) "	LD $@"
	$(Q) $(CC) -o blkid ../../misc/blkid.o libblkid.a $(LIBUUID)

test_probe: test_probe.in Makefile
	$(E) "Creating test_probe..."
	$(E) "#!/bin/sh" > test_probe
	$(E) "SRCDIR=@srcdir@" >> test_probe
	$(Q) cat $(srcdir)/test_probe.in >> test_probe
	$(Q) chmod +x test_probe

fullcheck check:: all tst_cache tst_dev tst_devname tst_devno \
 tst_getsize tst_probe tst_read tst_resolve tst_save tst_tag \
 test_probe tst_types
	./test_probe
	./tst_types

blkid.pc: $(srcdir)/blkid.pc.in $(top_builddir)/config.status
	$(E) "	CONFIG.STATUS $@"
	$(Q) cd $(top_builddir); CONFIG_FILES=lib/blkid/blkid.pc ./config.status

installdirs::
	$(E) "	MKDIR_P $(libdir) $(includedir)/blkid"
	$(Q) $(MKDIR_P) $(DESTDIR)$(libdir) \
		$(DESTDIR)$(includedir)/blkid $(DESTDIR)$(pkgconfigdir)

install:: all installdirs 
	$(E) "	INSTALL_DATA $(libdir)/libblkid.a"
	$(Q) $(INSTALL_DATA) libblkid.a $(DESTDIR)$(libdir)/libblkid.a
	-$(Q) $(RANLIB) $(DESTDIR)$(libdir)/libblkid.a
	$(Q) $(CHMOD) $(LIBMODE) $(DESTDIR)$(libdir)/libblkid.a
	$(Q) set -e; for i in $(HFILES_IN); do \
		echo "	INSTALL_DATA $(includedir)/blkid/$$i"; \
		$(INSTALL_DATA) $$i $(DESTDIR)$(includedir)/blkid/$$i; \
	done
	$(Q) for i in $(SMANPAGES); do \
		echo "	INSTALL_DATA $(man3dir)/$$i"; \
		$(INSTALL_DATA) $$i $(DESTDIR)$(man3dir)/$$i; \
	done
	$(E) "	INSTALL_DATA $(pkgconfigdir)/blkid.pc"
	$(Q) $(INSTALL_DATA) blkid.pc $(DESTDIR)$(pkgconfigdir)/blkid.pc

uninstall::
	$(RM) -f $(DESTDIR)$(libdir)/libblkid.a \
		$(DESTDIR)$(pkgconfigdir)/blkid.pc
	$(RM) -rf $(DESTDIR)$(includedir)/blkid
	for i in $(SMANPAGES); do \
		$(RM) -f $(DESTDIR)$(man3dir)/$$i; \
	done

clean::
	$(RM) -f \#* *.s *.o *.orig *.a *~ *.bak tst_cache tst_dev tst_devname \
		tst_devno tst_getsize tst_probe tst_read tst_resolve tst_save \
		tst_tag tst_types tests/*.out tests/*.ok \
		tests/*.img results test_probe core profiled/* \
		blkid.h blkid_types.h ../libblkid.a ../libblkid_p.a \
		$(SMANPAGES) blkid blkid.pc
	@echo rmdir tests/tmp tests
	@(rmdir tests/tmp tests 2> /dev/null ; exit 0)

mostlyclean:: clean
distclean:: clean
	$(RM) -f .depend Makefile blkid.pc \
		$(srcdir)/TAGS $(srcdir)/Makefile.in.old

$(OBJS): subdirs $(HFILES_IN)

# +++ Dependency line eater +++
# 
# Makefile dependencies follow.  This must be the last section in
# the Makefile.in file
#
cache.o: $(srcdir)/cache.c $(top_builddir)/lib/config.h \
 $(top_builddir)/lib/dirpaths.h $(srcdir)/blkidP.h $(srcdir)/list.h
dev.o: $(srcdir)/dev.c $(top_builddir)/lib/config.h \
 $(top_builddir)/lib/dirpaths.h $(srcdir)/blkidP.h $(srcdir)/list.h
devname.o: $(srcdir)/devname.c $(top_builddir)/lib/config.h \
 $(top_builddir)/lib/dirpaths.h $(srcdir)/blkidP.h $(srcdir)/list.h
devno.o: $(srcdir)/devno.c $(top_builddir)/lib/config.h \
 $(top_builddir)/lib/dirpaths.h $(srcdir)/blkidP.h $(srcdir)/list.h
getsize.o: $(srcdir)/getsize.c $(top_builddir)/lib/config.h \
 $(top_builddir)/lib/dirpaths.h $(srcdir)/blkidP.h $(srcdir)/list.h
llseek.o: $(srcdir)/llseek.c $(top_builddir)/lib/config.h \
 $(top_builddir)/lib/dirpaths.h $(srcdir)/blkidP.h $(srcdir)/list.h
probe.o: $(srcdir)/probe.c $(top_builddir)/lib/config.h \
 $(top_builddir)/lib/dirpaths.h $(srcdir)/blkidP.h $(srcdir)/list.h \
 $(srcdir)/probe.h
read.o: $(srcdir)/read.c $(top_builddir)/lib/config.h \
 $(top_builddir)/lib/dirpaths.h $(srcdir)/blkidP.h $(srcdir)/list.h
resolve.o: $(srcdir)/resolve.c $(top_builddir)/lib/config.h \
 $(top_builddir)/lib/dirpaths.h $(srcdir)/blkidP.h $(srcdir)/list.h
save.o: $(srcdir)/save.c $(top_builddir)/lib/config.h \
 $(top_builddir)/lib/dirpaths.h $(srcdir)/blkidP.h $(srcdir)/list.h
tag.o: $(srcdir)/tag.c $(top_builddir)/lib/config.h \
 $(top_builddir)/lib/dirpaths.h $(srcdir)/blkidP.h $(srcdir)/list.h
version.o: $(srcdir)/version.c $(top_builddir)/lib/config.h \
 $(top_builddir)/lib/dirpaths.h $(top_srcdir)/version.h
