David Notkin Autumn 2009 CSE303 Lecture 20 static make.

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.
Makefiles Tutorial adapted from and myMakeTutorial.txt.
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.
CS Lecture 11 Outline Compiling C programs using gcc Archiving modules Using Makefiles Debugging using gdb Assignment 3 discussion Lecture 111CS.
26-Jun-15 Rake. rake and make A program can consist of many source code files This is always true in Rails! The files may need to be compiled in a certain.
Guide To UNIX Using Linux Third Edition
CS465 - Unix C Programming (cc/make and configuration control)
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.
Lecture 8  make. Overview: Development process  Creation of source files (.c,.h,.cpp)  Compilation (e.g. *.c  *.o) and linking  Running and testing.
Makefiles, and.h files, and.c files, and.o files, OH MY! For projects with more complexity. (Great.. Just what we needed)
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.
리눅스 : Lecture 5 UNIX 유틸리티 : text editor, compilation (make), …
Jump to first page (C) 1998, Arun Lakhotia 1 Software Configuration Management: Build Control Arun Lakhotia University of Southwestern Louisiana Po Box.
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.
Introduction to C Programming CE Lecture 7 Compiler options and makefiles.
Chapter Ten g++ and make1 System Programming Software Development: g++ and make.
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.
1 CSE 390 Lecture 8 Large Program Management: Make; Ant slides created by Marty Stepp, modified by Jessica Miller and Ruth Anderson
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;
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.
Discussion Week 1 TA: Kyle Dewey. Project 0 Walkthrough.
Makefiles CARYL RAHN. Separate compilation Large programs are generally separated into multiple files, e.g. main.c addmoney.c removemoney.c money.h With.
Make: File Dependency System Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third.
Emacs, Compilation, and Makefile C151 Multi-User Operating Systems.
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.
Revisiting building. Preprocessing + Compiling 2 Creates an object file for each code file (.c ->.o) Each.o file contains code of the functions and structs.
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
Makefiles Manolis Koubarakis Data Structures and Programming Techniques 1.
Multiple file project management & Makefile
Large Program Management: Make; Ant
CSE 303 Lecture 17 Makefiles reading: Programming in C Ch. 15
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
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Hector Cen Fall 2017
Large Program Management: Make; Ant
Large Program Management: Make; Ant
Large Program Management: Make; Ant
Rake 4-Dec-18.
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
Compiler vs linker The compiler translates one .c file into a .o file
CSC 253 Lecture 15.
CSE 390 Lecture 8 Large Program Management: Make; Ant
SPL – PS1 Introduction to C++.
Large Program Management: Make; Ant
Large Program Management: Make, Ant
Presentation transcript:

David Notkin Autumn 2009 CSE303 Lecture 20 static make

static // example.c int passcode = 12345; // public static int admin_passcode = 67890; // private static used on global variables and functions –visible only to the current file/module (sort of like Java's private ) –declare things static if you do not want them exposed –avoids potential conflicts with multiple modules that happen to declare global variables with the same names –passcode will be visible through the rest of example.c, but not to any other modules/files compiled with example.c CSE303 Au092

Function static data When used inside a function static type name = value; … declares a static local variable that will be remembered across calls int nextSquare() { static int n = 0; static int increment = 1; n += increment; increment += 2; return n; } nextSquare() returns 1, then 4, then 9, then 16,... CSE303 Au093

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), and it’s error-prone –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 ( which is probably an executable like a.out )

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. –The basic idea is to compare file modification dates and to rebuild any file A dependent on another file B that has changed more recently than A

Makefile rule syntax

Running make $ make target uses the file named Makefile in current directory finds rule in Makefile for building target –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 clean: rm file1.o file2.o file3.o myprog make assumes that a rule's command will build or 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 (but not source or header 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 –make all ensures 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 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 include the current target file $^ all sources listed for the current target $< the first (left-most) source for the current target 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

Midterm grades vs. initial experience Unix experience –49% None –37% A little –11% Quite a bit –3% Pays my tuition C/C++ experience –52% None –37% A little –9% Quite a bit –2% Pays my tuition CSE303 Au0917 This is a histogram of midterm scores The bars are the % of people who self- described as having “none”, “a little” or “quite a bit” of Unix/C/C++ experience Each color should total 100% “Pays my tuition” omitted because of the small numbers Mean/Median None76/75 A little81/80 Quite a bit85/83

Questions? CSE303 Au0918