#
# Makefile for the Loki registry library
# $Id: Makefile.in,v 1.20 2004/11/24 02:33:32 megastep Exp $
#

CC		:= @CC@
CSRC	:= setupdb.c md5.c arch.c @GETOPT_C@
OS      := $(shell uname -s)
ARCH    := @ARCH@
OBJS    := $(CSRC:%.c=$(ARCH)/%.o)

SETUPDB_VERSION_MAJOR=@SETUPDB_VERSION_MAJOR@
SETUPDB_VERSION_MINOR=@SETUPDB_VERSION_MINOR@
DISTDIR = ..
VERSION = @SETUPDB_VERSION_MAJOR@.@SETUPDB_VERSION_MINOR@.@SETUPDB_VERSION_RELEASE@
PACKAGE = setupdb-$(VERSION)

CFLAGS	= @CPPFLAGS@ @CFLAGS@
CFLAGS	+= -DSETUPDB_VERSION_MAJOR=$(SETUPDB_VERSION_MAJOR)
CFLAGS  += -DSETUPDB_VERSION_MINOR=$(SETUPDB_VERSION_MINOR)
LIBS	= @LIBS@

IMAGE	= @IMAGE@

override TARGET = $(ARCH)/libsetupdb.a

all: $(TARGET)

$(ARCH):
	mkdir $(ARCH)

$(ARCH)/%.o: %.c
	$(CC) -o $@ $(CFLAGS) -c $<

$(TARGET): $(ARCH) $(OBJS)
	ar rcs $@ $(OBJS)

convert: $(ARCH) $(ARCH)/convert.o $(TARGET)
	$(CC) -g -o $@ $(ARCH)/convert.o $(TARGET) $(LIBS) @STATIC@
	strip $@
	@BRANDELF@ -t $(OS) $@

install-convert: convert
	cp convert $(IMAGE)/bin/$(OS)/$(ARCH)/

brandelf: $(ARCH) $(ARCH)/brandelf.o
	$(CC) -o $@ $(ARCH)/brandelf.o

md5sum: md5.c
	$(CC) $(CFLAGS) -o $@ md5.c -DMD5SUM_PROGRAM -lz @STATIC@
	strip $@
	@BRANDELF@ -t $(OS) $@

setupdb: register.c $(TARGET)
	$(CC) $(CFLAGS) -o $@ register.c $(TARGET) $(LIBS) @STATIC@

install-register: setupdb
	strip setupdb
	@BRANDELF@ -t $(OS) setupdb
	cp setupdb $(IMAGE)/bin/$(OS)/$(ARCH)/

clean:
	rm -f $(ARCH)/*.o *~

mostlyclean: clean
	rm -f convert md5sum brandelf setupdb
	rm -f Makefile config.cache config.status config.log

distclean: mostlyclean
	rm -rf alpha ppc sparc64 x86

dist: distclean
	cp -r . $(DISTDIR)/$(PACKAGE)
	(cd $(DISTDIR)/$(PACKAGE) && rm -r `find . -name CVS`)
	(cd $(DISTDIR)/$(PACKAGE) && rm -r `find . -name .cvsignore`)
	(cd $(DISTDIR) && tar zcvf $(PACKAGE).tar.gz $(PACKAGE))
	rm -rf $(DISTDIR)/$(PACKAGE)

dep: depend

depend:
	$(CC) -MM $(CFLAGS) $(CSRC) > .depend

ifeq ($(wildcard .depend),.depend)
include .depend
endif
