####################################################################
#                                                                  #
#       Makefile.kconf                                             #
#       Author : Sang Cheol Kim (ETRI), 2007                       #
#       Des : Makefile for Nano OS and Sensor Applications         #
#                                                                  #
#       Usage :                                                    #
#       % make lib              (create libnos.a)                  #
#       % make                  (create xxx.rom)                   #
#                                                                  #
#       To remove compliled files                                  #
#       % make clean            (delete xxx.rom in apps dir)       #
#                                                                  #
#       To generate kconf.h file                                   #
#       % make menuconfig                                          #
#                                                                  #
#       To see motelist,                                          #
#	% make motelist						   #
#                                                                  #
####################################################################

# kconfig Settings
# .config includes environment variables with a format of "CONFIG_XXX=y/n"
# ex) CONFIG_ETRI_SSN=y
# ex) CONFIG_ADC_M=y
# ex) CONFIG_RF_M=y
# export NOS_HOME=/cygdrive/c/nos-2.2.7

-include .config	
include $(NOS_HOME)/nos/platform/Makefile

	export MCU
	export PLATFORM

	export SRCDIR   = $(PWD)

## change this lines according to your project
ifneq ($(SRC),)
        export SRC     = $(SRC)
else
        export SRC     = $(wildcard *.c)
endif
        #ASRC   = $(basename $(wildcard *.asm)).asm # for assembler sources
        #export ASRC    = #kkk.asm

## if the number of source files is 1, the target name is from the source 
## else the target name is from the current directory name
ifeq ($(words $(SRC)), 1)
        export TRG     = $(basename $(SRC))
else
        PWDSL   = $(subst /, , $(shell pwd))
        export TRG     = $(word $(words $(PWDSL)), $(PWDSL))
endif

##	for kconfig
	srctree=$(NOS_HOME)
	export srctree

### define commanders
	CD		= cd
	RM		= rm -f 
	MV		= mv
	CP		= cp -f
	COMDIR		= $(NOS_HOME)/.tmp

all :
	make -C $(COMDIR) all
	$(CP) $(TRG).rom $(TRG).hex

lib : 
	make -C $(COMDIR) lib

warmup : kconf.h
	make -C $(COMDIR) warmup

clean : 
	$(RM) *.rom *.hex *.ihex *.lst *.map *.a *.e2s *.o *.elf
	make -C $(COMDIR) clean

print :
	make -C $(COMDIR) print

distclean : clean
	$(RM) .config* kconf.h

menuconfig :
	$(CD) $(NOS_HOME)/bin/src/kconfig; $(MAKE) $@
	$(NOS_HOME)/bin/mconf.exe $(NOS_HOME)/Kconfig

motelist :
	$(CD) $(NOS_HOME)/bin/src/motelist; $(MAKE) $@
	$(NOS_HOME)/bin/motelist.exe

# Definitions of MCU related variables and target
# this makefile defines
# CC, OBJCOPY, OBJDUMP, ISPEXE, "make burn port=<port_class>" 
ifneq ($(MCU),)
include $(NOS_HOME)/nos/arch/$(MCU)/Makefile
endif
