#
# Broadcom Linux Router Makefile
#
# Copyright 2005, Broadcom Corporation
# All Rights Reserved.
#
# THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
# KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
# SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
#
#

include common.mak

CFLAGS = -O2 -Wall #-mips32
CFLAGS += -I../shared -I../../include -I.
ifeq ($(STATIC),1)
CFLAGS += -static
endif
#CFLAGS += -static

#
#
#
ifeq ($(TOMATO_DEV),jon)
SEP=echo -e "\033[41;1m   $@   \033[0m"
else
SEP=true
endif

#
# standard packages
#
obj-y += ipt-parse

#
# configurable packages
#

obj-clean := $(foreach obj,$(obj-y) $(obj-n),$(obj)-clean)
obj-install := $(foreach obj,$(obj-y),$(obj)-install)

#
# Basic rules
#

all: clean-build $(obj-y)

fooit:
	@../btools/libfoo.pl

install package: $(obj-install) $(LINUXDIR)/.config
	@$(SEP)

	install -d $(TARGETDIR)

#
# cleaners
#

clean: clean-build $(obj-clean)
	#rm -rf layer7/squished

clean-build: dummy
	#rm -rf $(TARGETDIR)
	#rm -rf $(INSTALLDIR)
	#rm -f $(PLATFORMDIR)/linux.trx $(PLATFORMDIR)/vmlinuz $(PLATFORMDIR)/target.image
	#rm -rf $(PLATFORMDIR)/extras

distclean: clean
ifneq ($(INSIDE_MAK),1)
	$(MAKE) -C .. $@ INSIDE_MAK=1
endif

#
# configuration
#

CONFIG_IN := config/config.in

config/conf config/mconf:
	@$(MAKE) -C config

rconf: config/conf
	@config/conf $(CONFIG_IN)

rmconf: config/mconf
	@config/mconf $(CONFIG_IN)

roldconf: config/conf
	@config/conf -o $(CONFIG_IN)

kconf:
	@$(MAKE) -C $(LINUXDIR) config

kmconf:
	@$(MAKE) -C $(LINUXDIR) menuconfig

koldconf:
	@$(MAKE) -C $(LINUXDIR) oldconfig

config conf: rconf kconf

menuconfig mconf: rmconf kmconf

oldconfig oldconf: roldconf koldconf


#
# overrides and extra dependencies
#

busybox: dummy
	$(MAKE) -C busybox CFLAGS="-Os"
# V=1

busybox-install:
	rm -rf $(INSTALLDIR)/busybox
	$(MAKE) -C busybox install CONFIG_PREFIX=$(INSTALLDIR)/busybox CFLAGS="-Os"

busybox-test: dummy
	$(MAKE) -C busybox objsizes CFLAGS="-Os"

# 1.2:
#	busybox: busybox/include/bb_config.h
#		@$(MAKE) -C busybox CROSS_CFLAGS="-mips2"
#	busybox/include/bb_config.h:
#		@$(MAKE) -C busybox oldconfig
#		@$(MAKE) -C busybox clean
#	busybox-install:
#		rm -rf $(INSTALLDIR)/busybox
#		$(MAKE) -C busybox install PREFIX=$(INSTALLDIR)/busybox


ipt-parse: 

	@echo " [ipt-parse] CC $@"
ifeq ($(STATIC),1)
#	$(CC) $(CFLAGS) -static -o ipt-parse -L. src/ipt-parse.c src/sqlite3.c -lpthread -ldl
	$(CC) $(CFLAGS) -static -o ipt-parse -L. src/ipt-parse.c
else
#	@$(CC) $(CFLAGS) -o ipt-parse -L. src/ipt-parse.c src/sqlite3.c -lpthread -ldl
	@$(CC) $(CFLAGS) -o ipt-parse -L. src/ipt-parse.c src/sqlite3.c -ldl -DSQLITE_THREADSAFE=0 -DSQLITE_ENABLE_LOCKING_STYLE=1 -DSQLITE_DISABLE_DIRSYNC -DSQLITE_NO_SYNC
endif
	
	$(STRIP) ipt-parse
	$(SIZECHECK)
	$(CPTMP)

ipt-parse-install:
	@true

ipt-parse-clean:
	rm -f ipt-parse *.o *.a *.so

#	perl -e 'while (<>) { s/.SECS/time()-(24*60*60)/e; print; }' < httpd/gencert.sh > $(INSTALLDIR)/openssl/usr/sbin/gencert.sh
#	chmod 0500 $(INSTALLDIR)/openssl/usr/sbin/gencert.sh

#	install -D openssl/libssl.so $(INSTALLDIR)/openssl/usr/lib/libssl.so
#	$(STRIP) $(INSTALLDIR)/openssl/usr/lib/libssl.so

#	libnet:
#		@$(SEP)
#		@-mkdir -p libnet/lib
#		@$(MAKE) -C libnet CC=$(CC) AR=$(AR) RANLIB=$(RANLIB)

#	libpcap:
#		@$(SEP)
#		@$(MAKE) -C libpcap CC=$(CC) AR=$(AR) RANLIB=$(RANLIB)

#
# Generic rules
#

%:
	@[ ! -d $* ] || ( $(SEP); $(MAKE) -C $* )


%-clean:
	@-[ ! -d $* ] || $(MAKE) -C $* clean

%-install:
	@[ ! -d $* ] || $(MAKE) -C $* install INSTALLDIR=$(INSTALLDIR)/$*

%-build:
	$(MAKE) $*-clean $*

$(obj-y) $(obj-n) $(obj-clean) $(obj-install): dummy

.PHONY: all clean distclean mrproper install package
.PHONY: conf mconf oldconf kconf kmconf config menuconfig oldconfig
.PHONY: dummy libnet libpcap
