CSC 2500: Unix Lab Fall 2016

Similar documents
INTERMEDIATE SOFTWARE DESIGN SPRING 2011 ACCESS SPECIFIER: SOURCE FILE

Projects and Make Files

CSC 2500: Unix Lab Fall 2016

Build automation. CSE260, Computer Science B: Honors Stony Brook University

CSC 2500: Unix Lab Fall 2016

Final Topics. Ali Malik

UNIX Makefile. C Project Library Distribution and Installation.

CS Basics 15) Compiling a C prog.

Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 2

CS2141 Software Development using C/C++ Compiling a C++ Program

And You Thought There Couldn t be More C++ Fundamentals of Computer Science

Makefile Tutorial. Eric S. Missimer. December 6, 2013

2 Compiling a C program

GDB and Makefile. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011

Outline. COMP 2718: Software Development Tools: gcc and make. C and Java 3/28/16

Intermediate Programming, Spring 2017*

CAAM 420 Fall 2012 Lecture 15. Roman Schutski

EL2310 Scientific Programming

Compilation & linkage. Compilation & linkage. Make. Compilation & linkage. Explicit rules. What makefile contains

Multiple file project management & Makefile

CS240: Programming in C

Makefiles SE 2XA3. Term I, 2018/19

Make! CSC230: C and Software Tools. N.C. State Department of Computer Science. Some examples adapted from

CIS 190: C/C++ Programming. Lecture 2 Pointers and More

Data and File Structures Laboratory

Lab 1: Introduction to C Programming. (Creating a program using the Microsoft developer Studio, Compiling and Linking)

EL2310 Scientific Programming

GNU make... Martin Ohlerich, Parallel Programming of High Performance Systems

CMPSC 311- Introduction to Systems Programming Module: Build Processing

CS11 Advanced C++ Fall Lecture 4

Part III Synchronization A bit of C++ and ThreadMentor

COMP Lecture Notes The Compiler

Section 1: Tools. Kaifei Chen, Luca Zuccarini. January 23, Make Motivation How... 2

PROGRAM COMPILATION MAKEFILES. Problem Solving with Computers-I

CSE 374 Programming Concepts & Tools

Maemo Diablo GNU Make and makefiles Training Material

The Linux Programming Environment. Computer Science Department Texas State University

CS11 Intro C++ Spring 2018 Lecture 4

CMPSC 311- Introduction to Systems Programming Module: Build Processing

ENERGY 211 / CME 211. Evolution

CS240: Programming in C. Lecture 2: Overview

CSC 6575: Internet Security Fall 2017

CS201 - Lecture 1 The C Programming Language

The Make Utility. Independent compilation. Large programs are difficult to maintain. Problem solved by breaking the program into separate files

Reliable C++ development - session 1: From C to C++ (and some C++ features)

Starting to Program in C++ (Basics & I/O)

The make utility. Alark Joshi COMPSCI 253

The Make Utility. Independent compilation. Large programs are difficult to maintain. Problem solved by breaking the program into separate files

Workshop Agenda Feb 25 th 2015

CSC 6575: Internet Security Fall 2017

Continue: How do I learn C? C Primer Continued (Makefiles, debugging, and more ) Last Time: A Simple(st) C Program 1-hello-world.c!

PRINCIPLES OF OPERATING SYSTEMS

Crash Course in C++ R F L Evans. www-users.york.ac.uk/~rfle500/

Systems Programming. laboratory. Compilation automation. make ceedling

C Compilation Model. Comp-206 : Introduction to Software Systems Lecture 9. Alexandre Denault Computer Science McGill University Fall 2006

Tutorial: Compiling, Makefile, Parallel jobs

Makefiles are a simple way to organize code compilation. Using a makefile it is possible to compile several source files to produce an executable;

independent compilation and Make

CSCI-243 Exam 2 Review February 22, 2015 Presented by the RIT Computer Science Community

Make: a build automation tool

CSE 333 Interlude - make and build tools

Introduction. Key features and lab exercises to familiarize new users to the Visual environment

Reviewing gcc, make, gdb, and Linux Editors 1

[Software Development] Makefiles. Davide Balzarotti. Eurecom Sophia Antipolis, France

15213 Recitation Section C

