1 CSE 390 Lecture 8 Large Program Management: Make; Ant slides created by Marty Stepp, modified by Jessica Miller and Ruth Anderson

Slides:



Advertisements
Similar presentations
CSE 303 Lecture 16 Multi-file (larger) programs
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.
Makefiles  Provide a way for separate compilation.  Describe the dependencies among the project files.  The make utility.
David Notkin Autumn 2009 CSE303 Lecture 20 Multi-file (larger) programs Friday: social implications.
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.
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.
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.
Lecture 8  make. Overview: Development process  Creation of source files (.c,.h,.cpp)  Compilation (e.g. *.c  *.o) and linking  Running and testing.
CSE 403 Lecture 11 Static Code Analysis Reading: IEEE Xplore, "Using Static Analysis to Find Bugs" slides created by Marty Stepp
July 29, 2003Serguei Mokhov, 1 Makefile Brief Reference COMP 229, 346, 444, 5201 Revision 1.2 Date: July 18, 2004.
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), …
Adv. UNIX: large/131 Advanced UNIX v Objectives of these slides: –learn how to write/manage large programs consisting of multiple files, which.
Scons Writing Solid Code Overview What is scons? scons Basics Other cools scons stuff Resources.
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.
CSE 251 Dr. Charles B. Owen Programming in C1 Compilation and Makefiles.
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.
Makefiles CARYL RAHN. Separate compilation Large programs are generally separated into multiple files, e.g. main.c addmoney.c removemoney.c money.h With.
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.
Multiple File Compilation and linking By Bhumik Sapara.
C code organization CSE 2451 Rong Shi. Topics C code organization Linking Header files Makefiles.
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:
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
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
GNU Make Computer Organization II 1 © McQuain What is make ? make is a system utility for managing the build process (compilation/linking/etc).
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 14 – Makefiles and Compilation Management.
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
CSE 303 Lecture 17 Makefiles reading: Programming in C Ch. 15
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha Fall 2015
CSE 374 Programming Concepts & Tools
Brief Intro to Make CST494/ Gannod.
Large Program Management: Make; Ant
Makefiles Caryl Rahn.
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
Large Program Management: Make; Ant
Large Program Management: Make; Ant
Makefiles and the make utility
Large Program Management: Make; Ant
CSE 390 Lecture 8 Large Program Management: Make; Ant
CMSC 202 Additional Lecture – Makefiles
Large Program Management: Make; Ant
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
Makefiles and the make utility
Build Management EE 461L Based on materials from Christine Julien, Miryung Kim and Adnan Aziz.
CSE 390 Lecture 8 Large Program Management: Make; Ant
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.
Large Program Management: Make; Ant
The make utility (original presentation courtesy of Alark Joshi)
Large Program Management: Make, Ant
Presentation transcript:

1 CSE 390 Lecture 8 Large Program Management: Make; Ant slides created by Marty Stepp, modified by Jessica Miller and Ruth Anderson

2 Motivation single-file programs do not work well when code gets large  compilation can be slow  hard to collaborate between multiple programmers  more cumbersome to edit larger programs are split into multiple files  each file represents a partial program or module  modules can be compiled separately or together  a module can be shared between multiple programs but now we have to deal with all these files just to build our program…

3 Compiling: Java What happens when you compile a Java program? $ javac Example.java Example.class Answer: It produces a.class file.  Example.java is compiled to create Example.class How do you run this Java program? $ java Example produces

4 Compiling: C To compile a C program called source.c, type: gcc -o target source.c target (where target is the name of the executable program to build)  the compiler builds an actual executable file (not a.class like Java)  Example: gcc -o hi hello.c Compiles the file hello.c into an executable called “hi” To run your program, just execute that file:  Example:./hi commanddescription gcc GNU C compiler produces

5 Object files (.o) A.c file can also be compiled into an object (.o) file with -c : $ gcc -c part1.c part1.o $ ls part1.c part1.o part2.c  a.o file is a binary “blob” of compiled C code that cannot be directly executed, but can be directly “inserted” into a larger executable later You can compile a mixture of.c and.o files: $ gcc -o combined part1.o part2.ccombined Avoids recompilation of unchanged partial program files (e.g. part1.o ) produces

