Scons Writing Solid Code 02.12.2008. Overview What is scons? scons Basics Other cools scons stuff Resources.

Slides:



Advertisements
Similar presentations
Makefile Ansuman Banerjee Arijit Bishnu Debapriyo Majumdar Data and File Structures Lab M.Tech. Computer Science 1 st Year, Semester I Indian Statistical.
Advertisements

The make Utility Programming Tools and Environments Winter 2006.
Separate compilation Large programs are generally separated into multiple files, e.g. tuples.h, ray.h, ray.c, tuples.c main.c With several files, we can.
The Makefile utility ABC – Chapter 11, Motivation Small programs single file “Not so small” programs : –Many lines of code –Multiple components.
David Notkin Autumn 2009 CSE303 Lecture 20 static make.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation Namespaces Simple Make Files (Ignore all class references.
The Makefile Utility ABC – Chapter 11, Motivation Small programs single file “Not so small” programs : –Many lines of code –Multiple components.
Unix Continuum of Tools Do something once: use the command line Do something many times: –Use an alias –Use a shell script Do something that is complex.
1 CS 201 Makefile Debzani Deb. 2 Remember this? 3 What is a Makefile? A Makefile is a collection of instructions that is used to compile your program.
26-Jun-15 Rake. rake and make A program can consist of many source code files This is always true in Rails! The files may need to be compiled in a certain.
Guide To UNIX Using Linux Third Edition
CS465 - Unix C Programming (cc/make and configuration control)
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
Building with MPC Charles Calkins Principal Software Engineer Object Computing, Inc.
Introduction to The Linaro Toolchain Embedded Processors Training Multicore Software Applications Literature Number: SPRPXXX 1.
1 Introduction to Tool chains. 2 Tool chain for the Sitara Family (but it is true for other ARM based devices as well) A tool chain is a collection of.
CS 11 C track: lecture 1 Preliminaries Need a CS cluster account cgi-bin/sysadmin/account_request.cgi Need to know UNIX ITS.
Introduction to C Programming. A Brief History u Created by Dennis Ritchie at AT&T Labs in 1972 u Originally created to design and support the Unix operating.
July 29, 2003Serguei Mokhov, 1 Makefile Brief Reference COMP 229, 346, 444, 5201 Revision 1.2 Date: July 18, 2004.
Programming Tools gcc make utility Open Source code Static and Shared Libraries gdb Memory debugging tools.
Introduction Use of makefiles to manage the build process Declarative, imperative and relational rules Environment variables, phony targets, automatic.
리눅스 : Lecture 5 UNIX 유틸리티 : text editor, compilation (make), …
GNU Compiler Collection (GCC) and GNU C compiler (gcc) tools used to compile programs in Linux.
Compiling & Debugging Quick tutorial. What is gcc? Gcc is the GNU Project C compiler A command-line program Gcc takes C source files as input Outputs.
Old Chapter 10: Programming Tools A Developer’s Candy Store.
Programming With C.
Introduction to C Programming CE Lecture 7 Compiler options and makefiles.
System Programming - LAB 1 Programming Environments.
C Tutorial - Program Organization CS Introduction to Operating Systems.
Built-in Data Structures in Python An Introduction.
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Test Specifications A Specification System for Multi-Platform Test Suite Configuration, Build, and Execution Greg Cooksey.
CS105 Computer Programming PYTHON (based on CS 11 Python track: lecture 1, CALTECH)
Copyright © 2015 Curt Hill Make An Indispensable Developer’s Tool.
CPS120: Introduction to Computer Science Compiling a C++ Program From The Command Line.
Makefiles CARYL RAHN. Separate compilation Large programs are generally separated into multiple files, e.g. main.c addmoney.c removemoney.c money.h With.
CSE 1341 Honors Note Set 2 1. Overview  Java vs. C++  Functions in C++  First Programming Packet  Development Environment 2.
Emacs, Compilation, and Makefile C151 Multi-User Operating Systems.
Multiple File Compilation and linking By Bhumik Sapara.
C code organization CSE 2451 Rong Shi. Topics C code organization Linking Header files Makefiles.
First Compilation Rudra Dutta CSC Spring 2007, Section 001.
Creating FunctionstMyn1 Creating Functions Function can be divided into two groups: –Internal (built in) functions –User-defined functions.
Program Libraries 1. What is a program library? A library is a collection of implementations of behavior, written in terms of a language, that has a well-defined.
Makefile Script file to automate program compilation and linking (making) 1. Write the "makefile" 2. Write your programs 3. Run "make" or "make -f makefile"
PROGRAMMING USING PYTHON LANGUAGE ASSIGNMENT 1. INSTALLATION OF RASPBERRY NOOB First prepare the SD card provided in the kit by loading an Operating System.
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Software development tools
Introduction to C Topics Compilation Using the gcc Compiler
CSE 303 Lecture 17 Makefiles reading: Programming in C Ch. 15
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha Fall 2015
Brief Intro to Make CST494/ Gannod.
Makefiles Caryl Rahn.
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to C Programming Language
Makefile Tutorial CIS5027 Prof: Dr. Shu-Ching Chen
Prof: Dr. Shu-Ching Chen TA: Yimin Yang
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Hector Cen Fall 2017
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Rake 4-Dec-18.
Introduction to C Topics Compilation Using the gcc Compiler
Creating your first C program
Introduction to C Topics Compilation Using the gcc Compiler
Lab 4: Introduction to Scripting
Compiler vs linker The compiler translates one .c file into a .o file
Debugging.
EN Software Carpentry Python – A Crash Course Esoteric Sections Compiled Languages.
SPL – PS1 Introduction to C++.
The make utility (original presentation courtesy of Alark Joshi)
Presentation transcript:

scons Writing Solid Code

Overview What is scons? scons Basics Other cools scons stuff Resources

What is scons? scons is a program for building software, similar to make. scons is written using the Python programming language.

Why use scons over make?

What is scons? scons syntax is Python syntax; thus it inherits the clarity and concise nature of the Python language. scons scripts are Python scripts; anything that can be done in a Python script can be done in an scons script, providing a powerful and flexible tool for building software. Building of executables is handled by scons, not the script itself; thus scons scripts are much more platform independent.

scons Basics

#include int main() { printf(“Hello, World!\n”); return 0; }

scons Basics hello: hello.c gcc -o hello hello.c clean: rm hello Makefile:

scons Basics SConstruct: Program(‘hello.c’) That’s it!

scons Basics cleaning  scons -c creating object files  Object(‘hello.c’) specifying executable names  Program(‘hello_new’,’hello.c’)

scons Basics Compiling multiple files into one executable  Program(‘hello’, [‘hello1.c’, ‘hello2.c’])  The filenames are given in a typical Python list

scons Basics Since multiple files are given as a list, there are other ways to make them easier to read: sources = Split(‘hello1.c hello2.c’) Program(‘hello’, sources) or: sources = Split(“””hello1.c hello2.c”””) Program(‘hello’, sources)

Other cool scons stuff Arguments can also be specified by name, as a feature of the Python language. This reduces confusion as to what each argument is: sources = Split(‘hello1.c hello2.c’) Program(target = ‘hello’, source = sources) sources = Split(‘hello1.c hello2.c’) Program(source = sources, target = ‘hello’) Is equivalent to the following:

Other cool scons stuff Libraries can be created using the Library function call, similar to Program. Shared Libraries (DLLs) can be created using the SharedLibrary function call. scons will automatically add the -shared flag on UNIX systems.

Other cool scons stuff Including a library is as simple as specifying them as arguments in the Program function call: Program(‘hello.c’, LIBS=[‘m’,’pthread’], LIBPATH=’.’) Note that library prefixes or suffixes do not have to be specified, as scons will automatically use the correct extension based on the system the software is being built. This would result in something like this being executed: cc -o hello -L. -lm -lpthread

Other cool scons stuff Both LIBS and LIBPATH can either be a Python list, or a single filename or path string, like the other arguments previously discussed.

Other cool scons stuff By default, scons does not rebuild a target unless the content of a source file has actually been changed. To explicitly specify this behavior, use the SourceSignatures function call: SourceSignatures(‘MD5’) SourceSignatures(‘timestamp’)

Other cool scons stuff The same thing may be applied to targets as well, using the TargetSignatures function call. By default, scons uses the ‘build’ value. Another value that may be passed to this function is ‘content’, which allows scons to determine if the target doesn’t need to be rebuilt even if the source content was changed.

Other cool scons stuff Another useful function is Ignore, which will cause scons to ignore the changes of a source or dependency when determining whether a target should be rebuilt: Program(‘hello.c’) Ignore(‘/usr/include/stdio.h’)

Other cool scons stuff If a target needs to always be built for whatever reason, the AlwaysBuild function can be used: hello = Program(‘hello.c’) AlwaysBuild(hello) Note that this is executed correctly even though AlwaysBuild comes after the Program call.

Other cool scons stuff scons will not necessarily execute build commands in the specified order, and it executes other commands in the script before actually building the targets. This allows for functionality like that of AlwaysBuild, which takes as an argument the return value of Program.

Other cool scons stuff scons also allows for multiple construction environments, using the Environment function: env1 = Environment(CC = ‘gcc’, CCFLAGS = ‘-O2’) env2 = Environment(CC = ‘cc’, CCFLAGS = [‘-Wall’, ‘-pedantic’]

Other cool scons stuff env1.Object(‘hello_1.o’, ‘hello.c’) env2.Object(‘hello_2.o’, ‘hello.c’) results in : gcc -o hello_1.o -c -O2 hello.c cc -o hello_2.o -c -Wall -pedantic hello.c being executed

Other cool scons stuff Environments can be copied, if one wants multiple environments that are slightly similar, using Environment.Clone: env1 = Environment(CC = ‘gcc’) env2 = Environment.Clone(CCFLAGS = [‘-Wall’, ‘-pedantic’]) env3 = Environment.Clone(CCFLAGS = [‘-Wall’, ‘-O2’]

Other cool scons stuff You can check command line targets with the following: if ‘test’ in COMMAND_LINE_TARGETS: print “You want test!” Variables may also be set like so: #scons -Q test=1 This value can be checked through the ARGUMENTS dictionary.

Other cool scons stuff test = ARGUMENTS.get(‘test’, 0) if int(test): print “This is a test.”

Other cool scons stuff Default targets can be set by using the Default function: hello1 = Program(‘hello.c’) Default(hello1) hello2 = Program(‘hello2’, ‘hello.c’) This will only build hello1 unless hello2 is given as a command line target. Calling Default multiple times, or calling it like so: Default(prog1, prog2) will append more targets to the default. This list can be accessed through the DEFAULT_TARGETS list.

Other cool scons stuff If, for some reason there is a need to have nothing made by default, simply pass the variable None into the Default function.

Resources scons User Guide, v user.html user.html