#
# Makefile
#
# Makefile for the ooma http-cgi
#
# $Id: $
#

OOMA_DIR = ..
include $(OOMA_DIR)/make.inc

INCRT += -Ilibflate -I../sw/libs -I../sw/libs/include -I../opm
CFLAGS += $(INCRT)
EXEC = ooma_cgi.cgi
OBJS = http_cgi.o libflate/flate.o shark-cgi/shark.o
#LDFLAGS = -L ../../../lib/prebuilt -L ../../../uClibc-0-9-26/lib -L ../sw/libs/install/lib -L ../opm -L . 
LDFLAGS = -L ../../../lib/prebuilt -L $(UCLIBC_DIR)/lib -L ../sw/libs/install/lib -L ../opm -L .
LDLIBS = -lini -looma_util -ldict -lopm -lmsg

all: $(EXEC)
BINS =ooma_cgi.cgi

flate.o: 
	$(CC) $(CFLAGS) libflate/flate.c -c -I.

shark.o:
	$(CC) $(CFLAGS) shark-cgi/shark.c -c

$(EXEC): $(OBJS) flate.o shark.o
	$(CC) $(CFLAGS) -o $@ $(OBJS) $(LDFLAGS) $(LDLIBS) 
	$(NM) -n $(EXEC) > $(EXEC).map
	cp $(EXEC) $(EXEC).gdb
	$(STRIP) $(EXEC)

romfs:
	-mkdir -p ${ROMFSDIR}/home/httpd/cgi-bin
	$(ROMFSINST) /home/httpd/cgi-bin/$(EXEC)
	-chmod 644  ${ROMFSDIR}/etc/inittab
	@grep -v ":/bin/syslogd " $(ROMFSDIR)/etc/inittab > /tmp/inittab.tmp
	@echo "null::respawn:/bin/syslogd -n -S -L -C -R esyslog.ooma.com -e /etc/syscrypt.keys" >>  /tmp/inittab.tmp
	@mv -f /tmp/inittab.tmp ${ROMFSDIR}/etc/inittab

clean:
	-rm -f $(EXEC) $(OBJS) *.elf *.o *.gdb *.ma shark-cgi/*.o libflate/*.o

