logo

abstract class

build::BuildCs

sys::Obj
  build::BuildScript
    build::BuildCs
//
// Copyright (c) 2006, Brian Frank and Andy Frank
// Licensed under the Academic Free License version 3.0
//
// History:
//   10 Jan 06  Brian Frank  Creation
//

**
** BuildCs is the base class for build scripts used to manage
** building C# source code into a .NET exe or dll.
**
abstract class BuildCs : BuildScript
{

//////////////////////////////////////////////////////////////////////////
// Pod Meta-Data
//////////////////////////////////////////////////////////////////////////

  **
  ** Required output file created by the compiler.
  **
  File output := null

  **
  ** Required output type. Possible values are 'exe',
  ** 'winexe', 'library' or 'module'.
  **
  Str targetType := null

  **
  ** Required list of directories to compile.  All C# source
  ** files in each directory will be compiled.
  **
  File[] dirs := null

  **
  ** List of libraries to link to.
  **
  File[] libs := null

//////////////////////////////////////////////////////////////////////////
// Setup
//////////////////////////////////////////////////////////////////////////

  **
  ** Validate subclass constructor setup required meta-data.
  **
  internal override Void validate()
  {
    ok := true
    ok &= validateReqField("output")
    ok &= validateReqField("targetType")
    ok &= validateReqField("dirs")
    if (!ok) throw FatalBuildErr.make
  }

//////////////////////////////////////////////////////////////////////////
// BuildScript
//////////////////////////////////////////////////////////////////////////

  **
  ** Default target is `compile`.
  **
  override Target defaultTarget() { return target("compile") }

//////////////////////////////////////////////////////////////////////////
// Compile
//////////////////////////////////////////////////////////////////////////

  @target="compile C# source into exe or dll"
  Void compile()
  {
    if (!isWindows)
    {
      log.info("skipping [${scriptDir.name}]")
      return
    }

    log.info("compile [${scriptDir.name}]")
    log.indent

    // compile source
    csc := CompileCs.make(this)
    csc.output = output
    csc.targetType = targetType
    csc.src  = dirs
    csc.libs = libs
    csc.run

    log.unindent
  }

//////////////////////////////////////////////////////////////////////////
// Clean
//////////////////////////////////////////////////////////////////////////

  @target="delete all intermediate and target files"
  Void clean()
  {
    log.info("clean [${scriptDir.name}]")
    log.indent
    Delete.make(this, output).run
    log.unindent
  }

//////////////////////////////////////////////////////////////////////////
// Full
//////////////////////////////////////////////////////////////////////////

  @target= "clean+compile"
  Void full()
  {
    clean
    compile
  }
}