www.pudn.com > Firewall_PNE_3_3.zip > knlAddPrj.tcl, change:2009-03-16,size:8608b


# knlAddPrj.tcl - tcl script to add a wmb project to a Tornado Project
#
# Copyright 2004, Wind River Systems, Inc.
#
# modification history
# --------------------
# 01e,16mar06,tlu  updated the version of web-cli version to 4.5
# 01d,02jun05,zhu  removed the dependency on WM_BASE
# 01c,12may05,zhu  updated for vxWork 6.1 and workbench
# 01b,12may04,jws  put "common" include at end of flags
# 01a,18feb04,jws  written
#
# DESCRIPTION
#
# This is a template script for adding wmb projects to an existing
# Tornado project.  Usually that project would be a kernel.  The script is run
# from the directory in which you have created a WMIT project.  The
# script modifies the "default" build spec of the target project by adding
# include paths.  It then adds source files to the project.
#
# One argument is needed by the script; the name of the target .wpj file.
#
# To run this script, you must be in a Tornado command line
# environment, usually established by running "torVars" in a
# Tornado installation or view.  A sample invocation is:
#
# wtxtcl knlAddPrj.tcl ../aKnl/aKnl.wpj
#
# The file readme.txt, in this directory, contains more information
# about this, and other, scripts.
#


proc itMightBeAFile line {
    upvar $line lineread
    set lineread [string trim $lineread]
    if { [string length $lineread] == 0 }  { return 0 }
    if { [string index $lineread 0] == "#" }  { return 0 }

    return 1
}


# One argument is required.

if {$argc != 1} {
	puts "Argument must be <kernel_project_file>"
	exit 1
	}



# source some tcl libraries

# package require OsConfig

source [wtxPath host resource tcl OsConfig]cmpScriptLib.tcl
source [wtxPath host resource tcl OsConfig]Utils.tcl
#source [wtxPath host resource tcl app-config Project]WorkspaceDoc.tcl

###############################################################################
#
# cmpBuildFlagsAddAfter - add flags to the build
#
# This routine is just a quick way to append to the build macros
# CFLAGS and CFLAGS_AS. It could also be acheived using
# cmpBuildMacro[GS]et
#
# PARAMETERS
#    flags : flags to add to CFLAGS and CFLAGS_AS
# 
# RETURNS: N/A
#

proc cmpBuildFlagsAddAfter flags {
    global cmpProjHandle
    set hProj $cmpProjHandle
    set build [prjBuildCurrentGet $hProj]

    set tc [prjBuildTcGet $hProj $build]
    set cc [${tc}::toolFindByFile foo.c]
    set as [${tc}::toolFindByFile foo.s]

    set cflags   "[prjBuildFlagsGet $hProj $build $cc] $flags"
    set asflags  "[prjBuildFlagsGet $hProj $build $as] $flags"

    prjBuildFlagsSet $hProj $build $cc  $cflags
    prjBuildFlagsSet $hProj $build $as  $asflags
}


# set CPU [lindex $argv 0]
# set TOOL [lindex $argv 1]

set projFile [lindex $argv 0]

# import WIND_HOME

set windHome $env(WIND_HOME)

# Determine where WindManage stuff is.

if {[info exists env(WM_BASE)]} {
    set wmBase $env(WM_BASE)
} else {
    set wmBase $windHome/components/webcli-4.5
}

# Set the project base.  Oddly enough, if we don't use the full
# pathname, the generated Makefile can have problems.

set projBase [pwd]

# The project directory will be in $projBase.  Note that this is the
# WMIT project dirctory, NOT the kernel project directory!
#
# For this version of things, the project base directory is the same as the
# project directory and projBase is not necessary, but we will
# leave it, for now.

set projDir $projBase

# Read info from .rcp file.  The result is that prjType is a string
# consisting of any combination of "c" (CLI), "m" (Mibway), and "w"
# (Web).  The construction of this string is done for historical reasons.
# dirSrc and dirHdr contain the (DOS! format) pathnames to
# source and header directories input to WMIT.  For these pathnames,
# the trailing "\" has been removed.

set prjType ""
set dirSrc  ""
set dirHdr  ""

set chan [open $projDir/[file tail $projDir].rcp]

# Crude, but functional, parsing using regular expressions.

while { [gets $chan lineread] >= 0 } {
    if { [regexp {blade.+type="([^"]*)"} "$lineread" regMatch regSub1] } {
        if { $regSub1 == "RCW" } { append prjType "w" }
        if { $regSub1 == "RCCLI" } { append prjType "c" }
        if { $regSub1 == "RCM" } { append prjType "m" }
}
     if { [regexp {dirC="([^"]*)\\"} "$lineread" regMatch regSub1] } {
#       puts "$regSub1"
        set dirSrc $regSub1
}
     if { [regexp {dirH="([^"]*)\\"} "$lineread" regMatch regSub1] } {
#       puts "$regSub1"
        set dirHdr $regSub1
}
}

