Build Tools 1. Building a program for a large project is usually managed by a build tool that controls the various steps involved. These steps may include:

Slides:



Advertisements
Similar presentations
Makefiles. makefiles Problem: You are working on one part of a large programming project (e. g., MS Word).  It consists of hundreds of individual.c files.
Advertisements

Lecture 3 Getting Started with ITK!. Goals for this lecture Learn how to use Cmake Build ITK Example programs that use ITK.
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.
ANT: Another Nice Tool Ali Beyad October 1, 2003.
Understanding Makefiles COMP 2400, Fall 2008 Prof. Chris GauthierDickey.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation Namespaces Simple Make Files (Ignore all class references.
1 Ant – Another Neat Tool Representation and Management of Data on the Internet.
CS 501 : An Introduction to SCM & GForge An Introduction to SCM & GForge Lin Guo
Low level CASE: Source Code Management. Source Code Management  Also known as Configuration Management  Source Code Managers are tools that: –Archive.
Guide To UNIX Using Linux Third Edition
CS465 - Unix C Programming (cc/make and configuration control)
1 Building. 2 Goals of this Lecture Help you learn about: The build process for multi-file programs Partial builds of multi-file programs make, a popular.
G++ and make Dan Wilson CS193 02/01/06. The g++ Compiler What happens when you call g++ to build your program? Phase 1, Compilation:.cpp files are compiled.
Source Code Management Or Configuration Management: How I learned to Stop Worrying and Hate My Co-workers Less.
1 CMPT 275 Software Engineering Revision Control.
Automating the Build Process using ANT SE-2030 Dr. Mark L. Hornick 1.
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.
Introduction to ant Guy Rixon AstroGrid Consortium Meeting
Version Control with Subversion. What is Version Control Good For? Maintaining project/file history - so you don’t have to worry about it Managing collaboration.
CCA Port, Component & Application Build Skeleton Templates “A new script toolkit for generating CCA build skeletons” Torsten Wilde and James Kohl Oak Ridge.
Sumedha Rubasinghe October,2009 Introduction to Programming Tools.
Unix Makefiles COP 3330 Lecture Notes Dr. David A. Gaitros.
Introduction to Version Control
Automating the Build Process using Ant SE-2030 Dr. Rob Hasker 1 Based on material by Dr. Mark L. Hornick.
1 Lecture 19 Configuration Management Software Engineering.
Makefiles. makefiles Problem: You are working on one part of a large programming project (e. g., MS Word).  It consists of hundreds of individual.cpp.
Introduction Use of makefiles to manage the build process Declarative, imperative and relational rules Environment variables, phony targets, automatic.
Ant Build Tools.  Creating a product from source may take several steps: Compile Link Copy files to various directories Remove intermediate files Generate.
Version control Using Git Version control, using Git1.
Old Chapter 10: Programming Tools A Developer’s Candy Store.
Scons Writing Solid Code Overview What is scons? scons Basics Other cools scons stuff Resources.
Introduction to C Programming CE Lecture 7 Compiler options and makefiles.
July 2011CMSC 341 CVS/Ant 1 CMSC 341 Java Packages Ant CVS Project Submission.
Copyright © 2015 – Curt Hill Version Control Systems Why use? What systems? What functions?
CMake refactoring P. Hristov 19/03/2014. History I  Recursive makefiles (F.Carminati):  Problems in dependencies  Slow  "Recursive Makefiles.
Introduction Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Makefiles. Multiple Source Files (1) u Obviously, large programs are not going to be contained within single files. u C provides several techniques to.
Software Development COMP220/COMP285 Seb Coope Introducing Ant These slides are mainly based on “Java Development with Ant” - E. Hatcher & S.Loughran.
Chapter 1 Introducing Ant. What is ant? Ant is a build tool  Automate the tasks of compiling code, running test, and packaging the results for redistribution.
Linux development Lection What we gonna do today Root privileges Software packages Managing software packages Build procedures Build components.
Multiple File Compilation and linking By Bhumik Sapara.
SPI NIGHTLIES Alex Hodgkins. SPI nightlies  Build and test various software projects each night  Provide a nightlies summary page that displays all.
How to configure, build and install Trilinos November 2, :30-9:30 a.m. Jim Willenbring.
Object Oriented Programming COP3330 / CGS5409.  Compiling with g++  Using Makefiles  Debugging.
TEAM FOUNDATION VERSION CONTROL AN OVERVIEW AND WALKTHROUGH By: Michael Mallar.
Brandon Packard. Why make? So far, you have probably worked on relatively small projects Coding projects can become huge My research consists of 1600.
Wed Mar Michael Imamura / The GNU Autotools Your very own./configure.
Source Control Repositories for Enabling Team Working Doncho Minkov Telerik Corporation
CLHEP Infrastructure Improvements CHEP 2004 Lynn Garren, FNAL and Andreas Pfeiffer, CERN.
DIGITAL REPOSITORIES CGDD Job Description… Senior Tools Programmer – pulled August 4 th, 2011 from Gamasutra.
Software development tools
Build and Test system for FairRoot
Compilation and Debugging
Compilation and Debugging
Large Program Management: Make; Ant
LCGAA nightlies infrastructure
Large Program Management: Make; Ant
Makefiles and the make utility
Large Program Management: Make; Ant
JENKINS TIPS Ideas for making your life with Jenkins easier
Overview Unit testing Building Version control.
Large Program Management: Make; Ant
Large Program Management: Make; Ant
Large Program Management: Make; Ant
Carthage ios 8 onwards Dependency manager that streamlines the process of integrating the libraries into the project.
Makefiles and the make utility
CSE 390 Lecture 8 Large Program Management: Make; Ant
Large Program Management: Make; Ant
Presentation transcript:

Build Tools 1

Building a program for a large project is usually managed by a build tool that controls the various steps involved. These steps may include: 1.Compiling source code to binaries 2.Linking to binaries or libraries 3.Running software tests 4.Creating different build targets 5.Generating documentation 2

Build Tools There are a number of different build automation tools available. Make Automake CMake Apache Ant 3

Make The make utility is a commonly used build tool that can manage the process of building and rebuilding a project. Make was originally written in 1976 by Stuart Feldman, who received the 2003 ACM Software System award for his work. – For MAKE – there is probably no large software system in the world today that has not been processed by a version or offspring of MAKE. 4

Make Make is similar to a declarative programming language in that it describes the conditions for certain command but not the order in which they should be executed. This can sometimes cause confusion for programmers who are used to imperative programming. 5

Make A makefile consists of a set of rules. Each of these rules has a textual dependency line which defines the target of the rule as well as a optional set of dependencies: target: depenency1 command1 command2 6

Make Example – manual compilation: main.cpp class1.cpp class2.cpp $ g++ main.cpp class1.cpp class2.cpp –o main $./main Manually compile all files using gcc from the command line. 7

Make Example – simple makefile: all: g++ main.cpp class1.cpp class2.cpp –o main $ g++ main.cpp class1.cpp class2.cpp –o main $./main Makefile with a single (default) target that compiles all the files. 8

Make Example – Makefile with dependencies all: main main: main.o class1.o class2.o g++ main.o class1.o class2.o –o main main.o: main.cpp g++ -c main.cpp class1.o: g++ -c class1.cpp class2.o: g++ -c class2.cpp Makefile that considers each file and dependencies and recompiles only if necessary. 9

Make Example – Makefile with clean clean: rm –rf *o main $ make clean $ make $./main Makefiles often contain a clean target that can be used to completely clean the project of all compiled files and completely rebuild from scratch. 10

Make Example – Makefile using Macros # Comment – Selecting g++ as the compiler CC=g++ all: main main: main.o class1.o class2.o $(CC) main.o class1.o class2.o –o main main.o: main.cpp $(CC) -c main.cpp... Macros can be used in Makefiles to easily switch between different options and avoid rewriting large sections. 11

Make The problem with writing makefiles like this is that they can require a lot of work to set up and maintain them. Each object file has its own rule and set of dependencies that must be updated. Another option is to use wildcards and Generic Rules. 12

Make Example – Makefile - Macros and Generic rules. # Comment – Selecting g++ as the compiler CC=g++ SOURCES=$(wildcard *.cpp) OBJECTS=$(SOURCES:.cpp=.o) all: main main: $(OBJECTS) $(CC) $(OBJECTS) –o main.cpp.o: $(CC) –c $< -o 13

Make This makefile is an improvement. The generic rules for generating object files from source files allows us to add/remove source files without changing the makefile. However, it doesn't take into account any dependencies based on header files. 14

Make Example – Makefile # Comment – Selecting g++ as the compiler CC=g++ SOURCES=$(wildcard *.cpp) HEADERS=$(wildcard *.h) OBJECTS=$(SOURCES:.cpp=.o) all: main main: $(OBJECTS) $(CC) $(OBJECTS) –o main %.o: %.cpp $(HEADERS) $(CC) –c $< -o 15

Make This makefile now ensures that header files are included in the dependencies but also included every header file as a dependency for every object file. Any change to any header file will cause the entire project to be recompiled. 16

Make Rather than this all-inclusive approach for dependencies, most C compilers can generate a set of dependencies for you using the '-M' flag. This can be included into a makefile using -include 17

Make Example – Makefile # Comment – Selecting g++ as the compiler CC=g++ SOURCES=$(wildcard *.cpp) HEADERS=$(wildcard *.h) OBJECTS=$(SOURCES:.cpp=.o) DEPS =$(SOURCES:.cpp=.d) all: main main: $(OBJECTS) $(CC) $(OBJECTS) –o main %.o: %.cpp $(CC) –c $*.cpp -o $*.o $(CC) –M $*.cpp –o $*.d -include $(DEPS) 18

Make This makefile generates a.d file for each.cpp file that contains the dependency rule for that.cpp file. This.d file is then included into the makefile with all of the dependency information for that file. If the.cpp file or any of the dependencies change, the.o file will be recompiled and will generate a new dependency file. 19

Make This allows us to write a makefile that will only recompile files that actually need to be recompiled (to ensure fast compile times) but also uses generic rules so we don't need to keep maintaining the makefile. 20

Make For more information see: 21

Make Make doesn't support cross-platform compilation directly but it can be supported to some degree by platform-specific conditionals in the Makefile. ifeq($(OS), Windows) LIBS=-lopengl.dll else ifeq($(OS), MAC) LIBS=-framework OpenGL else ifeq($(OS), UBUNTU) LIBS=-lopengl endif 22

Automake Automake is a higher-level language that allows the programmer to avoid manually writing makefiles. For most simple cases it it enough to give the name of the program, a list of source files and a list of compile/link options. From this Automake can generate a makefile for your project. 23

Automake Automake is a part of a set of tools called The Autotools. These tools can automate some of the process of writing a Unix build system. This provides the user with a set of instructions:./configure make make install 24

Automake To generate makefiles with autotools, we write two files: Makefile.am: bin_PROGRAMS = main main_SOURCES = main.cpp class1.cpp class2.cpp configure.ac: AC_INIT([ammain], [1.0]) AM_INIT_AUTOMAKE AC_PROG_CXX AC_PROG_RANLIB AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([Makefile]) AC_OUTPUT 25

Automake To generate makefiles with autotools, we write two files: $ aclocal $ autoheader $ autoconf $ automake --add-missing This process generates the configure script and makefile for the project. 26

Automake The project can then be built using: $./configure $ make To build the project on a different system, simply re-run configure and then make the project. 27

Automake To generate and link to libraries: Makefile.am: noinst_LIBRARIES = libclass1.a libclass2.a libclass1_SOURCES = class1.cpp libclass2_SOURCES = class2.cpp bin_PROGRAMS = main main_SOURCES = main.cpp main_LDADD = libclass1.a libclass2.a 28

Automake For more information on Automake: 29

CMake CMake is the cross-platform, open-source build system designed to control the software compilation using platform and compiler independent configuration files. This tool automatically generates build scripts for different operating systems - Visual Studio projects for Windows and makefiles for Unix/Linux. 30

CMake CMake generates build scripts from files named: CMakeLists.txt These files must be put in each subdirectory of the project as required. 31

CMake Example – Simple CMake cmake_minimum_required(VERSION 2.6) project(Main) add_executable(Main main.cpp class1.cpp class2.cpp) $ cmake. -- The C compiler identification is Clang The CXX compiler identification is Clang Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info – done... 32

CMake Example – Simple CMake $ make Scanning dependencies of target Main [ 33%] Building CXX object CMakeFiles/Main.dir/main.cpp.o [ 66%] Building CXX object CMakeFiles/Main.dir/class1.cpp.o [100%] Building CXX object CMakeFiles/Main.dir/class2.cpp.o Linking CXX executable Main [100%] Built target Main 33

CMake Rather than giving CMake explicit commands for how to compile your program. Instead you give instructions of what you want it to build. 34

CMake Example – CMake with separate libraries cmake_minimum_required(VERSION 2.6) project(Main) add_library(class1 class1.cpp) add_library(class2 class2.cpp) add_executable(Main main.cpp) target_link_libraries(Main class1 class2) 35

CMake Example – CMake with separate directories./main.cpp./CMakeLists.txt class1/class1.h class1/class1.cpp class1/CMakeLists.txt class2/class2.h class2/class2.cpp class2/CMakeLists.txt 36

CMake Example – CMake with separate directories class1/CMakeLists.txt add_library(class1 class1.cpp) class2/CMakeLists.txt add_library(class2 class2.cpp)./CMakeLists.txt project(Main) include_directories("${Main_SOURCE_DIR}/class1") include_directories("${Main_SOURCE_DIR}/class2") add_subdirectory(class1) add_subdirectory(class2) add_executable(Main main.cpp) target_link_libraries(Main class1 class2) 37

CMake CMake will generate makefiles for each of the different directories along with the necessary code to: 1.Build each subdirectory 2.Include files from the subdirectories 3.Link binaries together 38

CMake CMake has support for finding packages and including/linking to them. This cross-platform support covers packages that have different names and methods of including/linking on different operating systems. 39

CMake Example – CMake with packages project(Main) add_executable(Main main.cpp) find_package(OpenGL) include_directories(${OpenGL_INCLUDE_DIRS}) target_link_libraries(Main ${OpenGL_LIBRARIES) 40

CMake For more information on CMake: 41

Apache Ant Apache Ant is a Java library for building large projects. It is used mainly for building Java Applications but does also have support for other languages such as C or C++. The build of a project is defined by an XML file called build.xml 42

Apache Ant Structure of build.xml: 43

Advanced Build Automation As projects become larger and more complex, more advanced build tools have been required to manage working with such large projects. Automation of the build process extends beyond simply managing the compiling and linking of a program. 44

Advanced Build Automation Distributed build automation is still largely a compilation/linking feature that farms out the compilation of different parts of the program to multiple locations or cores. 45

Advanced Build Automation An advanced build tool will not only build the project but can perform a series of tasks and tests to catch problems early on. Scheduled builds – Many projects have scheduled, (eg nightly) builds where the current version of the project is compiled each night and run through code tests to pick up any errors. Prevents errors in the code from propagating. 46

Advanced Build Automation Triggered builds – Some projects may be triggered to be rebuilt each time any developer commits new code. Can immediately catch problems before they become part of the project. 47

Version Control This type of build automation usually assumes the use of a version control system. Version control allows multiple developers to work on the same project at the same time. CVS - Concurrent Versions System SVN – Subversion Git 48

Version Control Trunk - A set of source code, resources etc making up a project. Basically the project. Branch - A branch splits from the trunk at some point in time, can be edited and updated separately. Used to try out ideas. Merging – A successful branch can be merged back into the trunk. 49

Version Control Check out – Creates a local copy of the project (specific to a trunk or branch) from the repository. Commit – Send your changes to the repository, creates a 'new version' of the project. 50

Version Control Version control software such as SVN is built using the client-server model where each client connects to a server that 'owns' the software repository. The server is responsible for accepting commits, it may 'lock' certain parts of the project etc. 51

Version Control Git is an example of a distributed version control system. Each user maintains a local copy which counts as a repository itself. Every user 'owns' the project as much as any other user or server. Changes can be pushed/pulled from any other copy of the project repository. 52