# lib/Makefile for libelf.
# Copyright (C) 1995 - 2006 Michael Riepe
# 
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
# 
# This library 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
# Library General Public License for more details.
# 
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

# @(#) $Id: Makefile.in,v 1.1 2008/06/16 00:01:21 cjohns Exp $

instroot =

prefix = @prefix@
exec_prefix = @exec_prefix@
libdir = @libdir@
includedir = @includedir@
installdirs = $(libdir) $(includedir) $(includedir)/libelf

CC = @CC@
LD = @LD@
AR = ar
MV = mv -f
RM = rm -f
LN_S = @LN_S@
RANLIB = @RANLIB@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@

CFLAGS = @CFLAGS@
CPPFLAGS = @CPPFLAGS@
DEFS = -DHAVE_CONFIG_H
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
DEPSHLIBS = @DEPSHLIBS@

DO_SHLIB = @DO_SHLIB@
PICFLAGS = @PICFLAGS@
SHLIB_SFX = @SHLIB_SFX@
SHLINK_SFX = @SHLINK_SFX@
SONAME_SFX = @SONAME_SFX@
LINK_SHLIB = @LINK_SHLIB@
INSTALL_SHLIB = @INSTALL_SHLIB@

SHLIB = libelf$(SHLIB_SFX)
SHLINK = libelf$(SHLINK_SFX)
SONAME = libelf$(SONAME_SFX)

# install includes in includedir?
DO_COMPAT = @DO_COMPAT@

COMPILE = $(CC) -c $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) $(XCFLAGS)

# no user serviceable parts below

PACKAGE = @PACKAGE@
VERSION = @VERSION@
MAJOR = @MAJOR@

SHELL = /bin/sh
@SET_MAKE@

srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@

topdir = ..
subdir = lib

.SUFFIXES:
.SUFFIXES: .c .o
.c.o:
	@$(RM) $@ $(@:.o=.os)
	if test -n "$(PICFLAGS)"; then \
	  $(COMPILE) $(PICFLAGS) $< && $(MV) $@ $(@:.o=.os); \
	else true; fi
	$(COMPILE) $<

INCLUDES = -I$(topdir) -I. -I$(srcdir)

# generic sources
SRCS1 = begin.c cntl.c end.c errmsg.c errno.c fill.c flag.c getarhdr.c \
	getarsym.c getbase.c getdata.c getident.c getscn.c hash.c kind.c \
	ndxscn.c newdata.c newscn.c next.c nextscn.c rand.c rawdata.c \
	rawfile.c strptr.c update.c version.c checksum.c
OBJS1 = begin.o cntl.o end.o errmsg.o errno.o fill.o flag.o getarhdr.o \
	getarsym.o getbase.o getdata.o getident.o getscn.o hash.o kind.o \
	ndxscn.o newdata.o newscn.o next.o nextscn.o rand.o rawdata.o \
	rawfile.o strptr.o update.o version.o checksum.o

# 32-bit sources
SRCS2 = 32.fsize.c 32.getehdr.c 32.getphdr.c 32.getshdr.c 32.newehdr.c \
	32.newphdr.c 32.xlatetof.c
OBJS2 = 32.fsize.o 32.getehdr.o 32.getphdr.o 32.getshdr.o 32.newehdr.o \
	32.newphdr.o 32.xlatetof.o

# support
SRCS3 = cook.c data.c input.c assert.c
OBJS3 = cook.o data.o input.o assert.o

# nlist
SRCS4 = nlist.c
OBJS4 = nlist.o

# opt
SRCS5 = opt.delscn.c x.remscn.c x.movscn.c x.elfext.c
OBJS5 = opt.delscn.o x.remscn.o x.movscn.o x.elfext.o

# 64-bit sources
SRCS64 = 64.xlatetof.c gelfehdr.c gelfphdr.c gelfshdr.c gelftrans.c swap64.c
OBJS64 = 64.xlatetof.o gelfehdr.o gelfphdr.o gelfshdr.o gelftrans.o swap64.o

# Versioning sources
SRCS_V = verdef_32_tof.c verdef_32_tom.c verdef_64_tof.c verdef_64_tom.c
OBJS_V = verdef_32_tof.o verdef_32_tom.o verdef_64_tof.o verdef_64_tom.o
HDRS_V = verdef.h verneed.h

SRCS = $(SRCS1) $(SRCS2) $(SRCS3) $(SRCS4) $(SRCS5) $(SRCS64) $(SRCS_V)
OBJS = $(OBJS1) $(OBJS2) $(OBJS3) $(OBJS4) $(OBJS5) $(OBJS64) $(OBJS_V)

# missing functions
LIBSRCS = memset.c
LIBOBJS = @LIBOBJS@

# public header files
HDRS = libelf.h nlist.h gelf.h

# public header files (created by configure)
AUXHDRS = sys_elf.h

# private header files
PRIVHDRS = byteswap.h errors.h ext_types.h private.h elf_repl.h \
	$(HDRS_V)

DISTFILES = $(SRCS) $(LIBSRCS) $(HDRS) $(PRIVHDRS) Makefile.in sys_elf.h.in \
    Makefile.w32 build.bat config.h.w32 libelf.def sys_elf.h.w32

all: libelf.a shared-$(DO_SHLIB)

check:

shared-yes: $(SHLIB)
shared-no:

