# Makefile - makefile to build the kernel shell
#
# Copyright (c) 2003-2007, 2009-2011, 2017-2018 Wind River Systems, Inc.
#
# The right to copy, distribute, modify or otherwise make use of this software
# may be licensed only pursuant to the terms of an applicable Wind River
# license agreement.
#
# modification history
# --------------------
# 02m,06jun18,lan  Break dependency between shell and object loader. (F9983)
# 02o,31may17,ljl  Added shellFuncExample.o (F8192)
# 02k,28sep11,rlp  Added  spyShellCmd.o module - CQID: WIND00285819.
# 02j,11may11,rlp  Added agentShellCmd object file.
# 02i,01apr11,jmp  Added tipShellCmd.o & wrloadShellCmd.o (CQ:WIND00144662).
# 02h,17dec10,pch  CQ:WIND00244631: build (only) ostool/shell/shellFuncBind
#		   for small footprint
# 02g,01oct10,jpb  Added dbgFuncBind.c
# 02g,10sep10,jmp  Ensure that C Interpreter Grammar/Lexer are generated on
#		   solaris.
# 02f,29mar10,jmp  No longer build RTP shell commands when _WRS_CONFIG_RTP is
#		   not defined by VSB.
# 02e,01jul09,jmp  Added shellFuncBind.c build.
# 02d,12jul07,v_r  Added shell history saving/loading facility (req
#		   CQ:WIND00005098).
# 02c,12jan06,zl   added mmanShellCmd
# 02b,29jul05,bpn  Moved rules to build shell commands doc to cmddoc/Makefile.
# 02a,09may05,bpn  Updated rule to build commands documentation.
# 01z,09mar05,asa  Added fppRegsLib.o to OBJS (SPR 105886)
# 01y,08nov04,bpn  Added rules to build commands documentation.
# 01x,30sep04,zl   added memory management library commands.
# 01w,29sep04,kk   added rtpShowShellCmd.c
# 01v,22sep04,bpn  Updated documentation. Added usrFsShellCmd.o, edrShellCmd.o,
#		   taskShellCmd.o, rtpShellCmd.o, shlShellCmd.o,
#		   moduleShellCmd.o and unloadShellCmd.o build.
# 01u,09sep04,bpn  Added dbgShellCmd.o and symShellCmd.o build.
# 01t,16jul04,bpn  Added completionLib.o build. Remove shellCompletionLib.c from
#		   the doc generation.
# 01s,04may04,pch  SPR 94932: add include of defs.library
# 01r,04may04,bpn  Added shellCmd.o build.
# 01q,04feb04,pch  PPC32 floating-point adjustments
# 01q,09feb04,bpn  Added shellCompletionLib.c to documentation.
# 01p,29oct03,bpn  Added shellConfigLib.o build.
# 01o,28oct03,bpn  Added shellDataLib.o build.
# 01n,21oct03,bpn  Removed shellInterpCGram.h generation.
# 01m,01oct03,bpn  Added shellWorkingCtxLib.o build.
# 01l,23sep03,bpn  Added shellPromptLib.o build.
# 01k,12aug03,bjl  fixed LIB_BASE_NAME for ppc.
# 01j,06aug03,pch  Add special case build for PPC floating point
# 01i,31jul03,pch  Add PPC32 support
# 01h,22jul03,bpn  Added the build of shellInterpCmd.o and of
#		   shellInterpCmdLib.o.
# 01g,08jul03,bpn  Added the build of shellCompletionLib.o.
# 01f,10jun03,bpn  Changed shellIntLib.c to shellInternalLib.c
# 01e,19may03,bpn  Added build of shellInterpLib.o
# 01d,10apr03,bpn  When creating the C lexer with flex, don't produce the
#		   default rule (-s flag).
# 01c,05mar03,bpn  Renamed shellDbgLib to dbgLib.
# 01b,26feb03,bpn  Added the build of shellDbgLib.o.
# 01a,24jan03,bpn  Created.
#
# DESCRIPTION
# This file contains the makefile rules for building the kernel shell component
#

TGT_DIR		= $(WIND_BASE)/target

LIB_BASE_NAME   = os

# Including defs.library to see if _WRS_CONFIG_xxx is defined.
# It must be after LIB_BASE_NAME
include $(TGT_DIR)/h/make/defs.library

ifneq ($(MAKECMDGOALS), man)
EXCLUDE_SUBDIRS	= cmddoc
endif

DOC_FILES	= shellLib.c dbgLib.c shellInterpLib.c \
		  ledLib.c shellInterpCmdLib.c shellPromptLib.c shellDataLib.c \
		  shellConfigLib.c

