Makefiles and Notes on Programming Assignment PA2

Slides:



Advertisements
Similar presentations
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.
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.
Strings and Dynamic Memory Allocation CS-2301, B-Term Programming Assignment #6 Strings and Dynamic Memory Allocation CS-2301, System Programming.
Systems Dev. Tutorial II: Make, utilities, & scripting Recitation Wednesday, Sept 13 th, 2006.
Programming Assignment #6 CS-2301 D-term Programming Assignment #6 Binary Trees CS-2301 System Programming D-term 2009 (Slides include materials.
More Miscellaneous Topics CS-2301 B-term More Miscellaneous Topics CS-2301, System Programming for Non-majors (Slides include materials from The.
Programming Assignment #4 Binary Trees
Introduction to Classes and Objects CS-2303, C-Term Introduction to Classes and Objects CS-2303 System Programming Concepts (Slides include materials.
Binary TreesCS-2301, B-Term Programming Assignment #5 Binary Trees CS-2301, System Programming for Non-Majors (Slides include materials from The.
Enabling the ARM Learning in INDIA ARM DEVELOPMENT TOOL SETUP.
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.
Introduction Use of makefiles to manage the build process Declarative, imperative and relational rules Environment variables, phony targets, automatic.
Old Chapter 10: Programming Tools A Developer’s Candy Store.
GNU Make Computer Organization II 1 © McQuain What is make ? make is a system utility for managing the build process (compilation/linking/etc).
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.
Multiple File Compilation and linking By Bhumik Sapara.
C code organization CSE 2451 Rong Shi. Topics C code organization Linking Header files Makefiles.
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).
Multiple file project management & Makefile
Makefiles CSSE 332 Operating Systems
Lecture 3 Translation.
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha Fall 2015
Brief Intro to Make CST494/ Gannod.
Makefiles Caryl Rahn.
Computer Systems and Networks
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
Programming Assignment #4 Binary Trees in C++
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Makefiles and the make utility
Data Structures and Programming Techniques
Strings and Streams Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition,
“Under the Hood” of Polymorphism
Classes, Constructors, etc., in C++
Containers and the Standard Template Library (STL)
Miscellaneous C++ Topics
Dynamic Memory Allocation (and Multi-Dimensional Arrays)
Structures, Unions, and Typedefs
Derived Classes in C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition,
Linked Lists in C and C++
Binary Trees (and Big “O” notation)
Polymorphism Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition, by Kernighan.
Bit Fields & Bitwise Operations
Programming Assignment #1 12-Month Calendar—
Templates (again) Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition,
Symbolic Constants in C
Recursion and Implementation of Functions
Programming Assignment #6
Accessing Files in C Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition,
Scope Rules and Storage Types
Programming Assignment #5
CMPSC 60: Week 4 Discussion
Differences between Java and C
Your first C and C++ programs
Iterators Professor Hugh C. Lauer CS-2303, System Programming Concepts
Operator Overloading Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition,
Digression on Loop Invariants
Appendix F C Programming Environment on UNIX Systems
Lab Project #4: PerfLab— Code Optimizations and Performance
A Deeper Look at Classes
Preparation for Assignment 2
Makefiles and the make utility
Compiler vs linker The compiler translates one .c file into a .o file
SPL – PS1 Introduction to C++.
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.
Introduction to Classes and Objects
Presentation transcript:

Makefiles and Notes on Programming Assignment PA2 Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition, by Kernighan and Ritchie, Absolute C++, by Walter Savitch, The C++ Programming Language, Special Edition, by Bjarne Stroustrup, and from C: How to Program, 5th and 6th editions, by Deitel and Deitel) CS-2303, A-Term 2010 Programming Assignment PA #2

Programming Assignment PA #2 Game of Life Read input line to determine size of board, number of generations, etc. Dynamically allocate memory for three boards of the appropriate size Initialize one board to initial configuration (in center) Play up to n generations After each generation, test for termination — I.e., same as previous or 2nd previous generation Print final generation Optional pause and/or print after each generation for debugging purposes Free dynamically allocated memory! CS-2303, A-Term 2010 Programming Assignment PA #2

Dynamically Allocated Arrays Each board is a 2D array Size determined at run-time gcc feature of dynamic automatic arrays not appropriate for this assignment Allocate array of pointers to rows Allocate array(s) for actual rows CS-2303, A-Term 2010 Programming Assignment PA #2

Programming Assignment PA #2 From this point on, every programming assignment at WPI must be accompanied by makefile or equivalent Unless otherwise specified Eclipse, Visual Studio, etc. provide own makefile equivalents Program Organization See Lab2 Must have At least one .h file (your interface) At least two .c files (together your program) One makefile Suggested partition Life.c — main program, read input & initialize Game.c — playing game, testing termination Board.c — utility functions for printing boards, comparison, etc. Life.h — interface with function headers, extern variable for any globals, etc. You may choose your own partition of the problem CS-2303, A-Term 2010 Programming Assignment PA #2

Programming Assignment PA #2 Makefile A scripting “language” that specifies how an application is to be built Flags, compiler switches, libraries to link Creates final target and all intermediate files Recompiles only what needs to be E.g., source files that have changed Dependencies upon other files For PA2, target is the program Life CS-2303, A-Term 2010 Programming Assignment PA #2

Programming Assignment PA #2 Format of Makefile List of targets Followed by colon and dependencies For each target, command line(s) for building target If any List of environment variables For passing switches to commands, etc. CS-2303, A-Term 2010 Programming Assignment PA #2

Programming Assignment PA #2 make command make Builds the first target in file makefile make –f myMakefile Builds the first target in file myMakefile make Life Builds target Life in file makefile make CFLAGS=-g Builds first target using compiler flag –g make CFLAGS=-O2 Life Builds target Life using compiler flag –O2 (i.e., optimized code) CS-2303, A-Term 2010 Programming Assignment PA #2

Programming Assignment PA #2 Example Makefile Environment variable (note '=‘ sign) CFLAGS = -g all: Board.o Game.o Life.o Input.o gcc $(CFLAGS) Board.o Game.o Life.o Input.o -o Life *.o: *.c gcc -Wall -c $(CFLAGS) *.c clean: rm -f *.o Life echo "Make clean completed." Board.o: Life.h Game.o: Life.h Target (note colon; note also dependencies following colon ) Command lines must be preceded by tabs, not spaces Command line to build target all Generic target and command for all .o files Note dependency on corresponding .c file Very important target — cleans up the directory (note two commands) Targets with no commands, only dependencies CS-2303, A-Term 2010 Programming Assignment PA #2

Summary – make & makefiles make — a useful tool for building all but the most trivial programs Avoids stupid mistakes in compile commands Builds only the parts of an application that need to be rebuilt Can be combined to make very elaborate build “scripts” CS-2303, A-Term 2010 Programming Assignment PA #2

Programming Assignment PA #2 Questions? Next Topic CS-2303, A-Term 2010 Programming Assignment PA #2