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.

Slides:



Advertisements
Similar presentations
Version Control System (Sub)Version Control (SVN).
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.
MT311 Tutorial Li Tak Sing( 李德成 ). Uploading your work You need to upload your work for tutorials and assignments at the following site:
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.
Software Language Levels Machine Language (Binary) Assembly Language –Assembler converts Assembly into machine High Level Languages (C, Perl, Shell)
ECE 353 WinAVR and C Debugging Tutorial By Adam Bailin ECE 353 Fall ‘06.
Customizing Word Microsoft Office Word 2007 Illustrated Complete.
Using the Visual Basic Editor Visual Basic for Applications 1.
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.
Computer Science 210 Computer Organization Modular Decomposition Making a Library Separate Compilation.
Lecture 8  make. Overview: Development process  Creation of source files (.c,.h,.cpp)  Compilation (e.g. *.c  *.o) and linking  Running and testing.
1 ENG236: ENG236: C++ Programming Environment (2) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY.
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.
Chapter 2 Build Your First Project A Step-by-Step Approach 2 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
1 Integrated Development Environment Building Your First Project (A Step-By-Step Approach)
Xin Liu Sep 16, Introduction Xin (Shane) Liu PhD Candidate in Computer Science Research Area: Computer Graphics Tutorial Page: pages.cpsc.ucalgary.ca/~liuxin/CPSC453.
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.
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.
Program documentation Using the Doxygen tool Program documentation1.
Old Chapter 10: Programming Tools A Developer’s Candy Store.
Chapter Ten g++ and make1 System Programming Software Development: g++ and make.
System Programming - LAB 1 Programming Environments.
C Tutorial - Program Organization CS Introduction to Operating Systems.
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).
Makefiles. Multiple Source Files (1) u Obviously, large programs are not going to be contained within single files. u C provides several techniques to.
Data Display Debugger (DDD)
Using Visual Studio C++ Express Ron Gross A current copy of this can be found at or this direct linkhttp://tinyurl.com/2ucarothis.
Tools – Ant-MakeEtc 1 CSCE 747 Fall 2013 CSCE 747 Software Testing and Quality Assurance Tools 12 – Hamcrest 10/02/
Makefiles CARYL RAHN. Separate compilation Large programs are generally separated into multiple files, e.g. main.c addmoney.c removemoney.c money.h With.
Yannick Patois - Datagrid Software Repository Presentation - March, n° 1 Datagrid Software Repository Presentation CVS, packages and automatic.
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.
Emacs, Compilation, and Makefile C151 Multi-User Operating Systems.
Problem Solving With C++ Recitation – make February 2016.
Multiple File Compilation and linking By Bhumik Sapara.
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:
Object Oriented Programming COP3330 / CGS5409.  Compiling with g++  Using Makefiles  Debugging.
GNU Make Computer Organization II 1 © McQuain What is make ? make is a system utility for managing the build process (compilation/linking/etc).
Chapter 2 Build Your First Project A Step-by-Step Approach 2 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
Makefiles Manolis Koubarakis Data Structures and Programming Techniques 1.
Multiple file project management & Makefile
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha Fall 2015
Computer Science 210 Computer Organization
Compilation and Debugging
Compilation and Debugging
Makefiles.
Agenda Make Utility Command Line Arguments in Unix
SCMP Special Topic: Software Development Spring 2017 James Skon
Computer Science 210 Computer Organization
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
Makefiles and Notes on Programming Assignment PA2
1. Open Visual Studio 2008.
Computer Science 210 Computer Organization
Data Structures and Programming Techniques
SCMP Software Development Spring 2018 James Skon
Appendix F C Programming Environment on UNIX Systems
GNU Make.
Makefiles and the make utility
Makefiles, GDB, Valgrind
Makefile Assignment Create a file called f1.cpp. It should contain the following function: int squareIt ( int x ) { //insert code to calc and return the.
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

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 together to form winword.exe.  You make a change to one of these.c files and now need to rebuild word.exe.  How do you do it without having to recompile hundreds of.c files that haven’t changed?

w/out makefiles g++ -o word.exe f1.c f2.c f3.c f4.c … f999.c But only f4.c has changed and only needs to be recompiled! Compiler option to create intermediate (object modules) files: g++ -c f1.c g++ -c f2.c … g++ -c f999.c g++ -o word.exe f1.o f2.o f3.o … f999.o Then I just manually do: g++ -c f4.c and then relink.

But how can I automatically determine only what needs to be recompiled?  Write a program that looks at the modification time of the.c file and the.o (or.exe) file. If the mod time of the.c file is more recent than the mod time of the.o (or.exe) file, then we know that we know that we need to recompile and relink.  But I don’t want to write this program! (Someone already built this into the Java compiler, and MS Visual Studio.)

makefiles Consist of: 1.Comments (begin with #) 2.Definitions 3.Dependencies 4.Commands

makefiles Consist of: 1.Comments (begin with #) 2.Definitions 3.Dependencies 4.Commands  Comments: # # this is a comment. #

makefiles Consist of: 1.Comments (begin with #) 2.Definitions 3.Dependencies 4.Commands  Definitions (are like constants): CC = g++ -g or CC = g++ -O3 …  to use these definitions, evaluate with $(CC)

3. Dependencies a: b c d …  This means that a is dependent upon (needs) b and c and d …  What is word.exe dependent upon (below)?  g++ -o word.exe f1.o f2.o f3.o … f999.o  word.exe is dependent upon f1.o, f2.o, …, f999.o word.exe: f1.o f2.o … f999.o  What is f1.o dependent upon?

Dependencies & 4. Commands  Usually, a dependency is followed by a command to rebuild/recreate/update the entity to the left of the colon (called a tag).  Dependencies are hierarchical (i.e., top-down). word.exe: f1.o f2.o … f999.o g++ -o word.exe f1.o f2.o … f999.o g++ -o word.exe f1.o f2.o … f999.o f1.o: f1.c g++ -c f1.c g++ -c f1.c f2.o: f2.c g++ -c f2.c g++ -c f2.c…

makefile syntax target1 target2 target3 : prerequisite1 prerequisite2 <tab>command1<tab>command2<tab>command3 1. One or more targets (to the left of the colon). 2. Zero or more prereqs (after the colon). 3. Zero or more commands (each must be preceeded by a tab).

“Standard phony” targets  all Perform all tasks to build the application  install Create an installation of the application from the compiled binaries  clean Delete the binary files generated from sources  distclean Delete all the generated files that were not in the original source distribution  TAGS Create a tags table for use by editors  info Create GNU info files from their Texinfo sources  check Run any tests associated with this application  docsCreate (doxygen) documentation. (gjg)

Example (including definitions and comments) #for debug version: CC = g++ -g #for production version: #CC = g++ -O3 word.exe: f1.o f2.o … f999.o $(CC) -o word.exe f1.o f2.o … f999.o $(CC) -o word.exe f1.o f2.o … f999.o f1.o: f1.c $(CC) -c f1.c $(CC) -c f1.c…

Example (more than 1 command) #for debug version: CC = g++ -g word.exe:f1.o f2.o … f999.o echo link word.exe $(CC) -o word.exe f1.o f2.o … f999.o f1.o:f1.c echo compile f1.c $(CC) -c f1.c …

Example (make more than one) #for debug version: CC = g++ -g all:word.exe fred.exe … word.exe:f1.o f2.o … f999.o echo link word.exe $(CC) -o word.exe f1.o f2.o … f999.o f1.o:f1.c echo compile f1.c $(CC) -c f1.c …

Example make commands  make  Checks the first dependency that appears in the file makefile.  make all  Checks the all dependency in makefile.  make word.exe  make f1.o  make fred.exe  make –f myMakeFile all  Checks the all dependency in file myMakeFile.

Assignment 1. Create a file called f1.cpp. It should contain the following function: int squareIt ( int x ) { //insert code to calc and return the square of x } 2. Create a file called f2.cpp. It should contain the following function: int cubeIt ( int x ) { //insert code to calc and return the cube of x }

Assignment (cont’d.) 3. Create a main program in a file called main.cpp #include #include extern int squareIt ( int x ); extern int cubeIt ( int x ); int main ( int argc, char* argv[] ) { …}

Assignment (cont’d.)  Main should ask the user to enter a number. Main should then call the two functions, add up the values, and then print out this sum.  Main should repeat the above 3 times.  Get this to compile, link, and run.

Assignment (cont’d.)  Then create a makefile which should only recompile and relink only when changes are made.  The makefile should also contain a tag called clean. Whenever the user types make clean, this tag should simply delete all.o and.exe files. See the man page for rm. If no.o or.exe files are present, make clean should not report any errors.

Assignment (cont’d.)  Fully document each C/C++ file and each function with doxygen.