 
# Makefile for floppyfw.
# As you can see, this is based on the buildroot/busybox/uClibc Make system.
# 
# Changes are Copyright (C) 2003-2004 Thomas Lundquist <thomasez@zelow.no>
#

# Makefile for a simple busybox/uClibc root filesystem
#
# Copyright (C) 2001-2003 Erik Andersen <andersen@codepoet.org>
# Copyright (C) 2002 by Tim Riker <Tim@Rikers.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Library General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program 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
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA

# $Id: Makefile,v 1.31 2005/12/07 19:50:42 thomasez Exp $

#############################################################
#
# EDIT this stuff to suit your system and preferences
#
# Use := when possible to get precomputation, thereby 
# speeding up the build process.
#
#############################################################

# Which version of floppyfw is this?
FLOPPYFW_VERSION=3.0.11

# What sortof target system shall we compile this for?
ARCH:=i386
#ARCH:=arm
#ARCH:=mips
#ARCH:=mipsel
#ARCH:=powerpc
#ARCH:=sh4
#ARCH:=cris
#ARCH:=m68k
#ARCH:=v850
#ARCH:=sparc
#ARCH:=sh64
#ARCH:=whatever

# If you want to add FPU/MATH emulation, set this to true;
# (Not properly tested yet.)
EMULATE_FPU=false

# Command used to download source code
WGET:=wget --passive-ftp

# Optimize toolchain for which type of CPU?
# WARNING!!!  CURRENTLY BROKEN!!! LEAVE IT AS $(ARCH)!!!
OPTIMIZE_FOR_CPU=$(ARCH)
# WARNING!!!  CURRENTLY BROKEN!!! LEAVE IT AS $(ARCH)!!!
#OPTIMIZE_FOR_CPU=i486
#OPTIMIZE_FOR_CPU=strongarm
#OPTIMIZE_FOR_CPU=whatever

TARGET_OPTIMIZATION=-Os
TARGET_DEBUGGING= #-g

# Any additional gcc options you may want to include....
EXTRA_GCC_CONFIG_OPTIONS=

# For SMP machines some stuff can be run in parallel
# This one sets j<amount of CPUs> but it may be just as good or even better
# with amount +1
# JLEVEL=-j$(shell expr $(shell grep -i -c '^processor[[:space:]]*:[[:space:]]*[0-9]\+' /proc/cpuinfo) \+ 1)
# Or if running distcc: 
# JLEVEL=-j5

# Sourceforge-mirror:
SF_HOST=superb-east
SF_MIRROR=http://$(SF_HOST).dl.sourceforge.net

# NICs you want in the nics.ffw module package separated by a space.
# If you want options to the module, put them in a () after the module.
NIC_MODULES=3c509 3c59x 8139cp 8139too e100 e1000 pcnet32 r8169 ne ne2k-pci forcedeth tulip via-rhine

#############################################################
#
# The list of stuff to build for the target filesystem
#
#############################################################

TARGETS+=uclibc

# Probably a good thing even if you choose not to patch anything.
# This target only unpacks. The linux target does the patching.
TARGETS+=patch-o-matic

# POM-patches to add:
# I could have used base but some of the patches has a problem.
# It's alot here, probably not so smart, cut back later.
POM_PATCHES=h323-conntrack-nat quake3-conntrack-nat connlimit dstlimit pptp-conntrack-nat directx8-conntrack-nat time cuseeme-nat rtsp-conntrack iprange random ipp2p mms-conntrack-nat connrate msnp-conntrack-nat nth sip-conntrack-nat set expire psd TARPIT

# After switching to a newer p-o-m;
# 
# Did not apply cleanly: dropped-table tproxy
#
# Did not compile cleanly: 
#   policy: (ipt_policy.c:15:22: net/xfrm.h: No such file or directory)
#
#   osf: (extensions/libipt_osf.c: In function `help':
#   extensions/libipt_osf.c:46: warning: too many arguments for format
#   extensions/libipt_osf.c: In function `parse':
#   extensions/libipt_osf.c:107: error: `IPT_OSF_CONNECTOR' undeclared (first use in this function)
#   extensions/libipt_osf.c:107: error: (Each undeclared identifier is reported only once
#   )
#
# Missing: string

# IPTABLES_MODULES: this is a result of the patches you have chosen above and
# also the included modules in the kernel (also check the kernel config.)
# This works the same way as NIC_MODULES.
# If you want options to the module, put them in a () after the module.
IPTABLES_MODULES=ip_conntrack arp_tables iptable_filter arptable_filter iptable_mangle ipt_state ipt_MASQUERADE ipt_SET ipt_DSCP ipt_REJECT ipt_DSCP ipt_ECN ipt_LOG ipt_MARK ipt_REDIRECT ipt_TCPMSS ipt_TOS ipt_ULOG ipt_conntrack ipt_connlimit ipt_dscp ipt_ecn ipt_helper ipt_length ipt_limit ipt_mac ipt_mark ipt_physdev ipt_pkttype ipt_tcpmss ipt_tos ipt_ttl ipt_unclean ip_conntrack_ftp ip_nat_ftp ip_conntrack_irc(ports=6666,6667,6668,7000) ip_nat_irc sch_htb ip_conntrack_h323 ip_conntrack_mms ip_nat_mms ip_conntrack_rtsp ip_conntrack_pptp ip_conntrack_quake3 ipt_iprange ipt_multiport ip_nat_proto_gre ipt_ipp2p ipt_time

