TOP:=$(abspath ../..)
-include $(TOP)/common.mk

FTP_MKLI:=$(FTP_BASE)/linux/linux-2.6/kernel
BASENAME:=mklinuximg

.PHONY: download unpack upgrade preconfig postconfig build clean
.PHONY: pre_postconfig cfg_save cfg_load xconfig gconfig menuconfig checkdir

default: build

# Find Latest Linux dist from Gaisler FTP server
download:
	@$(SCRIPTS)/download.sh $(FTP_MKLI) $(PWD)/reference $(BASENAME)

# Install latest Linux distribution in reference directory, make sure
# to do download target first...
install:
# Stop if package already installed.
	@if [ -f reference/CURRENT.$(BASENAME) ]; then \
	 if diff -q reference/CURRENT.$(BASENAME) reference/LATEST.$(BASENAME) > /dev/null; then \
	  echo ; \
	  echo "!!! Latest mklinuximg package already installed" ; \
	  echo ; \
	  exit 0 ; \
	  fi; \
	 fi; \
	 $(SCRIPTS)/unpack.sh $(PWD)/reference $(PWD) $(BASENAME) || exit 1; \
	 echo INSTALLING...; \
	 newname=`sed -n -e 's/^NAME=//gp' reference/LATEST.$(BASENAME)`; \
	 echo NEWNAME=$$newname ; \
	 rm -f $(BASENAME); \
	 ln -s $(BASENAME)-$$newname $(BASENAME); \
	 mv reference/LATEST.$(BASENAME) reference/CURRENT.$(BASENAME); \
	 if [ -f $(BASENAME)/pkg/install.sh ]; then \
	  sh $(BASENAME)/pkg/install.sh; \
	  fi; \
	 cd $(BASENAME)/pkg; make install;

upgrade: download install

checkdir:
	@if [ ! -L $(BASENAME) ]; then \
	 echo ;\
	 echo "!!! mklinuximg is not installed" ; \
	 echo ; \
	 exit 1; \
	 fi;	

xconfig:

gconfig:

menuconfig:

preconfig: checkdir
	cd $(BASENAME)/pkg; make preconfig

pre_postconfig: checkdir
	cd $(BASENAME)/pkg; make pre_postconfig

postconfig: checkdir
	cd $(BASENAME)/pkg; make postconfig

clean: checkdir
	cd $(BASENAME)/pkg; make clean

cfg_save:

cfg_load:

# Wrap in the Linux RAM Image using the LEON Linux Loader (the "wrapper") into
# a runnable Linux Image for RAM. GRMON or MKPROM can boot this image.
build: checkdir
	cd $(BASENAME)/pkg; make build
