#-----------------------------------------------------------------------------
#Template Makefile for apps
#-----------------------------------------------------------------------------


#------- Comment/uncomment the following line to enable/disable debugging---------
DEBUG = n
#-----------------------------------------------------------------------------


#---------------------- Compute TOPDIR and include Rules file --------------------
ifndef TOPDIR
TOPDIR  := $(shell cd ../../../../..; pwd)
endif
include $(TOPDIR)/development/rules/Rules.make.apps



#-----------------------------------------------------------------------------
#If compiling using gcc............
#CC=gcc

# If IPMI has been included in the project......
LIBS += $(TOPDIR)/development/proprietary/firmware/libs/libipmi/src/local/libipmi.so
ifeq ($(SOC),PILOT_II)
LIBS += $(TOPDIR)/development/proprietary/firmware/libs/libmmap/libmmap.so
endif
#LIBS += $(TOPDIR)/development/firmware/libs/libi2c/libi2c.so
#LIBS += $(TOPDIR)/development/proprietary/firmware/libs/libami/libami.so
#LIBS += $(TOPDIR)/development/proprietary/firmware/libs/libuserm/porting/libuserm.so
#LIBS += $(TOPDIR)/development/oemprop/firmware/libs/libcmnipmi/libcmnipmi.so	//removed by vm
#LIBS += $(TOPDIR)/development/oem/firmware/libs/libipt/libipt.so	//removed by vm
#LIBS += $(TOPDIR)/development/proprietary/firmware/libs/libportcfg/libportcfg.so	//removed by vm
LIBS += $(TARGETDIR)/lib/libpam.so.0
#---------------------- Change according to your files ----------------------------
TARGET 		= smash

#put your own sources here
SRC 		 =  ./Source/SM_CLPParse.c 
SRC		+=  ./Source/SM_FIFO.c 
SRC		+=  ./Source/SM_hashfns.c 
SRC		+=  ./Source/SM_hashtable.c 
SRC		+=  ./Source/SM_iniparse.c 
SRC		+=  ./Source/SM_Initialize.c 
SRC		+=  ./Source/SM_lex.yy.c 
SRC		+=  ./Source/SM_main.c 
SRC		+=  ./Source/SM_parser.c 
SRC		+=  ./Source/SM_rexstr.c 
SRC		+=  ./Source/SM_TargetTree.c 
SRC		+=  ./Source/SM_Executer.c 
SRC		+=  ./Source/SM_OutputFormat.c 
SRC		+=  ./Source/solssh.c 
#SRC		+=  ./Source/SM_JOB_ID.c 
SRC		+=  ./Source/SM_FreeOutput.c
#SRC		+=  ./Source/SM_ErrorParse.c	//removed by vm
#added on 15th december........for addition of OEM commands.
#SRC		+=  ./Source/SM_OEMExecuter.c

#if IPMI has been included in the project....
SRC		+=  ./Source/SM_libipmi_interface.c
#SRC             +=  ./temp/console.c


SRC += ./Console/console.c
SRC += ./Console/history.c
SRC += ./Console/cmdline.c

# tftp clint support added..
#SRC		+=  ./Source/tftp.c
#SRC		+=  ./Source/ftp.c

#mapping support...
#SRC		+=  ./Source/SM_map.c

#Profiles Mapping Support
SRC		+=  ./Source/SM_MapProfiles.c

#put your own compilation options and flags here
CFLAGS += -Os
CFLAGS += -funsigned-bitfields
CFLAGS += -fno-strict-aliasing 
#CFLAGS += -DERRORCOND
CFLAGS += -g

#If IPMI has been included in the project....
CFLAGS += -I $(TOPDIR)/development/proprietary/firmware/apps/smash/Console
CFLAGS += -I $(TOPDIR)/development/proprietary/firmware/apps/smash/Include
CFLAGS += -I $(TARGETDIR)/usr/include
CFLAGS += -I$(TOPDIR)/development/oem/common/include/libipmi_inc_oem
CFLAGS += -I$(TOPDIR)/development/oemprop/firmware/libs/libcmnipmi/common/include/
CFLAGS += -I $(TOPDIR)/development/common/include/libipmi_inc
CFLAGS += -I $(TOPDIR)/development/common/include/ipmi_inc
CFLAGS += -I $(TOPDIR)/development/common/include/webifc
CFLAGS += -I $(TOPDIR)/development/common/include/flash
CFLAGS += -I $(TOPDIR)/development/common/include/fmh
CFLAGS += -I $(TOPDIR)/development/common/include/adviser
CFLAGS += -I $(TOPDIR)/development/common/include/activedir_cfg
CFLAGS += -I $(TOPDIR)/development/common/include/network
CFLAGS += -I $(TOPDIR)/development/oem/common/include/libipt
CFLAGS += -I $(TOPDIR)/development/common/include/racsessioninfo
CFLAGS += -I $(TOPDIR)/development/common/include/portcfg
# CFLAGS += -I$(TARGETDIR)/lib/libpam.so
#CFLAGS += -I$(TARGETDIR)/lib/libpam_misc.so



#---------------------------------------------------------------------------------

SUBDIRS  = .


#--------------WARNING : Donot Modify anything below this line ---------------------

all:   .depend $(TARGET) #subdirs # If your module exports symbols

#subdirs:
#	for n in $(SUBDIRS); do $(MAKE) -C $$n all  || exit 1; done

$(TARGET): $(SRC:.c=.o)
	$(CC) $(CFLAGS) $(LIBS) -lpthread -ldl -rdynamic $^ -o $@

