Make. A simple make file $ make program Strength of make is its sensitivity to dependency hierarchies. Specify such dependencies in a description file.

Slides:



Advertisements
Similar presentations
The make Utility Programming Tools and Environments Winter 2006.
Advertisements

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.
The Makefile utility ABC – Chapter 11, Motivation Small programs single file “Not so small” programs : –Many lines of code –Multiple components.
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,
Systems Dev. Tutorial II: Make, utilities, & scripting Recitation Wednesday, Sept 13 th, 2006.
The Makefile Utility ABC – Chapter 11, Motivation Small programs single file “Not so small” programs : –Many lines of code –Multiple components.
2000 Copyrights, Danielle S. Lahmani UNIX Tools G , Fall 2000 Danielle S. Lahmani Lecture 9.
CS465 - Unix C Programming (cc/make and configuration control)
The Makefile Utility ABC – Chapter 11, Motivation Small programs single file “Not so small” programs : –Many lines of code –Multiple components.
Lecture 8  make. Overview: Development process  Creation of source files (.c,.h,.cpp)  Compilation (e.g. *.c  *.o) and linking  Running and testing.
Unix Makefiles COP 3330 Lecture Notes Dr. David A. Gaitros.
July 29, 2003Serguei Mokhov, 1 Makefile Brief Reference COMP 229, 346, 444, 5201 Revision 1.2 Date: July 18, 2004.
Programming Tools gcc make utility Open Source code Static and Shared Libraries gdb Memory debugging tools.
Introduction Use of makefiles to manage the build process Declarative, imperative and relational rules Environment variables, phony targets, automatic.
The UNIX development environment CS 400/600 – Data Structures.
Jump to first page (C) 1998, Arun Lakhotia 1 Software Configuration Management: Build Control Arun Lakhotia University of Southwestern Louisiana Po Box.
1 Linux Command. Advanced Compiler Laboratory2 Simple linux cmds ls List information about FILEs, by default the current directory. pwd Print Working.
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.
Lecture 2 Linux Basic Commands,Shell and Make September 8, 2015 Kyu Ho Park.
Chapter Ten g++ and make1 System Programming Software Development: g++ and make.
The Makefile (in a windows environment) Make reads its instructions from text files. An initialization file is read first, followed by the makefile. The.
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.
Lecture 24CS311 – Operating Systems 1 1 CS311 – Lecture 24 Outline Final Exam Study Guide Note: These lecture notes are not intended replace your notes.
Week 2-3 Control flow (review) Conditional statements If, else, else if, switch-case, break Loop constructs for, while, do-while, break, continue, label--go;
0 4.1 Basics of Functions + Execution Diagram + make 4.2 Functions Returning Non-integers + Prototype Function 4.3 External Variables 4.4 Scope Rules 4.5.
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)
CS252: Systems Programming Ninghui Li Slides by Prof. Gustavo Rodriguez-Rivera Topic 7: Unix Tools and Shell Scripts.
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.
An Introduction to the UNIX Make Utility Introduction: Although make can be used in conjunction with most programming languages all examples given here.
CSI605 Introduction to make. Advantages of Make Significantly reduces the amount of time spent compiling a program. Insures that programs are compiled.
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
Makefile Script file to automate program compilation and linking (making) 1. Write the "makefile" 2. Write your programs 3. Run "make" or "make -f makefile"
UNIX Development: g++ and make CS 2204 Class meeting 8 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
Embedded System Programming.1 C-Language Review.
Makefiles Manolis Koubarakis Data Structures and Programming Techniques 1.
Multiple file project management & Makefile
Makefiles CSSE 332 Operating Systems
The make utility (original presentation courtesy of Alark Joshi)
Lecture 2 Linux Basic Commands,Shell and Make
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha Fall 2015
Brief Intro to Make CST494/ Gannod.
Shell Scripting March 1st, 2004 Class Meeting 7.
Makefiles Caryl Rahn.
SEEM3460 Tutorial The Make Utility.
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
Makefiles and the make utility
Data Structures and Programming Techniques
CMPSC 60: Week 4 Discussion
SCMP Software Development Spring 2018 James Skon
CSc 352: Elementary “make”
CSc 352 An Introduction to make
Makefiles and the make utility
Makefiles, GDB, Valgrind
SCMP Software Development Spring 2018 James Skon
Review.
The make utility (original presentation courtesy of Alark Joshi)
Presentation transcript:

Make

A simple make file $ make program Strength of make is its sensitivity to dependency hierarchies. Specify such dependencies in a description file called makefile (or Makefile). target program is built of 1 or more files called dependents, recursively.

