AXIS_USABLE_LIBS = UCLIBC GLIBC
include $(AXIS_TOP_DIR)/tools/build/Rules.axis

SRCDIR   = $(AXIS_TOP_DIR)/apps/temploggerd/temploggerd
LDFLAGS  += -L$(prefix)/lib
CPPFLAGS += -I$(prefix)/include
CFLAGS += -I$(prefix)/include

PKG_INSTALL_DIR:=$(SRCDIR)/install_dir

INSTOWNER = -o root -g root

$(SRCDIR)/Makefile:
	cd $(SRCDIR) && \
	DESTDIR="$(PKG_INSTALL_DIR)" \
	RANLIB="$(RANLIB)" AR="$(AR)" STRIP="$(STRIP)" \
	CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
	CPPFLAGS="$(CPPFLAGS)" \
	./configure --verbose \
		--target=$(AXIS_BUILDTYPE) \
		--host=$(AXIS_BUILDTYPE) \
		--program-prefix="" \
		--program-suffix="" \
		--prefix= \
		--bindir=/bin \
		--libdir=/lib \
		--datadir=/usr/lib \
		--includedir=/include \
		--oldincludedir=/include

all: build

build: $(SRCDIR)/Makefile
	mkdir -p $(PKG_INSTALL_DIR)
	$(MAKE) -C $(SRCDIR) \
		DESTDIR="$(PKG_INSTALL_DIR)" \
		all install
	touch $@

install: all
	$(INSTALL) -d $(prefix)/bin
	#$(INSTALL) -d $(prefix)/lib
#	$(STRIP) -g $(PKG_INSTALL_DIR)/bin/rrd_replace
#	$(STRIP) -g $(PKG_INSTALL_DIR)/bin/temploggerd
#	cat $(prefix)/bin/add_new_sensor.sh | sed 's/bash/sh/g' > $(prefix)/bin/add_new_sensor.sh
#	chmod 755 $(prefix)/bin/add_new_sensor.sh
	sed -i 's/bash/sh/g' $(PKG_INSTALL_DIR)/bin/add_new_sensor.sh
	$(INSTALL) $(INSTOWNER) -m 0755 $(PKG_INSTALL_DIR)/bin/add_new_sensor.sh $(prefix)/bin/
	$(INSTALL) $(INSTOWNER) -m 0755 $(PKG_INSTALL_DIR)/bin/temploggerd $(prefix)/bin/
	$(INSTALL) $(INSTOWNER) -m 0755 $(PKG_INSTALL_DIR)/bin/rrd_replace $(prefix)/bin/
	$(INSTALL) -d $(prefix)/usr/lib/temploggerd
	cp -fRp $(PKG_INSTALL_DIR)/usr/lib/temploggerd/images $(prefix)/usr/lib/temploggerd/
	cp -fRp $(PKG_INSTALL_DIR)/usr/lib/temploggerd/templates $(prefix)/usr/lib/temploggerd/
	$(INSTALL) $(INSTOWNER) -m 0644 temploggerd.default $(prefix)/etc/conf.d/temploggerd
	$(INSTALL) $(INSTOWNER) -m 0755 kill-temploggerd $(prefix)/bin/
	$(INSTALL) $(INSTOWNER) -m 0755 run-temploggerd $(prefix)/bin/
	$(INSTALL) $(INSTOWNER) -m 0755 temploggerd.init $(prefix)/etc/init.d/temploggerd
	$(INSTALL) $(INSTOWNER) -m 0644 temploggerd.conf.default $(prefix)/usr/lib/temploggerd
	$(INSTALL) -d $(prefix)/usr/html/
	ln -sf /var/lib/temploggerd/www/temploggerd $(prefix)/usr/html/temploggerd
	$(INSTALL) -d $(prefix)/usr/html/axis-cgi/
	ln -sf /var/lib/temploggerd/cgi-bin $(prefix)/usr/html/axis-cgi/temploggerd

clean:
	$(RM) -r $(SRCDIR)/Makefile
