Makefiles CISC/QCSE 810. BeamApp and Tests in C++ 5 source code files After any modification, changed source needs to be recompiled all object files need.

Slides:



Advertisements
Similar presentations
Compiling. Your C, C++ or Fortran program won’t work unless you compile it The compiler will build your program as an executable file (typically in the.
Advertisements

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.
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.
Understanding Makefiles COMP 2400, Fall 2008 Prof. Chris GauthierDickey.
Compilation & linkage.h read.h.c read.c.c main.c.c list.c.h list.h prog1 Linkage: g++ read.o main.o list.o –o prog1.o main.o.o list.o.o read.o Compilation:
1 The Makefile Utility ABC – Chapter 11,
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.
The Makefile Utility ABC – Chapter 11, Motivation Small programs single file “Not so small” programs : –Many lines of code –Multiple components.
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.
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.
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.
CIS*2450 Seminar I Makefiles Debugging/Design Approaches Exception Handling Library Revision Control Designed by: Terry Moreland Updated by: Tom Crabtree.
Programming Tools gcc make utility Open Source code Static and Shared Libraries gdb Memory debugging tools.
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.
August 7, 2003Serguei A. Mokhov, 1 gcc Tutorial COMP 444/5201 Revision 1.1 Date: January 25, 2004.
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.
Adv. UNIX: large/131 Advanced UNIX v Objectives of these slides: –learn how to write/manage large programs consisting of multiple files, which.
Old Chapter 10: Programming Tools A Developer’s Candy Store.
Running ORGANON in R Peter Gould and David Marshall Growth Model User Group December 9, 2011.
Chapter Ten g++ and make1 System Programming Software Development: g++ and make.
Installing CompuCell3D from source Maciej Swat Biocomplexity Institute, Indiana University.
Makefile M.A Doman. Compiling multiple objects Card.cpp -> Card.o Deck.cpp -> Deck.o main.cpp -> main.o main.o Deck.o Card.o -> Dealer.exe.
GNU Make Computer Organization II 1 © McQuain What is make ? make is a system utility for managing the build process (compilation/linking/etc).
The Make utility. Motivation Small programs all in single cpp file “Not so small” programs : Many lines of code Multiple components More than one programmer.
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.
Using Visual Studio C++ Express Ron Gross A current copy of this can be found at or this direct linkhttp://tinyurl.com/2ucarothis.
Makefiles CARYL RAHN. Separate compilation Large programs are generally separated into multiple files, e.g. main.c addmoney.c removemoney.c money.h With.
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 all linked.
Problem Solving With C++ Recitation – make February 2016.
C code organization CSE 2451 Rong Shi. Topics C code organization Linking Header files Makefiles.
Slide 1 Running NEMO at ECMWF Slide 1 NEMO under Perforce at ECMWF Kristian S. Mogensen Last revised:
CSI605 Introduction to make. Advantages of Make Significantly reduces the amount of time spent compiling a program. Insures that programs are compiled.
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:
Advanced UNIX progamming Fall 2002 Instructor: Ashok Srinivasan Lecture 2 Class web site:
CSc 352 An Introduction to make Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
GNU Make Computer Organization II 1 © McQuain What is make ? make is a system utility for managing the build process (compilation/linking/etc).
Wed Mar Michael Imamura / The GNU Autotools Your very own./configure.
Visual Programming Borland Delphi. Developing Applications Borland Delphi is an object-oriented, visual programming environment to develop 32-bit applications.
Building programs LinuxChix-KE. What happens in your CPU? ● It executes a small set of instructions called "machine code" ● Each instruction is just a.
Makefiles CSSE 332 Operating Systems
The make utility (original presentation courtesy of Alark Joshi)
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha Fall 2015
Brief Intro to Make CST494/ Gannod.
Compilation and Debugging
Compilation and Debugging
Makefiles.
Makefiles Caryl Rahn.
SCMP Special Topic: Software Development Spring 2017 James Skon
Editor, Compiler, Linker, Debugger, Makefiles
Makefile Tutorial CIS5027 Prof: Dr. Shu-Ching Chen
What is make? make is a system utility for managing the build process (compilation/linking/etc). There are various versions of make; these notes discuss.
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
Makefiles and the make utility
Getting Started: Developing Code with Cloud9
CMPSC 60: Week 4 Discussion
Kyle Fitzpatrick Konstantin Zak 11/29/2004
SCMP Software Development Spring 2018 James Skon
Build Tools (make) CSE 333 Autumn 2018
Appendix F C Programming Environment on UNIX Systems
Preparation for Assignment 2
Makefiles and the make utility
Debugging.
Makefiles, GDB, Valgrind
SCMP Software Development Spring 2018 James Skon
What is make? make is a system utility for managing the build process (compilation/linking/etc). There are various versions of make; these notes discuss.
Presentation transcript:

Makefiles CISC/QCSE 810

BeamApp and Tests in C++ 5 source code files After any modification, changed source needs to be recompiled all object files need to be relinked Changing debug, profiling settings all source needs to be recompiled, relinked

At command line # Compile all source g++ -c *.cpp # try to link all objects g++ *.o –o BeamApp

Obvious limitations Have to manually type in flags Will recompile everything every time Tries to include all objects in one big program have multiple "main" functions each program needs only some objects

Makefiles Some of the earlier problems can be worked around with directories, organizing files Simply better, though, to use some version of 'make' with a 'makefile' "A makefile is a collection of instructions that should be used to compile your program."

Non-obvious advantage Makefiles make it easier for you to recompile your code They also make it easier for others to recompile your code Build process for many libraries is  download and unzip ./configure  make  make test  make install If you ever want to package up C, C++, Fortran, include a makefile

Using make Some things we would like our makefile to handle make BeamApp make clean make solver_Test make all make install Also, change compiler flags for debug, optimization, and profiling

Makefile structure - variables Variable definitions CFLAGS= -g # compiler flags CC=gcc # set C compiler name CPP=g++ # set C++ compiler name

Makefile structure - rules Rules are of the form :  commands Note at the start of each command line BeamApp: BeamApp.o solver.o Beam.o $(CPP) $(LFLAGS) BeamApp.o solver.o Beam.o \ –o BeamApp BeamApp.o: BeamApp.cpp $(CPP) –c $(CFLAGS) BeamApp.cpp

Common rules Many object compilations follow the same basic rule form: BeamApp.o: BeamApp.cpp $(CPP) –c $(CFLAGS) BeamApp.cpp Makefiles can do this everytime with pattern rules: %.o : %.cpp $(CPP) -c $(CFLAGS) $< -o (Also see old-fashioned 'pattern rules' in some makefiles)

Make clean Customary target for make deletes any object files, executables, in preparation for a completely 'clean' rebuild clean: rm *.o *.exe Sometimes has error message; see more sophisticated ways on web Ensure it is not first in make file 'make' on its own triggers first target in makefile

Rule order make uses explicit rules, if present, over general rules BeamApp.o is in makefile, so it compiles it according to specific instruction Only other object files, without explicit targets, are compiled using %.o rule Order does matter in some cases, so be wary true for any rule-based system with potential conflicts

Make solver_Test solver_Test: solver.o solver_Test.o $(CPP) $(LFLAGS) solver.o solver_Test.o -o solver_Test; If we want to run the test as part of the build, solver_Test: solver.o solver_Test.o $(CPP) $(LFLAGS) solver.o solver_Test.o -o solver_Test;./solver_Test For test routines, might want to force rebuild: add dependency on 'clean'

Make all Common target 'all' usually builds all related programs or libraries all: BeamApp solver_Test

Compiler Options -Wall – all warnings -g – debug (so program works with gdb or other debugger) -O# - optimize the code (free speed!) -O3 most common for final production code Takes longer to compile Can introduce errors! Solution? Nothing magical; best improvements are better code -pg – include profiler information

Make install Often, if you have a program or library you're rebuilding, you need to move the final product elsewhere MATLAB library path bin directory for executables 'make install' is usually used for this install: BeamApp cp BeamApp ~/bin

Setting Variables Can change variables in makefile, then recompile CFLAGS=-g -Wall Can also override makefile variables at command line make CFLAGS=-O3 all or export CFLAGS=-O2 make –e all

Make Variants Some variants include: CMake, by Kitware Jam, by Perforce Qmake, by Trolltech Main benefits are portability between OSes, compilers automation of makefile creation

Resources Gnu makefile conventions and style Conventions.html