Description file example CC = gcc program : main.o iodat.o dorun.o lo.o /usr/lib/crtn.a ${CC} –o program main.o iodat.o dorun.o lo.o /usr/lib/crtn.a main.o : main.c ${CC} –c main.c iodat.o : iodat.c ${CC} –c iodat.c dorun.o : dorun.c ${CC} –c dorun.c lo.o : lo.s as -o lo.o lo.s delete: rm –f *.o tab Each entry consists of a dependency line (:) and one or more command lines. To the left of the : is the target. To the right are the target dependencies. Command lines begin with a \t character. Command lines show how to build a target. CC is a variable; makes it easier to change the compiler.

How make is used: In the directory that contains a makefile execute for any target in a makefile. Or make several targets: The command Makes the first target. $ make $ make target1 target2 target3 $ make

How make works: make executes the commands associated with the command line target. But before that it checks a lot. Does a file called program exist and is it newer than any of its dependencies. If so, make exits doing nothing. If, for example, dorun.o is newer than program make essentially processes before it then executes the program entry command. If dorun.o is newer than program make checks dorun.o dependency. dorun.o depends on dorun.c and if dorun.c is newer than dorun.o make essentiallyprocesses before it then executes the program entry command. $ make program $ make dorun

Key to make’s usefulness: Ability to decide on its own what things to build.

Summary: Building a program means executing a chain of commands. Make traces back through the chain of dependencies and decides what commands must be executed. Make works its way through the chain until finally your command-line target is up to date.

2 nd Example: plot_prompt : basic.o prompt.o cc –o plot_prompt basic.o prompt.o plot_win : basic.o window.o cc –o plot_win basic.o window.o basic.o : basic.c cc –c basic.c prompt.o : prompt.c cc –c prompt.c window.o : window.c cc –c window.c

2 nd Example (cont) $ make plot_prompt cc –o prompt.c cc –o plot_prompt basic.o prompt.o

Command line options: Minor part of make. -f description file with non-standard name -n print out all commands to execute but execute none -s execute all but no echoed output -q checks if targets are up-to-date; returns 0 if so; non-zero otherwise -t updates modified date of target (advances target date) -i continue to execute commands even if errors early on -e change precedence order of macro expansion

Macros: name = text string # definition $(name) or ${name} # usage DEBUG_FLAG = # none now but can change to –g ${CC} ${DEBUG_FLAG} –o myprog myprog.c

Macro examples CC = gcc OBJS = main.o\ iodat.o\ dorun.o\ lo.o program : main.o iodat.o dorun.o lo.o /usr/lib/crtn.a ${CC} –o program ${OBJS} /usr/lib/crtn.a main.o : main.c ${CC} –c main.c iodat.o : iodat.c ${CC} –c iodat.c dorun.o : dorun.c ${CC} –c dorun.c lo.o : lo.s as -o lo.o lo.s delete: rm –f *.o

More macros: plot: ${OBJS} ${CC} –o plot ${DEBUG_FLAGS} ${OBJS} mv plot ${RUN_DIR} MY_SRC = ${SRC} ${SHARED_SRC} SHARED_DIR = /opt/public SHARED_SRC = ${SHARED_DIR}/shared.c CFLAGS = # typical macro

Macros on the Command Line: DF = # debug turned off myprog: … ${CC} ${DF} myprog.c –o myprog $ make myprog “DF=-g” In this execution of make, the debug flag is set.

Macros from the Environment: $ DIR=/usr/proj; export DIR $ make myprog # Makefile Myprog: … cd ${DIR} ${CC} … $ setenv DIR /usr/proj

Macro Priorities: Macro defined in Makefile, in environment and on command-line. Precedence, least to greatest: Internal to make Shell variable Internal to Makefile Command-line Precedence, least to greatest with –e option : Internal to make Internal to Makefile Shell variable Command-line

Macro String Substitution: SRC = src1.c src2.c src3.c EXECS = ${SRC:.c=} cp ${EXECS} /backup/bin/.

Internal is the current target ? means all prerequisites newer than current target plot_prompt: basic.o prompt.o ${CC} –o basic.o prompt.o libops : interact.o sched.o gen.o ar r $? $ cc –c sched.c $ make libops

Internal Macros (2): is the current target but only on dependency lines. is the current target but only on command lines. CMDS = cat dd echo dae cc cmp comm ar ld chown docmk : CMDS = cat dd echo dae cc cmp comm ar ld chown ${CMDS} : ${CC} –O $? –o $ make echo # acts like echo: echo.c cc –O echo.c –o echo

1 st makefile revisited C_OBJS = main.o iodat.o dorun.o OBJS = ${C_OBJS} lo.o LIB = /usr/lib/crtn.a program: ${OBJS} ${LIB} ${CC} –o ${OBJS} ${LIB} ${C_OBJS} : ${CC} –c $? lo.o : lo.s ${AS} –o $?