#ipt_MIRROR 
#ip_queue 
#ipt_string 
#ip_nat_tftp
#ip_conntrack_tftp
#ip_nat_amanda
#ip_conntrack_amanda

TARGETS+=linux

TARGETS+=busybox
USE_BUSYBOX_SNAPSHOT=false

TARGETS+=iptables

TARGETS+=ipset

TARGETS+=iproute2

TARGETS+=dnsmasq

TARGETS+=bridgeutils

# TARGETS+=modutils

TARGETS+=pppd

TARGETS+=pppoe

TARGETS+=pcmcia

TARGETS+=wireless-tools

TARGETS+=dropbear

TARGETS+=ethtool

# This one will be installed in add.ffw, alas, the floppy base itself and
# not it's own package.
#TARGETS+=mii-diag

TARGETS+=e3

TARGETS+=noip2

TARGETS+=nanotop

TARGETS+=wsmenu

TARGETS+=lpd-p910nd

# TARGETS+=openntpd

# These needs to be tested.
TARGETS+=siproxd
TARGETS+=ucarp
TARGETS+=lineserv
TARGETS+=tcpdump
TARGETS+=madwifi
TARGETS+=muninlite
TARGETS+=micro_proxy
# TARGETS+=quagga

# The hostap target will add patches to the kernel and build a hostap.ffw
# package with hostapd, hostap-driver and wpa_supplicant and hostap-utils
# if you set it here.
# TARGETS+=hostap
# TARGETS+=hostap-utils

# Not yet
# TARGETS+=ebtables

# And at last:
TARGETS+=module-packages
TARGETS+=floppy

#############################################################
#
# You should probably leave this stuff alone unless you know 
# what you are doing.
#
#############################################################

TARGET_CFLAGS=$(TARGET_OPTIMIZATION) $(TARGET_DEBUGGING) $(TARGET_SOFT_FLOAT)
# TARGET_CC=distcc gcc
TARGET_CC=gcc
TARGET_CX=g++

HOSTCC:=distcc gcc
BASE_DIR:=${shell pwd}
SOURCE_DIR:=$(BASE_DIR)/sources
SCRIPTS_DIR:=$(BASE_DIR)/scripts
CONFIG_DIR:=$(BASE_DIR)/configs
LICENSES_DIR:=$(BASE_DIR)/licenses
MODULES_BASE_DIR:=$(BASE_DIR)/modules
MODULES_DIR:=$(MODULES_BASE_DIR)/2.4-std
DL_DIR:=$(BASE_DIR)/downloads
PATCH_DIR=$(BASE_DIR)/patches
PACKAGES_DIR=$(BASE_DIR)/packages
PACKAGES_INI_DIR=$(PACKAGES_DIR)/scripts
PACKAGES_SKELETON_DIR=$(PACKAGES_DIR)/skeleton
INITRD_DIR=$(BASE_DIR)/initrd
INITRD_MASTER=$(INITRD_DIR)/master
ADD_DIR=$(BASE_DIR)/add
ADD_MASTER=$(ADD_DIR)/master

TMP_DIR=$(BASE_DIR)/tmp

# Need another name maybe?
BUILD_DIR:=$(BASE_DIR)/build_$(ARCH)$(ARCH_FPU_SUFFIX)

TARFLAGS=--format oldgnu

#TAR_VERBOSE=--verbose
RM=rm -f

# This may be a problem to use but I'll try.
# --strip-unneeded
STRIP=strip --strip-unneeded -g --remove-section=.comment --remove-section=.note 
STRIP_KMOD=strip --strip-debug --remove-section=.comment --remove-section=.note
STRIP=$(STRIP_KMOD) --strip-unneeded

SSTRIP=$(shell command type sstrip >/dev/null 2>&1 && echo sstrip || echo $(STRIP))

#DEPMOD=(cd $(LINUX_DIR); \
#	/sbin/depmod -ae -F System.map -b $(MODULES_DIR) -r $(LINUX_VERSION))

DEPMOD=([ -d $(MODULES_DIR)/lib/modules/$(LINUX_VERSION) ] && \
	$(BASE_DIR)/perl/depmod.pl -n \
		-b $(MODULES_DIR)/lib/modules/$(LINUX_VERSION)/ \
		-k $(LINUX_DIR)/vmlinux \
		> $(LINUX_MODULES_DEP) )

