Rake 4-Dec-18.

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.
The Makefile utility ABC – Chapter 11, Motivation Small programs single file “Not so small” programs : –Many lines of code –Multiple components.
David Notkin Autumn 2009 CSE303 Lecture 20 static make.
Understanding Makefiles COMP 2400, Fall 2008 Prof. Chris GauthierDickey.
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,
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation Namespaces Simple Make Files (Ignore all class references.
The Makefile Utility ABC – Chapter 11, Motivation Small programs single file “Not so small” programs : –Many lines of code –Multiple components.
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)
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.
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.
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.
1 Rake. 2 Automated Build Any non-trivial project needs facility to automate builds –Routine common tasks that need to be carried out several times a.
Chapter Ten g++ and make1 System Programming Software Development: g++ and make.
System Programming - LAB 1 Programming Environments.
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.
The Make utility. Motivation Small programs all in single cpp file “Not so small” programs : Many lines of code Multiple components More than one programmer.
Makefiles. Multiple Source Files (1) u Obviously, large programs are not going to be contained within single files. u C provides several techniques to.
Copyright © 2015 Curt Hill Make An Indispensable Developer’s Tool.
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.
Make Make is a system utility that automatically compiles your programs for you Make looks for a file named Makefile (or makefile) in the current directory.
Multiple File Compilation and linking By Bhumik Sapara.
Announcements Assignment 1 will be regraded for all who’s score (not percentage) is less than 6 (out of 65). If your score is 6 or higher, but you feel.
Brandon Packard. Why make? So far, you have probably worked on relatively small projects Coding projects can become huge My research consists of 1600.
UNIX Development: g++ and make CS 2204 Class meeting 8 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
Makefiles Manolis Koubarakis Data Structures and Programming Techniques 1.
Multiple file project management & Makefile
Makefiles CSSE 332 Operating Systems
COM S 326X Deep C Programming for the 21st Century Prof. Rozier
The make utility (original presentation courtesy of Alark Joshi)
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
C-Shell with Functions
Brief Intro to Make CST494/ Gannod.
Compilation and Debugging
Compilation and Debugging
Shell Scripting March 1st, 2004 Class Meeting 7.
Makefiles Caryl Rahn.
Intro to PHP & Variables
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
Separate Compilation and Namespaces
Conditions and Ifs BIS1523 – Lecture 8.
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Makefiles and the make utility
Data Structures and Programming Techniques
Creating your first C program
Functional interface.
CMPSC 60: Week 4 Discussion
CSc 352: Elementary “make”
Lab 4: Introduction to Scripting
GNU Make.
Makefiles and the make utility
Compiler vs linker The compiler translates one .c file into a .o file
 A function is a named sequence of statement(s) that performs a computation. It contains  line of code(s) that are executed sequentially from top.
SPL – PS1 Introduction to C++.
The make utility (original presentation courtesy of Alark Joshi)
Presentation transcript:

Rake 4-Dec-18

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 order Some parts of the program may depend on other parts being up to date A UNIX makefile is a file that describes these dependencies UNIX make is a program that reads a makefile, determines the correct order in which to update files, and updates them Ruby programs are interpreted, not compiled; but... Rails uses metaprogramming to create source files and data files from other files Consequently, something like make is still needed rake provides the same functionality as make, but is implemented very differently

Rakefiles Rakefiles are written in Ruby  The following code fragment expresses that a file file_1 depends on files file_2 and file_3 file "file_1" => ["file_2", "file_3"] We can use this code fragment with a block that tells what to do with the dependency file "file_1" => ["file_2", "file_3"] do # code to create file_1 from file_2 and file_3 end A rakefile can consist simply of a number of these blocks Like make, rake looks at the modification dates of files and only updates them as necessary

First example, I This example uses C files as examples Suppose we have the files main.c, greet.h, and greet.c main.c is our usual “Hello World” program, but includes greet.h, which specifies a greet method (on greet.c) Our target (the file we want to build) is hello.o We have the following dependencies: file "main.o" => ["main.c", "greet.h"] file "greet.o" => ["greet.c"] file "hello" => ["main.o", "greet.o"] To create the target, we need to execute these commands: cc -c -o main.o main.c cc -c -o greet.o greet.c cc -o hello main.o greet.o

First example, II Here’s the rakefile: file 'main.o' => ["main.c", "greet.h"] do sh "cc -c -o main.o main.c" end file 'greet.o' => ['greet.c'] do sh "cc -c -o greet.o greet.c" end file "hello" => ["main.o", "greet.o"] do sh "cc -o hello main.o greet.o" end

Running rake The syntax for running a rake command is rake [options ...] [VAR=VALUE] [targets ...] Unless we use the option -f filename , rake will read its commands from a file named rakefile Our target (the thing we want to make) is named "hello" in this file, so (assuming the program on the previous slide is on a file named rakefile), we run rake by saying rake hello

Additional targets file targets check modification dates, hence these tasks are only done when needed Non-file tasks are always performed Non-file tasks use the task keyword instead of file We can specify a default task, such as "hello", like this: task :default => ["hello"] Other non-file tasks are: clean -- Remove temporary files created during the build process clobber -- Remove all files generated during the build process The Rake library implements clean and clobber for you, but you have to tell it what files to clean or clobber Do this with FileLists clean and clobber use the lists named CLEAN and CLOBBER, respectively Example: CLEAN = FileList["greet.o"] You can use wildcards: CLOBBER = FileList["*.o"]

Dynamically building tasks Example: SRC = FileList['*.c'] SRC.each do |fn| obj = fn.sub(/\.[^.]*$/, '.o') file obj do sh "cc -c -o #{obj} #{fn}" end end Notes: Remember that Ruby will do substitution in double-quoted strings The file list depends on the source files (.c files), because the object files (.o files) may or may not be present The dependencies between source and object files are specified elsewhere Rake can figure this out

Automatically building tasks Rather than dynamically building tasks, it’s usually easier just to generate them automatically For example, In C the object .o files depend on the source .c files, so we can say: rule '.o' => '.c' do |t| sh "cc -c -o #{t.name} #{t.source}" end

Final result require 'rake/clean' CLEAN.include('*.o') CLOBBER.include('hello') task :default => ["hello"] SRC = FileList['*.c'] OBJ = SRC.ext('o') rule '.o' => '.c' do |t| sh "cc -c -o #{t.name} #{t.source}" end file "hello" => OBJ do sh "cc -o hello #{OBJ}" end # File dependencies go here ... file 'main.o' => ['main.c', 'greet.h'] file 'greet.o' => ['greet.c']

Credit These slides cover only the most basic use of rake The extended example used in these slides is taken from http://docs.rubyrake.org/read/book/1 A more comprehensive explanation of rakefiles can be found at http://www.martinfowler.com/articles/rake.html

The End