CSE 303 Lecture 17 Makefiles reading: Programming in C Ch. 15

Slides:



Advertisements
Similar presentations
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.
Advertisements

Makefiles  Provide a way for separate compilation.  Describe the dependencies among the project files.  The make utility.
David Notkin Autumn 2009 CSE303 Lecture 20 static make.
Understanding Makefiles COMP 2400, Fall 2008 Prof. Chris GauthierDickey.
1 CSE 390 Lecture 8 Large Program Management: Make; Ant slides created by Marty Stepp, modified by Josh Goodwin
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.
Basic linux shell commands and Makefiles. Log on to engsoft.rutgers.edu Open SSH Secure Shell – Quick Connect Hostname: engsoft.rutgers.edu Username/password:
CS465 - Unix C Programming (cc/make and configuration control)
Lecture 8  make. Overview: Development process  Creation of source files (.c,.h,.cpp)  Compilation (e.g. *.c  *.o) and linking  Running and testing.
Enabling the ARM Learning in INDIA ARM DEVELOPMENT TOOL SETUP.
July 29, 2003Serguei Mokhov, 1 Makefile Brief Reference COMP 229, 346, 444, 5201 Revision 1.2 Date: July 18, 2004.
Jump to first page (C) 1998, Arun Lakhotia 1 Software Configuration Management: Build Control Arun Lakhotia University of Southwestern Louisiana Po Box.
Scons Writing Solid Code Overview What is scons? scons Basics Other cools scons stuff Resources.
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.
1 CSE 390 Lecture 8 Large Program Management: Make; Ant slides created by Marty Stepp, modified by Jessica Miller and Ruth Anderson
CSE 251 Dr. Charles B. Owen Programming in C1 Compilation and Makefiles.
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.
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015 Makefile Tutorial CIS5027.
Lecture 8  make. Using make for compilation  With medium to large software projects containing many files, it’s difficult to: Type commands to compile.
Emacs, Compilation, and Makefile C151 Multi-User Operating Systems.
Problem Solving With C++ Recitation – make February 2016.
C code organization CSE 2451 Rong Shi. Topics C code organization Linking Header files Makefiles.
Brandon Packard. Why make? So far, you have probably worked on relatively small projects Coding projects can become huge My research consists of 1600.
CSc 352 An Introduction to make Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 14 – Makefiles and Compilation Management.
UNIX Development: g++ and make CS 2204 Class meeting 8 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
Makefiles Manolis Koubarakis Data Structures and Programming Techniques 1.
Multiple file project management & Makefile
The make utility (original presentation courtesy of Alark Joshi)
Large Program Management: Make; Ant
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha Fall 2015
CSE 374 Programming Concepts & Tools
C – Multi-file development and make
Brief Intro to Make CST494/ Gannod.
Large Program Management: Make; Ant
Makefiles Caryl Rahn.
SCMP Special Topic: Software Development Spring 2017 James Skon
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
Large Program Management: Make; Ant
Large Program Management: Make; Ant
Makefiles and the make utility
Large Program Management: Make; Ant
Makefiles and Notes on Programming Assignment PA2
Rake 4-Dec-18.
Data Structures and Programming Techniques
CSE 390 Lecture 8 Large Program Management: Make; Ant
CMPSC 60: Week 4 Discussion
CMSC 202 Additional Lecture – Makefiles
Large Program Management: Make; Ant
SCMP Software Development Spring 2018 James Skon
Large Program Management: Make; Ant
Build Tools (make) CSE 333 Autumn 2018
Large Program Management: Make; Ant
Large Program Management: Make; Ant
Large Program Management: Make; Ant
CSc 352 An Introduction to make
Makefiles and the make utility
Compiler vs linker The compiler translates one .c file into a .o file
Build Management EE 461L Based on materials from Christine Julien, Miryung Kim and Adnan Aziz.
Makefiles, GDB, Valgrind
CSE 390 Lecture 8 Large Program Management: Make; Ant
SCMP Software Development Spring 2018 James Skon
Large Program Management: Make; Ant
The make utility (original presentation courtesy of Alark Joshi)
Large Program Management: Make, Ant
Presentation transcript:

CSE 303 Lecture 17 Makefiles reading: Programming in C Ch. 15 slides created by Marty Stepp http://www.cs.washington.edu/303/

The compilation process What happens when you compile a Java program? $ javac Example.java Example.java is compiled to create Example.class But... what if you compile it again? what if Example.java uses Point objects from Point.java? what if Point.java is changed but not recompiled, and then we try to recompile Example.java?