# SED=/bin/sed -i -e
SED=/usr/bin/perl -p -i -e
LZMAD=lzmacat
LZMAC=lzmacomp
MAKE=/usr/bin/make $(JLEVEL)
HOST_ARCH:=$(shell $(HOSTCC) -dumpmachine | sed -e s'/-.*//' \
	-e 's/sparc.*/sparc/' \
	-e 's/arm.*/arm/g' \
	-e 's/m68k.*/m68k/' \
	-e 's/ppc/powerpc/g' \
	-e 's/v850.*/v850/g' \
	-e 's/sh[234]/sh/' \
	-e 's/mips-.*/mips/' \
	-e 's/mipsel-.*/mipsel/' \
	-e 's/cris.*/cris/' \
	-e 's/i[3-9]86/i386/' \
	)

GNU_HOST_NAME:=$(HOST_ARCH)-pc-linux-gnu

all:   world

TARGETS_CLEAN:=$(patsubst %,%-clean,$(TARGETS))
TARGETS_SOURCE:=$(patsubst %,%-source,$(TARGETS))
TARGETS_DIRCLEAN:=$(patsubst %,%-dirclean,$(TARGETS))

world: $(ADD_MASTER) $(INITRD_MASTER) $(DL_DIR) $(TMP_DIR) $(BUILD_DIR) $(PACKAGES_DIR) $(TARGETS)

.PHONY: all world clean dirclean distclean source $(TARGETS) \
	$(TARGETS_CLEAN) $(TARGETS_DIRCLEAN) $(TARGETS_SOURCE)

include makefiles/*.mk

#############################################################
#
# staging and target directories do NOT list these as 
# dependancies anywhere else
#
#############################################################
$(TMP_DIR):
	mkdir -p $(TMP_DIR)

$(DL_DIR):
	mkdir -p $(DL_DIR)

$(BUILD_DIR):
	mkdir -p $(BUILD_DIR)

$(PACKAGES_DIR):
	mkdir -p $(PACKAGES_DIR)

$(MODULES_BASE_DIR):
	mkdir -p $(MODULES_BASE_DIR)

$(MODULES_DIR):
	mkdir -p $(MODULES_DIR)

$(ADD_MASTER):
	cp -a $(ADD_DIR)/skeleton $(ADD_MASTER)
	-find $(ADD_MASTER) -type d -name CVS -exec $(RM) -r {} \; > /dev/null 2>&1
	-find $(ADD_MASTER) -type d -name .svn -exec $(RM) -r {} \; > /dev/null 2>&1

$(INITRD_MASTER):
	cp -a $(INITRD_DIR)/skeleton $(INITRD_MASTER)
	-find $(INITRD_MASTER) -type d -name CVS -exec $(RM) -r {} \; > /dev/null 2>&1
	-find $(INITRD_MASTER) -type d -name .svn -exec $(RM) -r {} \; > /dev/null 2>&1

source: $(TARGETS_SOURCE)

#############################################################
#
# Cleanup and misc junk
# 
# Fix later.. (yeah!)
#
#############################################################
clean: $(TARGETS_CLEAN)
	$(RM) -r $(INITRD_MASTER) $(ADD_MASTER) 

dirclean: $(TARGETS_DIRCLEAN)
	$(RM) -r $(INITRD_MASTER) $(ADD_MASTER) 

distclean:
	$(RM) -r $(DL_DIR) $(BUILD_DIR)

veryclean:
	$(RM) -r $(INITRD_MASTER) 
	$(RM) -r $(INITRD_DIR)/initrd.sq 
	$(RM) -r $(ADD_MASTER) 
	$(RM) $(ADD_DIR)/*.ffw $(ADD_DIR)/*.bz2
	$(RM) -r $(BUILD_DIR)
	$(RM) -r $(MODULES_BASE_DIR)
	# Should have the skeleton or packages somewhere else.
	$(RM) $(PACKAGES_DIR)/*.ffw $(PACKAGES_DIR)/*.bz2
	$(RM) -r isoimage*
	$(RM) -r soekris.tar.bz2
	$(RM) -r flash.tar.bz2
	# Dangerous..
	$(RM) -r floppy*

sourceball: 
	$(RM) -r $(BUILD_DIR)
	set -e; \
	cd ..; \
	$(RM) buildroot.tar.bz2; \
	tar -cvf buildroot.tar buildroot; \
	bzip2 -9 buildroot.tar

list-targets:
	@(echo "DIRS:"; \
		for t in $(TMP_DIR) $(DL_DIR) $(BUILD_DIR) \
		$(MODULES_BASE_DIR) $(MODULES_DIR) \
		$(ADD_MASTER) $(INITRD_MASTER) $(PACKAGES_DIR); do \
		echo -e "\t$$t"; \
	  done \
	)
	@echo "TARGETS:"
	@(for t in $(TARGETS); do \
		echo -e "\t$$t"; \
	  done \
	)
	@echo "TARGETS_SOURCE:"
	@(for t in $(TARGETS_SOURCE); do \
		echo -e "\t$$t"; \
	  done \
	)
	@echo "TARGETS_CLEAN:"
	@(for t in $(TARGETS_CLEAN); do \
		echo -e "\t$$t"; \
	  done \
	)
	@echo "TARGETS_DIRCLEAN:"
	@(for t in $(TARGETS_DIRCLEAN); do \
		echo -e "\t$$t"; \
	  done \
	)