Compiling with Multiple Files The Importance of Debugging CS 16: Solving Problems with Computers I Lecture #7

The make utility automatically determines which pieces of a large program need to be recompiled, and issues commands to recompile them.

Software Building (Sestavování aplikací)

CSCi 4061: Intro to Operating Systems Spring 2017 Instructor: Jon Weissman Assignment 1: Simple Make Due: Feb. 15, 11:55 pm

CMPT 300. Operating Systems. Brief Intro to UNIX and C

Basic Unix Commands. CGS 3460, Lecture 6 Jan 23, 2006 Zhen Yang

Build Tools. Software Engineering SS A tool was needed. Agenda for today. Build tools. Software complexity. Build tools

Make: a build automation tool 1/23

Deep C. Multifile projects Getting it running Data types Typecasting Memory management Pointers. CS-343 Operating Systems

Programming I Laboratory - lesson 01

Build Tools. Software Engineering SS 2007

Computing Layers. Chapter 3 Digital Logic Structures. Combinational vs. Sequential. State Machine. Another type of sequential circuit

Introduction to System Programming : makefile

Lab 1: First Steps in C++ - Eclipse

CSI 402 Lecture 1 (Programs in Multiple Files and make) 1 1 / 20

Introduction to Supercomputing

Intermediate Programming, Spring Misha Kazhdan

#include <stdio.h> int main() { printf ("hello class\n"); return 0; }

CpSc 1111 Lab 5 Formatting and Flow Control

CpSc 1111 Lab 4 Part a Flow Control, Branching, and Formatting

CMSC 104 Lecture 2 by S Lupoli adapted by C Grasso

JTSK Programming in C II C-Lab II. Lecture 3 & 4

Problem Set 1: Unix Commands 1

Makefile Practice: Part 1 Making a Single Program without Templated.h Files: Get the MakeBasics folder from the CS260 repository.

1.7 Recursion. Department of CSE

Chris' Makefile Tutorial

Exercise 1: Basic Tools

GNU Make 1. 1 material adapted from GNU Make by Richard Stallman

How to learn C? CSCI [4 6]730: A C Refresher or Introduction. Diving In: A Simple C Program 1-hello-word.c

CSC209H Lecture 5. Dan Zingaro. February 4, 2015

EL2310 Scientific Programming

HPC User Environment


C++ Lab 07 - Introduction to C++ Build Systems

Transcription:

CSC 2500: Unix Lab Fall 2016 Makefile Mohammad Ashiqur Rahman Department of Computer Science College of Engineering Tennessee Tech University

Agenda Make Utility Build Process The Basic Makefile Target Using Dependencies Using Variables and Comments Lab 9: Creating Makefiles M. Ashiq Rahman, Tennessee Tech University 2

The make utility Makefiles are special format files that together with the make utility help to automatically build and manage the projects. The command make will look for a file named makefile in your directory, and then execute it. If you have several makefiles, then you can execute them with the command: make -f mymakefile M. Ashiq Rahman, Tennessee Tech University 3

Build Process Build process includes the following two things: Compiler takes the source files and outputs object files Linker takes the object files and creates an executable The trivial way to compile the files and obtain an executable, is by running the command: g++ main.cpp hello.cpp factorial.cpp -o hello M. Ashiq Rahman, Tennessee Tech University 4

// functions.h void print_hello(); int factorial(int n); Example: Files // main.cpp #include <stdio.h> #include "functions.h" int main() { print_hello(); printf("\n"); printf("the factorial of 5 is %d\n", factorial(5)); return 0; } // hello.cpp #include <stdio.h> #include "functions.h" void print_hello() { printf("hello World!"); } // factorial.cpp #include "functions.h" int factorial(int n) { if(n!=1) { return(n * factorial(n-1)); } else return 1; } M. Ashiq Rahman, Tennessee Tech University 5

The Basic Makefile The basic makefile is composed of: target: dependencies [tab] system command This syntax applied to our example will look like: all: g++ main.cpp hello.cpp factorial.cpp -o hello To run this makefile on our files: make -f Makefile1 Target is named all. This is the default target for makefiles. The make utility will execute this target if no other one is specified. Here no dependencies for target all, so make safely executes the system commands specified. M. Ashiq Rahman, Tennessee Tech University 6