depend .depend dep:
	$(CC) $(CFLAGS) -M  $(SRC) > $@

extrainstall:

install:  .depend all
	$(STRIP) $(TARGET)
	$(INSTALL) -d $(target_bindir)
	$(INSTALL) -d $(BINARYDIR)/usr/local/bin
	$(INSTALL) -d $(target_confdir)
	$(INSTALL) -d $(BINARYDIR)/conf
	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) $(TARGET) $(target_bindir)
	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) $(TARGET) $(BINARYDIR)/usr/local/bin
	chmod +s $(target_bindir)/$(TARGET)
	chmod +s $(BINARYDIR)/usr/local/bin/$(TARGET)
#	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) smashclp.bnf $(target_etcdir)
#	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) smashclp.bnf $(BINARYDIR)/etc
#	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) Commands.conf $(target_etcdir)
#	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) Commands.conf $(BINARYDIR)/etc
#	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) bmcipmb.ini $(target_confdir)
#	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) bmcipmb.ini $(BINARYDIR)/conf
#	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) bmclo.ini $(target_confdir)
#	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) bmclo.ini $(BINARYDIR)/conf
	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) bmc.ini $(target_confdir)/bmc.ini
	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) bmc.ini $(BINARYDIR)/conf/bmc.ini
	ln -sf ../conf/bmc.ini $(target_etcdir)/bmc.ini
	ln -sf ../conf/bmc.ini $(BINARYDIR)/etc/bmc.ini
#	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) SMASHTarget.map $(target_confdir)
#	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) SMASHTarget.map $(BINARYDIR)/conf
#	ln -sf ../conf/SMASHTarget.map $(target_etcdir)/SMASHTarget.map
#	ln -sf ../conf/SMASHTarget.map $(BINARYDIR)/etc/SMASHTarget.map
	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) CIM_NumericSensor.ini $(target_confdir)
	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) CIM_NumericSensor.ini $(BINARYDIR)/conf
	ln -sf ../conf/CIM_NumericSensor.ini $(target_etcdir)/CIM_NumericSensor.ini
	ln -sf ../conf/CIM_NumericSensor.ini $(BINARYDIR)/etc/CIM_NumericSensor.ini
#	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) CIM_ActiveDirectory.ini $(target_confdir)
#	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) CIM_ActiveDirectory.ini $(BINARYDIR)/conf
#	ln -sf ../conf/CIM_ActiveDirectory.ini $(target_etcdir)/CIM_ActiveDirectory.ini
#	ln -sf ../conf/CIM_ActiveDirectory.ini $(BINARYDIR)/etc/CIM_ActiveDirectory.ini
#	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) SM_OEM_TRG $(target_confdir)
#	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) SM_OEM_TRG $(BINARYDIR)/conf
#	ln -sf ../conf/SM_OEM_TRG $(target_etcdir)/SM_OEM_TRG
#	ln -sf ../conf/SM_OEM_TRG $(BINARYDIR)/etc/SM_OEM_TRG
#	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) SM_OEM_CMD $(target_confdir)
#	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) SM_OEM_CMD $(BINARYDIR)/conf
#	ln -sf ../conf/SM_OEM_CMD $(target_etcdir)/SM_OEM_CMD
#	ln -sf ../conf/SM_OEM_CMD $(BINARYDIR)/etc/SM_OEM_CMD
#	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) AD_SERV.ini $(target_confdir)
#	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) AD_SERV.ini $(BINARYDIR)/conf
#	ln -sf ../conf/AD_SERV.ini $(target_etcdir)/AD_SERV.ini
#	ln -sf ../conf/AD_SERV.ini $(BINARYDIR)/etc/AD_SERV.ini
	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) CIM_RecordLog.ini $(target_confdir)
	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) CIM_RecordLog.ini $(BINARYDIR)/conf
	ln -sf ../conf/CIM_RecordLog.ini $(target_etcdir)/CIM_RecordLog.ini
	ln -sf ../conf/CIM_RecordLog.ini $(BINARYDIR)/etc/CIM_RecordLog.ini
	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) CIM_LogRecord.ini $(target_confdir)
	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) CIM_LogRecord.ini $(BINARYDIR)/conf
	ln -sf ../conf/CIM_LogRecord.ini $(target_etcdir)/CIM_LogRecord.ini
	ln -sf ../conf/CIM_LogRecord.ini $(BINARYDIR)/etc/CIM_LogRecord.ini
	
	ln -sf ../var/smash.ini $(target_etcdir)/smash.ini
	ln -sf ../var/smash.ini $(BINARYDIR)/etc/smash.ini
#	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) OEM_Target/libOEMTestTarget.so $(target_libdir)
#	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) OEM_Target/libOEMTestTarget.so $(BINARYDIR)/usr/local/lib
#	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) OEM_Command/libOEMTestCommand.so $(target_libdir)
#	$(INSTALL) $(ONLY_IF_NEW) $(PRESERVE_SOURCE_TIMESTAMP) OEM_Command/libOEMTestCommand.so $(BINARYDIR)/usr/local/lib
#	for n in $(SUBDIRS); do $(MAKE) -C $$n install || exit 1; done
       	
clean:
	rm -f *.o *~ core .depend $(TARGET)
	rm -f *.o *~ core .depend 
	rm ./Source/*.o -f
	rm ./Console/*.o -f
#	for n in $(SUBDIRS); do $(MAKE) -C $$n clean; done
	

ifeq (.depend,$(wildcard .depend))
include .depend
endif
#----------------------------------------------------------------------------------------