6 Header files (.h) header : A C file whose only purpose is to be #included (#include is like java import statement)  generally a filename with the.h extension  holds shared variables, types, and function declarations  similar to a java interface: contains function declarations but not implementations key ideas:  every name.c intended to be a module (not a stand alone program) has a name.h  name.h declares all global functions/data of the module  other.c files that want to use the module will #include name.h

7 Compiling large programs Compiling multi-file programs repeatedly is cumbersome: $ gcc -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

8 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.

9 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

10 make Exercise figlet : program for displaying large ASCII text (like banner ).  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

11 Makefile rule syntax target : source1 source2... sourceN command...  source1 through sourceN are the dependencies for building target  Make will execute the commands in order Example: myprogram : file1.c file2.c file3.c gcc -o myprogram file1.c file2.c file3.c this is a tab THIS IS NOT spaces!!  The command line must be indented by a single tab not by spaces; NOT BY SPACES! SPACES WILL NOT WORK!

12 Running make $ make target  uses the file named Makefile in current directory  Finds a 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

13 Making a Makefile Exercise: Create a basic Makefile to build {hello.c, file2.c, file3.c}  Basic works, but is wasteful. What happens if we change file2.c? everything is recompiled. On a large project, this could be a huge waste

14 Making a Makefile courtesy XKCD

15 Making a Makefile Exercise: Create a basic Makefile to build {hello.c, file2.c, file3.c}  Basic works, but is wasteful. What happens if we change file2.c? everything is recompiled. On a large project, this could be a huge waste  Augment the makefile to make use of precompiled object files and dependencies by adding additional targets, we can avoid unnecessary re-compilation

16 Rules with no dependencies myprog: file1.o file2.o file3.o gcc -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 its commands (e.g. clean above)  make clean is a convention for removing all compiled files

17 Rules with no commands all: myprog myprog2 myprog: file1.o file2.o file3.o gcc -o myprog file1.o file2.o file3.o myprog2: file4.c gcc -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 Exercise: add “clean” and “all” rules to our hello Makefile

18 Variables NAME = value (declare) $(NAME) (use) Example Makefile: OBJFILES = file1.o file2.o file3.o PROGRAM = myprog $(PROGRAM): $(OBJFILES) gcc -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

19 More variables Example Makefile: OBJFILES = file1.o file2.o file3.o PROGRAM = myprog CC = gcc CCFLAGS = -g -Wall $(PROGRAM): $(OBJFILES) $(CC) $(CCFLAGS) -o $(PROGRAM) $(OBJFILES) many makefiles create variables for the compiler, flags, etc.  this can be overkill, but you will see it "out there"

20 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*)other special variables Example Makefile: myprog: file1.o file2.o file3.o gcc $(CCFLAGS) -o $^ file1.o: file1.c file1.h file2.h gcc $(CCFLAGS) -c $< Exercise: change our hello Makefile to use variables for the object files and the name of the program *

21 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 Makefile comments!.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 $< Exercise: simplify our hello Makefile with a single.c.o conversion

22 What about Java? Create Example.java that uses a class MyValue in MyValue.java  Compile Example.java and run it javac automatically found and compiled MyValue.java  Now, alter MyValue.java Re-compile Example.java… does the change we made to MyValue propagate? Yep! javac follows similar timestamping rules as the makefile dependencies. If it can find both a.java and a.class file, and the.java is newer than the.class, it will automatically recompile But be careful about the depth of the search... But, this is still a simplistic feature. Ant is a commonly used build tool for Java programs giving many more build options.

23 Ant Similar idea to Make, though Ant uses build.xml instead of Makefile: tasks tasks Tasks can be things like:   A whole lot more…

24 Ant Example Create an Ant file to compile our Example.java program Running ant (assuming build.xml in current directory): $ ant targetname

25 Ant Example Create an Ant file to compile our Example.java program

26 Automated Build Systems Fairly essential for any large programming project  Why? Shell scripts instead? What are these tools aiming to do?  Is timestamping the right approach for determining “recompile”?  What about dependency determination?  What features would you want from an automated build tool?  Should “building” your program also involve non-syntactic checking? Ant can run JUnit tests…