libelf.a: $(OBJS) $(LIBOBJS)
	@$(RM) $@
	$(AR) rcv $@ $(OBJS) $(LIBOBJS)
	$(RANLIB) $@

$(SHLIB): libelf.a
	@$(RM) $(SHLIB)
	$(LINK_SHLIB) -o $(SHLIB) $(OBJS:.o=.os) $(LIBOBJS:.o=.os) $(DEPSHLIBS)
	if test "$(SONAME)" = "$(SHLIB)"; then true; else \
	  $(RM) $(SONAME) && $(LN_S) $(SHLIB) $(SONAME); \
	fi
	if test "$(SHLINK)" = "$(SHLIB)"; then true; else \
	  $(RM) $(SHLINK) && $(LN_S) $(SHLIB) $(SHLINK); \
	fi

install: install-data \
	install-shared-$(DO_SHLIB) install-compat-$(DO_COMPAT)

installdirs: $(top_srcdir)/mkinstalldirs
	dirs="$(installdirs)"; for dir in $$dirs; do \
	    $(SHELL) $(top_srcdir)/mkinstalldirs $(instroot)$$dir; \
	done

install-data: all installdirs
	$(INSTALL_DATA) libelf.a $(instroot)$(libdir)
	-cd $(instroot)$(libdir) && $(RANLIB) libelf.a
	files="$(HDRS) $(AUXHDRS) elf_repl.h"; for file in $$files; do \
	  if test -r $$file; then \
	    $(INSTALL_DATA) $$file $(instroot)$(includedir)/libelf; \
	  else \
	    $(INSTALL_DATA) $(srcdir)/$$file $(instroot)$(includedir)/libelf; \
	  fi; \
	done

uninstall: uninstall-data \
	uninstall-shared-$(DO_SHLIB) uninstall-compat-$(DO_COMPAT)

uninstall-data:
	$(RM) $(instroot)$(libdir)/libelf.a
	$(RM) -r $(instroot)$(includedir)/libelf

install-shared-yes: install-shared
install-shared-no:
install-shared: installdirs $(SHLIB)
	$(INSTALL_SHLIB) $(SHLIB) $(instroot)$(libdir)
	if test "$(SONAME)" = "$(SHLIB)"; then true; else \
	  cd $(instroot)$(libdir) && $(RM) $(SONAME) && $(LN_S) $(SHLIB) $(SONAME); \
	fi
	if test "$(SHLINK)" = "$(SHLIB)"; then true; else \
	  cd $(instroot)$(libdir) && $(RM) $(SHLINK) && $(LN_S) $(SHLIB) $(SHLINK); \
	fi

uninstall-shared-yes: uninstall-shared
uninstall-shared-no:
uninstall-shared:
	cd $(instroot)$(libdir) && $(RM) $(SHLIB) $(SONAME) $(SHLINK)

install-compat-yes: install-compat
install-compat-no:
install-compat: installdirs
	files="$(HDRS)"; for file in $$files; do \
	  if test -f $(instroot)$(includedir)/$$file; then true; else \
	    echo "#include <libelf/$$file>" > $(instroot)$(includedir)/$$file; \
	  fi; \
	done

uninstall-compat-yes: uninstall-compat
uninstall-compat-no:
uninstall-compat:
	files="$(HDRS)"; for file in $$files; do \
	  if grep "^#include <libelf/$$file>\$$" $(instroot)$(includedir)/$$file >/dev/null 2>&1; then \
	    $(RM) $(instroot)$(includedir)/$$file; \
	  else true; fi; \
	done

mostlyclean:
	$(RM) *.o *.a *.os $(SHLIB) $(SONAME) $(SHLINK)
	$(RM) *~ core a.out errlist

clean: mostlyclean

distclean: clean
	$(RM) stamp-h $(AUXHDRS)
	$(RM) Makefile

maintainer-clean: distclean

# maintainer only

MAINT = @MAINT@

distdir = $(PACKAGE)-$(VERSION)
distsubdir = $(topdir)/$(distdir)/$(subdir)
$(MAINT)dist: $(DISTFILES)
	if test -d $(distsubdir); then true; else mkdir $(distsubdir); fi
	files="$(DISTFILES)"; for file in $$files; do \
	  ln $(srcdir)/$$file $(distsubdir) || \
	    cp -p $(srcdir)/$$file $(distsubdir) || exit 1; \
	done

# For the justification of the following Makefile rules, see node
# `Automatic Remaking' in GNU Autoconf documentation.

$(MAINT)Makefile: Makefile.in $(topdir)/config.status
	cd $(topdir) && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= ./config.status

$(MAINT)sys_elf.h: stamp-h
$(MAINT)stamp-h: sys_elf.h.in $(topdir)/config.status
	cd $(topdir) && CONFIG_FILES= CONFIG_HEADERS=$(subdir)/sys_elf.h ./config.status
	$(RM) stamp-h && echo timestamp > stamp-h

# Tell versions [3.59,3.63) of GNU make not to export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

# dependencies
$(OBJS): private.h $(topdir)/config.h libelf.h gelf.h errors.h $(AUXHDRS)
32.fsize.o: ext_types.h
32.xlatetof.o: byteswap.h ext_types.h
64.xlatetof.o: byteswap.h ext_types.h
getarsym.o: byteswap.h
memset.o: $(topdir)/config.h
nlist.o: nlist.h
swap64.o: byteswap.h
$(OBJS_V): byteswap.h ext_types.h $(HDRS_V)
