#  Makefile
#
#  LUNAR - Lightweight Underlay Network Ad hoc Routing
#
#  Makefile for building Intel and ARM versions of the kernel
#  module lunar.o (2.4.x) and lunar.ko (2.6.x)
#
#  Copyright (C) 2004 Per Svensson
#
#  2005-04-15 cft: added support for mips and uml
#
#  This file is distributed under the terms of the GNU general Public
#  License (GPL), see the file COPYING


## We find out what kernel is running
ifndef KERNELVERSION
KERNELVERSION := $(shell uname -r)
endif
KERNELBASE    := $(basename $(KERNELVERSION))
KERNELMAJOR   := $(basename $(KERNELBASE))
KERNELMINOR   := $(suffix $(KERNELBASE))
OLD_KERNEL    := $(strip $(foreach V, .0 .1 .2 .3 .4, $(shell [ "$(V)" = "$(KERNELMINOR)" ] && echo yes)))

all:
	@echo "usage: make { arm | intel | mips | uml }"


modules:
        ifeq ($(KERNELMAJOR),2)

          ifeq ($(OLD_KERNEL),yes)
		$(MAKE) -C lnx -f Makefile-24
          else
		$(MAKE) -C lnx
          endif

        else
		@echo "Kernel version not supported"
        endif


arm:
	@echo
	@echo "** Compiling LUNAR (release date "`awk '/^#define LUNAR_RELEASE/ { gsub("\"","",$$3); printf $$3;}' < include/version.h`"), arch is ARM"
	@echo
	$(MAKE) clean
	$(MAKE) -C lnx -f Makefile-arm


intel:
        ifneq ($(KERNELMAJOR),$(basename $(KERNELMAJOR)))
	$(MAKE) intel KERNELVERSION=$(KERNELBASE)
        else
	@echo
	@echo "** Compiling LUNAR (release date "`awk '/^#define LUNAR_RELEASE/ { gsub("\"","",$$3); printf $$3;}' < include/version.h`")"
	@echo "**           for Linux kernel "$(KERNELVERSION)", arch is INTEL"
	@echo
	$(MAKE) modules
        endif


mipsel:
	@echo
	@echo "** Compiling LUNAR (release date "`awk '/^#define LUNAR_RELEASE/ { gsub("\"","",$$3); printf $$3;}' < include/version.h`"), arch is MIPSEL"
	@echo
	$(MAKE) clean
	$(MAKE) -C lnx -f Makefile-mipsel


uml:
        ifneq ($(KERNELMAJOR),$(basename $(KERNELMAJOR)))
	$(MAKE) uml KERNELVERSION=$(KERNELBASE)
        else
	@echo
	@echo "** Compiling LUNAR (release date "`awk '/^#define LUNAR_RELEASE/ { gsub("\"","",$$3); printf $$3;}' < include/version.h`")"
	@echo "**           for Linux kernel "$(KERNELVERSION)", arch is User Mode Linux (UML)"
	@echo
	$(MAKE) modules ARCH=um
        endif

clean:
	rm -f *~ include/*~ src/*~ ns2/*~ ns2/*.o
	$(MAKE) -C lnx clean

# eof
