Site hosted by Angelfire.com: Build your free website today!

Skip's Linux Home Page
Brought to you by Skip using CityDeskTM from Fog Creek Software

SCons Examples

By Skip
Created: Monday, September 22, 2003, 11:32:09 MST
Last updated: Monday, October 20, 2003, 08:45:05 MST
Changes: Removed extra headers.


Example 1

SConstruct

# This is a comment
env = Environment()   # Create an environmnet
env.Program(target = "helloworld", source = ["helloworld.c"])

 

Example 2

SConstruct

# This is a comment

env = Environment()   # Create an environmnet

lib_target  = "hello"
lib_sources = ["libhello.c"]

libhello = env.SharedLibrary(target = lib_target, source = lib_sources)
hello = env.Program(source = ["helloworld.c"], target = "helloworld")
myhello = env.Program(source = ["myhello.c","libhello.so"], target = "myhello")

env.Install(dir = "Build", source = hello)
env.Install(dir = "Build", source = myhello)
env.Install(dir = "Build", source = libhello)
env.Alias('install', ['Build'])

 

Example 3

SConstruct

# Comment
print "I'm SConstruct"

# Builder src.out
src_outBldr = Builder(action='cp $SOURCES $TARGET',
		suffix='.out',
		src_suffix='.src')

# Scanner src

env = Environment() # Initialize the environment
env.Append(BUILDERS = {'MyOutBuilder' : src_outBldr})

# Specify a target
print "Here are some targets."

print "hw: hw.c"
hw = env.Program('hw','hw.c')
env.Install('Build',hw)

print "hw2: hw2.cc"
hw2 = env.Program('hw2','hw2.cc')
env.Install('Build',hw2)

print "foo.out: foo.src"
foo = env.MyOutBuilder(target='foo',source=['foo.src'])
env.Install('Build',foo)

env.Alias('install',['Build'])

print "Done specifying targets."

print "Done with SConstruct file"

 

Source files

Example 1: helloworld.c


#include <stdio.h>

int main() {
  printf("Hello World.");
}

Example 2: helloworld.c


#include <stdio.h>

int main() {
  printf("Hello World.");
}

Example 2: libhello.c


#include <stdio.h>

void printHello() 
{
  printf("Hello World");
}

Example 2: myhello.c



extern void printHello();

int main (void)
{
   printHello();
   return 0;
}


Example 3: foo.src


# This is the source file


Example 3: hw.c


#include <stdio.h>

int main (void)
{
   fprintf(stdout,"I'm alive!\n\tHello world!\n");
   return 0;
}

Example 3: hw2.cc


#include <iostream>

class MyWorld
{
   public:
      MyWorld();
      ~MyWorld();

      int print();
};

MyWorld::MyWorld()
{
   // do nothing
}

MyWorld::~MyWorld()
{
   // do nothing
}

int
MyWorld::print()
{
   std::cout << "Ahhh... Hello world!\n";
   return 0;
}

int main (void)
{
   MyWorld mw;

   return mw.print();
}

Home

Made with CityDesk