close $chan

# If we do not use a full pathname for projFile, strange things
# can happen when computing dependencies!

cmpProjOpen $projFile

cmpBuildSpecSet default


# ----- Now we customize the project -----

set ourBase $projDir

# Add include directories for WindManage.

# The "common" path must be after the bsp directory.  This covers
# up the fact that common contains a file named config.h.

cmpBuildFlagsAddAfter -I$wmBase/target/h/wrn/wm/common

cmpBuildFlagsAdd -I$wmBase/target/h/wrn/wm/backplane
cmpBuildFlagsAdd -I$wmBase/target/h/wrn/wm/wmm
cmpBuildFlagsAdd -I$wmBase/target/h/wrn/wm/cli
cmpBuildFlagsAdd -I$wmBase/target/h/wrn/wm/http
cmpBuildFlagsAdd -I$wmBase/target/h/wrn/wm/common/zlib/vxWorks
# cmpBuildFlagsAdd -I$wmBase/target/h/wrn/em

cmpBuildFlagsAdd -I$wmBase/target/h


# These next are project specific and must match the directories
# specified to WMIT.

# This turns "\" to "/" in the headers pathname.  We then turn this
# into an absolute pathname so that the project manipulating tcl
# scripts can turn it back to a relative pathname, if possible!

regsub -all {\\} $dirHdr {/} dirHdr

cd $dirHdr
set dirHdr [pwd]
cd $projDir

puts "Adding include directory $dirHdr"
cmpBuildFlagsAdd -I$dirHdr


# Add any sources files we need starting with WindManage stuff
# Exactly what we need is project specific.

set wmSrcPath $wmBase/target/src/wrn/wm

# First, files that everybody needs in the common and
# backplane directories.  This includes the zlib files.

set chan [open $wmSrcPath/common/project.files]

while { [gets $chan lineread] >= 0 } {
    if { [itMightBeAFile lineread] } { cmpFileAdd $wmSrcPath/$lineread }
}

close $chan


# Now, mibway project related files, if necessary.  Always pull the
# snmp files from WIND_BASE.

if { [string first m $prjType] != -1 } {

puts "Including Mibway files..."

# cmpBuildFlagsAdd -I$wmBase/target/h/wrn/wm/snmp/engine

set chan [open $wmSrcPath/wmm/project.files]

while { [gets $chan lineread] >= 0 } {
    if { [itMightBeAFile lineread] } { cmpFileAdd $wmSrcPath/$lineread }
}

close $chan

}

# Now, cli project related files, if necessary.

if { [string first c $prjType] != -1 } {

puts "Including CLI files..."

set chan [open $wmSrcPath/cli/project.files]

while { [gets $chan lineread] >= 0 } {
    if { [itMightBeAFile lineread] } { cmpFileAdd $wmSrcPath/$lineread }
}

close $chan

}

# Now, web project related files, if necessary.

if { [string first w $prjType] != -1 } {

puts "Including WEB files..."

set chan [open $wmSrcPath/http/project.files]

while { [gets $chan lineread] >= 0 } {
    if { [itMightBeAFile lineread] } { cmpFileAdd $wmSrcPath/$lineread }
}

close $chan

}

# Now add the WMIT created and other project specific files.
# The locations of some of these files are set in WMIT.
# The exact files are project specific.

# Do the same stuff as for the header pathname.

regsub -all {\\} $dirSrc {/} dirSrc
# puts $dirSrc

cd $dirSrc
set fileSrcPath [pwd]
cd $projDir

set ourSourceFiles [glob $fileSrcPath/*.c]
foreach srcFile $ourSourceFiles {
    puts "adding $srcFile to project"
    cmpFileAdd $srcFile
}

# Finally, extra user source files, if any.  In order to avoid
# later problems, we want to pass an absolute pathname to
# cmpFileAdd.

if { [file readable $projDir/custom.files] } {

puts "Including extra user files..."

set chan [open $projDir/custom.files]

while { [gets $chan lineread] >= 0 } {

    # Clean up the input and check for comments and empty lines.

#    set lineread [string trim $lineread]
#    if { [string length $lineread] == 0 }  { continue }
#    if { [string index $lineread 0] == "#" }  { continue }

     if { ![itMightBeAFile lineread] } { continue }

    # Now, glob, then process

    set files [glob $lineread]

    foreach aFile $files {
        if { [file pathtype $aFile] != "absolute" } {
            set aFile $projDir/$aFile
        }
        if { [file isdirectory $aFile] } {
            cmpBuildFlagsAdd -I$aFile
            puts "adding $aFile to include path"
        } else {
            cmpFileAdd $aFile
            puts "adding $aFile to project"
        }
    }
}

close $chan

}

cmpProjClose