Dependencies Sometimes is useful to use different targets. Because: If we modify a single file in our project, we do not have to recompile everything, only what you modified. The target called clean is useful if we want to have a fast way to get rid of all the object files and so..phony target: A phony target is one that is not the name of a file; rather it is just a name for a recipe to be executed when you make an explicit request. all: hello hello: main.o factorial.o hello.o g++ main.o factorial.o hello.o -o hello main.o: main.cpp g++ -c main.cpp factorial.o: factorial.cpp g++ -c factorial.cpp hello.o: hello.cpp g++ -c hello.cpp clean: rm -f *o hello M. Ashiq Rahman, Tennessee Tech University 7

Dependencies (2) all: hello hello: main.o factorial.o hello.o g++ main.o factorial.o hello.o -o hello main.o: main.cpp g++ -c main.cpp factorial.o: factorial.cpp g++ -c factorial.cpp hello.o: hello.cpp g++ -c hello.cpp clean: rm -f *o hello $ make f mymakefile g++ -c main.cpp g++ -c factorial.cpp g++ -c hello.cpp g++ main.o factorial.o hello.o -o hello $ ls factorial.cpp functions.h hello.cpp main.cpp mymakefile factorial.o hello hello.o main.o $ make f mymakefile clean $ ls factorial.cpp functions.h hello.cpp main.cpp mymakefile $./hello Hello World! The factorial of 5 is 120 M. Ashiq Rahman, Tennessee Tech University 8

Using Variables Variables can be used when writing makefiles. Useful where we want to change the compiler, or the compiler options. Just a note: -Wall option is for all warnings # CC is the compiler to be used CC=g++ # CFLAGS will be the options to the compiler. CFLAGS=-c -Wall all: hello hello: main.o factorial.o hello.o $(CC) main.o factorial.o hello.o -o hello main.o: main.cpp $(CC) $(CFLAGS) main.cpp factorial.o: factorial.cpp $(CC) $(CFLAGS) factorial.cpp hello.o: hello.cpp $(CC) $(CFLAGS) hello.cpp clean: rm -f *o M. Ashiq Rahman, Tennessee Tech University 9

Ultimate Makefile CC=g++ CFLAGS=-c -Wall LDFLAGS= SOURCES=main.cpp hello.cpp factorial.cpp OBJECTS=$(SOURCES:.cpp=.o) EXECUTABLE=hello all: $(SOURCES) $(EXECUTABLE) $(EXECUTABLE): $(OBJECTS) $(CC) $(LDFLAGS) $(OBJECTS) -o $@.cpp.o: $(CC) $(CFLAGS) $< -o $@ $(variable:suffix=replacement) $(patsubst pattern,replacement,$(variable)) OBJECTS=$(patsubst %.cpp,%.o,$(sources)) LDFLAGS is the linker flag so that the linker will look in the directed directory to find the shared library. M. Ashiq Rahman, Tennessee Tech University 10

Lab 09 Objective: Writing Makfile Makefile variables Targets, dependencies, and rules Creating a shared library PHONY targets Auto-generating dependencies For this lab, you will write a make file, called Makefile, that compiles a Craps game. M. Ashiq Rahman, Tennessee Tech University 12

Lab 09: Description Craps.zip consists of craps_game.cpp, craps_helper.cpp, craps_io.cpp files. Your Makefile Compile craps_game.cpp, craps_helper.cpp, craps_io.cpp into object files Combine them into a shared library. Remember that you must use the compiler flag -fpic when compiling and the -shared flag when linking to create a shared library. M. Ashiq Rahman, Tennessee Tech University 13

Lab 09: Homework Submission Rename your makefile as <FirstName Initial><LastName>_makefile. Submission Deadline: Friday, November 11, 2016 Submission Site: ilearn (a Dropbox folder named Homework 09 ) Submission Content: Submit your makefile. M. Ashiq Rahman, Tennessee Tech University 14

Lab 09: Lab Practice Create the makefile described in the lecture. Without variables (makefile1) With variables (makefile2) M. Ashiq Rahman, Tennessee Tech University 15

THANKS Acknowledgement: - http://mrbook.org/blog/tutorials/make/ M. Ashiq Rahman, Tennessee Tech University 16