INTERNAL_DOC_FILES	= completionLib.c shellInternalLib.c shellMemLib.c \
			  shellInOutLib.c shellCompletionLib.c shellHistLib.c

# For now, it is necessary to generate C Interpreter Lexer & Grammar on solaris
# using the following Flex & Bison version. Using an incorrect version yields
# to many differences in the machine generated.

FLEX		= /wind/river/native/sun4-solaris2/bin/flex
BISON		= /wind/river/native/sun4-solaris2/bin/bison

OBJS	=	shellFuncBind.o shellFuncExample.o

# Except for shellFuncBind, the shell requires malloc() etc.
# and should not be built if they are not available.

ifndef _WRS_CONFIG_MEM_ALLOT
OBJS	+=	adrSpaceShellCmd.o	\
		completionLib.o		\
                dbgFuncBind.o		\
		dbgShellCmd.o		\
		edrShellCmd.o		\
		emacsLedLib.o		\
		fppRegsLib.o		\
		histShellCmd.o		\
		ledLib.o		\
		memEdrShellCmd.o	\
		mmanShowShellCmd.o	\
		sdShowShellCmd.o	\
		shellCmd.o		\
		shellCompletionLib.o	\
		shellConfigLib.o	\
		shellDataLib.o		\
		shellHistLib.o		\
		shellInOutLib.o		\
		shellInternalLib.o	\
		shellInterpC.o		\
		shellInterpCmd.o	\
		shellInterpCmdLib.o	\
		shellInterpLib.o	\
		shellLib.o		\
		shellMemLib.o		\
		shellPromptLib.o	\
		shellRemoteAccessLib.o	\
		shellWorkingCtxLib.o	\
		shlShellCmd.o		\
		spyShellCmd.o		\
		symShellCmd.o		\
		taskShellCmd.o		\
		usrFsShellCmd.o		\
		viLedLib.o		\
		vmShowShellCmd.o	\
		tipShellCmd.o		\
		agentShellCmd.o		\
		wrloadShellCmd.o

# Skip build of files providing RTP shell commands when _WRS_CONFIG_RTP is
# not defined by VSB.

 ifdef _WRS_CONFIG_RTP
    OBJS +=	rtpShellCmd.o		\
		rtpShowShellCmd.o	\
		memEdrRtpShellCmd.o
 endif

 ifdef _WRS_CONFIG_LOADER
 OBJS += moduleShellCmd.o \
         unloadShellCmd.o
 endif
 
# Suppress local build of dbgLib.o for all PPC as it is
# built in target/src/hwdb via a symlink
 ifneq ($(VX_CPU_FAMILY),ppc)
    OBJS += dbgLib.o
 endif
endif

ifdef   _WRS_CONFIG_COMPONENT_IPSSL
override ADDED_CFLAGS +=        -D_WRS_CONFIG_SSL
endif

ifdef PARSER
LOCAL_CLEAN	= shellInterpCGram.c shellInterpCLexer.c
endif
include $(TGT_DIR)/h/make/rules.library

$(LIBDIR)/shellInterpC.o : shellInterpCGram.c shellInterpC.h \
			   shellInterpCLexer.c shellInterpC.c

# To preempt the default rule
shellInterpC.c: shellInterpC.y
	@echo ""

shellInterpCGram.c : shellInterpC.y
ifdef PARSER
	- @ $(RM) $@
	@ echo ""
	@ echo "Generate C Interpreter Grammar..."
ifneq ($(WIND_HOST_TYPE),sun4-solaris2)
	@ echo "ERROR: C Interpreter Grammar must be generated on solaris!"
else
	${BISON} -l -p $(basename $<) -o $@ $<
endif
else
	@ echo "Warning: New C parser $<. Cannot regenerate file $@"
	@ echo "Checkout file $@, and build the shell with PARSER=1"
endif

shellInterpCLexer.c : shellInterpC.lex 
ifdef PARSER
	- @ $(RM) $@
	@ echo ""
	@ echo "Generate C Interpreter Lexer..."
ifneq ($(WIND_HOST_TYPE),sun4-solaris2)
	@ echo "ERROR: C Interpreter Lexer must be generated on solaris!"
else
	${FLEX} -s -B -8 -L -P$(basename $<) -o$@ $<
endif
else
	@ echo "Warning: New C lexer $<. Cannot regenerate file $@"
	@ echo "Checkout file $@, and build the shell with PARSER=1"
endif

clean-lex:
	$(RM) shellInterpCLexer.c

clean-yacc:
	$(RM) shellInterpCGram.c

clean-parser: clean-lex clean-yacc
