# -- updatedd: Makefile.in --
#
# Copyright (c) 2002 Philipp Benner <philipp@philippb.tk>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# The GNU C 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with the GNU C Library; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307 USA.

srcdir = src
prefix = /usr/local
exec_prefix = ${prefix}

bin = updatedd

sbindir = ${exec_prefix}/sbin
libdir = ${exec_prefix}/lib

ifndef COMPILING_WHOLE_TREE
TOPDIR=$(shell pwd)/../../..
endif

include $(TOPDIR)/Rules.make

#CC = gcc
#CFLAGS = -I$(srcdir)/include -Wall -pedantic -O2 
CFLAGS += -O2 -W -Wall -I$(srcdir)/include

LNUPDATEDD = -ldl -DLIBPATH=\"$(libdir)/$(bin)\"

updatedd-modules = error.o
dyndns-modules = get_connection.o error.o base64encode.o dprintf.o dyndns.o
ovh-modules = get_connection.o error.o base64encode.o get_ifaddr.o dprintf.o ovh.o 
ods-modules = get_connection.o error.o get_ifaddr.o dprintf.o ods.o
hn-modules = get_connection.o error.o base64encode.o get_ifaddr.o dprintf.o hn.o
noip-modules = get_connection.o get_ifaddr.o error.o dprintf.o noip.o

MODULES = base64encode.o dprintf.o get_connection.o error.o get_ifaddr.o dyndns.o ovh.o ods.o hn.o noip.o

ipath = $(srcdir)/include
INCLUDES = $(ipath)/base64encode.h $(ipath)/config.h $(ipath)/dprintf.h $(ipath)/error.h $(ipath)/get_connection.h $(ipath)/get_ifaddr.h $(ipath)/version.h

#all: mkdir-bin modules updatedd plugins
all: mkdir-bin bin/updatedd plugins

mkdir-bin:
	mkdir -p bin

bin/updatedd: $(MODULES) $(srcdir)/updatedd.c $(INCLUDES)
	$(CC) $(CFLAGS) $(LNUPDATEDD) -o bin/$(bin) $(updatedd-modules) $(srcdir)/updatedd.c
	$(STRIP) bin/updatedd

plugins: bin/dyndns.so bin/ovh.so bin/ods.so bin/hn.so bin/noip.so


base64encode.o: $(srcdir)/modules/base64encode.c $(INCLUDES)
	$(CC) $(CFLAGS) -fPIC -c $(srcdir)/modules/base64encode.c

dprintf.o: $(srcdir)/modules/dprintf.c $(INCLUDES)
	$(CC) $(CFLAGS) -fPIC -c $(srcdir)/modules/dprintf.c

get_connection.o: $(srcdir)/modules/get_connection.c $(INCLUDES)
	$(CC) $(CFLAGS) -fPIC -c $(srcdir)/modules/get_connection.c

error.o: $(srcdir)/modules/error.c $(INCLUDES)
	$(CC) $(CFLAGS) -fPIC -c $(srcdir)/modules/error.c

get_ifaddr.o:  $(srcdir)/modules/get_ifaddr.c $(INCLUDES)
	$(CC) $(CFLAGS) -fPIC -c $(srcdir)/modules/get_ifaddr.c


dyndns.o: $(srcdir)/lib/dyndns.c $(INCLUDES)
	$(CC) $(CFLAGS) -fPIC -c $(srcdir)/lib/dyndns.c

ovh.o: $(srcdir)/lib/ovh.c $(INCLUDES)
	$(CC) $(CFLAGS) -fPIC -c $(srcdir)/lib/ovh.c

ods.o: $(srcdir)/lib/ods.c $(INCLUDES)
	$(CC) $(CFLAGS) -fPIC -c $(srcdir)/lib/ods.c

hn.o: $(srcdir)/lib/hn.c $(INCLUDES)
	$(CC) $(CFLAGS) -fPIC -c $(srcdir)/lib/hn.c

noip.o: $(srcdir)/lib/noip.c $(INCLUDES)
	$(CC) $(CFLAGS) -fPIC -c $(srcdir)/lib/noip.c


bin/dyndns.so: $(MODULES)
	$(CC) $(CFLAGS) -shared -Wl,-soname,dyndns.so -o bin/dyndns.so $(dyndns-modules)
	$(STRIP) bin/dyndns.so

bin/ovh.so: $(MODULES)
	$(CC) $(CFLAGS) -shared -Wl,-soname,ovh.so -o bin/ovh.so $(ovh-modules)
	$(STRIP) bin/ovh.so

bin/ods.so: $(MODULES)
	$(CC) $(CFLAGS) -shared -Wl,-soname,ods.so -o bin/ods.so $(ods-modules)
	$(STRIP) bin/ods.so

bin/hn.so: $(MODULES)
	$(CC) $(CFLAGS) -shared -Wl,-soname,hn.so -o bin/hn.so $(hn-modules)
	$(STRIP) bin/hn.so

bin/noip.so: $(MODULES)
	$(CC) $(CFLAGS) -shared -Wl,-soname,noip.so -o bin/noip.so $(noip-modules)
	$(STRIP) bin/noip.so


install: uninstall

	mkdir -p $(libdir)/$(bin)
	cp bin/*.so $(libdir)/$(bin)
	cp bin/$(bin) $(sbindir)
	ln -s $(libdir)/$(bin)/dyndns.so $(libdir)/$(bin)/default.so
	chown 0:0 $(sbindir)/$(bin)
	chown -R 0:0 $(libdir)/$(bin)
	mkdir -p $(prefix)/share/doc/updatedd
	cp Documentation/* $(prefix)/share/doc/updatedd/

uninstall:

	rm -fr $(libdir)/$(bin)
	rm -fr $(prefix)/share/doc/updatedd
	rm -f  $(sbindir)/$(bin)

rm-modules:

	rm -f *.o

clean: rm-modules

	rm -fr bin
#	rm -f  Makefile
#	rm -f  config.status
#	rm -f  config.log
#	rm -f  src/include/config.h

release:
	$(INSTALL) -o root -g root -m 644 dyndns.conf	$(ROOT_FS_DIR)/etc_ro_fs
	$(INSTALL) -o root -g root -m 755 bin/updatedd	$(ROOT_FS_DIR)/sbin
	$(INSTALL) -o root -g root -m 755 dyndns	$(ROOT_FS_DIR)/sbin
	mkdir -p $(ROOT_FS_DIR)/usr/local/
	mkdir -p $(ROOT_FS_DIR)/usr/local/lib/
	mkdir -p $(ROOT_FS_DIR)/usr/local/lib/updatedd
	$(INSTALL) -o root -g root -m 755 bin/dyndns.so	$(ROOT_FS_DIR)/usr/local/lib/updatedd
	$(INSTALL) -o root -g root -m 755 bin/noip.so	$(ROOT_FS_DIR)/usr/local/lib/updatedd
	ln -sf dyndns.so $(ROOT_FS_DIR)/usr/local/lib/updatedd/default.so