Compiling large programs compiling multi-file programs repeatedly is cumbersome: $ gcc -g -Wall -o myprogram file1.c file2.c file3.c retyping the above command is wasteful: for the developer (so much typing) for the compiler (may not need to recompile all; save them as .o) improvements: use up-arrow or history to re-type compilation command for you use an alias or shell script to recompile everything use a system for compilation/build management, such as make

Dependencies dependency : When a file relies on the contents of another. can be displayed as a dependency graph to build main.o, we need data.h, main.c, and io.h if any of those files is updated, we must rebuild main.o if main.o is updated, we must update project1

make make : A utility for automatically compiling ("building") executables and libraries from source code. a very basic compilation manager often used for C programs, but not language-specific primitive, but still widely used due to familiarity, simplicity similar programs: ant, maven, IDEs (Eclipse), ... Makefile : A script file that defines rules for what must be compiled and how to compile it. Makefiles describe which files depend on which others, and how to create / compile / build / update each file in the system as needed.

make demo figlet : program for displaying large ASCII text (like banner). http://sourceforge.net/projects/freshmeat_figlet/ Let's download a piece of software and compile it with make: download .tar.gz file un-tar it (optional) look at README file to see how to compile it (sometimes) run ./configure for cross-platform programs; sets up make for our operating system run make to compile the program execute the program

Makefile rule syntax target : source1 source2 ... sourceN command ... Example: myprogram : file1.c file2.c file3.c gcc -o myprogram file1.c file2.c file3.c The command line must be indented by a single tab not by spaces; NOT BY SPACES! SPACES WILL NOT WORK!

Running make variations: $ make target uses the file named Makefile in current directory finds rule in Makefile for building target and follows it if the target file does not exist, or if it is older than any of its sources, its commands will be executed variations: $ make builds the first target in the Makefile $ make -f makefilename $ make -f makefilename target uses a makefile other than Makefile

Rules with no sources myprog: file1.o file2.o file3.o gcc -g -Wall -o myprog file1.o file2.o file3.o clean: rm file1.o file2.o file3.o myprog make assumes that a rule's command will build/create its target but if your rule does not actually create its target, the target will still not exist the next time, so the rule will always execute (clean above) make clean is a convention for removing all compiled files

Rules with no commands all: myprog myprog2 myprog: file1.o file2.o file3.o gcc -g -Wall -o myprog file1.o file2.o file3.o myprog2: file4.c gcc -g -Wall -o myprog2 file4.c ... all rule has no commands, but depends on myprog and myprog2 typing make all will ensure that myprog, myprog2 are up to date all rule often put first, so that typing make will build everything

Variables NAME = value (declare) $(NAME) (use) OBJFILES = file1.o file2.o file3.o PROGRAM = myprog $(PROGRAM): $(OBJFILES) gcc -g -Wall -o $(PROGRAM) $(OBJFILES) clean: rm $(OBJFILES) $(PROGRAM) variables make it easier to change one option throughout the file also makes the makefile more reusable for another project

More variables variables can be conditional (ifdef above) OBJFILES = file1.o file2.o file3.o PROGRAM = myprog ifdef WINDIR # assume it's a Windows box PROGRAM = myprog.exe endif CC = gcc CCFLAGS = -g -Wall $(PROGRAM): $(OBJFILES) $(CC) $(CCFLAGS) -o $(PROGRAM) $(OBJFILES) variables can be conditional (ifdef above) many makefiles create variables for the compiler, flags, etc. this can be overkill, but you will see it "out there"

Special variables $@ the current target file $^ all sources listed for the current target $< the first (left-most) source for the current target (there are other special variables) myprog: file1.o file2.o file3.o gcc $(CCFLAGS) -o $@ $^ file1.o: file1.c file1.h file2.h gcc $(CCFLAGS) -c $<

Auto-conversions rather than specifying individually how to convert every .c file into its corresponding .o file, you can set up an implicit target: # conversion from .c to .o .c.o: gcc $(CCFLAGS) -c $< "To create filename.o from filename.c, run gcc -g -Wall -c filename.c" for making an executable (no extension), simply write .c : .c: gcc $(CCFLAGS) -o $@ $< related rule: .SUFFIXES (what extensions can be used)

Dependency generation You can make gcc figure out dependencies for you: $ gcc -M filename instead of compiling, outputs a list of dependencies for the given file $ gcc -MM filename similar to -M, but omits any internal system libraries (preferred) Example: $ gcc -MM linkedlist.c linkedlist.o: linkedlist.c linkedlist.h util.h related command: makedepend