LINUX System : Lecture 5 text editor, compilation (make), … Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University.

Slides:



Advertisements
Similar presentations
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.
Advertisements

A Guide to Unix Using Linux Fourth Edition
Editing with vi Or more fun than you thought you’d have without a mouse Prof. Chris GauthierDickey.
Program Development Tools IDE vs point tools Two tool flavors exist for developing embedded software: -IDEs: (Integrated Development Environments) i.e.,
CIS 240 Introduction to UNIX Instructor: Sue Sampson.
Vi Editor TA for ITIS3100: Xu Fei
Chapter 5 Editing Text Files
1 ENERGY 211 / CME 211 Lecture 2 September 24, 2008.
1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display.
Guide To UNIX Using Linux Third Edition
CS 497C – Introduction to UNIX Lecture 9: The vi/vim Editor Chin-Chih Chang
Starting Vi Opening an existing file vi filename Creating a new file vi filename In your workshop directory, create a new file called mysong vi mysong.
Lecture 8  make. Overview: Development process  Creation of source files (.c,.h,.cpp)  Compilation (e.g. *.c  *.o) and linking  Running and testing.
CSCI 330 T HE UNIX S YSTEM Editing files. E DITOR C ONCEPTS Editing a file is to modify the content of a file Text editor: Enter and modify text in a.
1 Unix Editors (ee, ed, ex, vi, vim) and Compilers (g77, gcc) Speaker: Li-Wen Chen Date:
Chapter 3 Mastering Editors
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
The UNIX development environment CS 400/600 – Data Structures.
T HE VI EDITOR. vi has 2 modes: command mode (initial or "default" mode) insert mode [Esc] is used to switch to command mode. In general, vi commands:
리눅스 : Lecture 5 UNIX 유틸리티 : text editor, compilation (make), …
Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2.
Adv. UNIX: large/131 Advanced UNIX v Objectives of these slides: –learn how to write/manage large programs consisting of multiple files, which.
Software I: Utilities and Internals Lecture 2 – The vi Text Editor * Modified from Dr. Robert Siegfried original presentation.
CS240 Computer Science II Introduction the Unix File System and File Related Utilities Based on “UNIX for Programmers and Users” by G.Class and K. Ables.
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.
Introduction to Vim Robbie CSCI2100 Data Structures Tutorial 3.
Chapter Ten g++ and make1 System Programming Software Development: g++ and make.
Text editors Why should I use an editor ? It is very important to able to use at least one text mode editor a text mode editor is so useful on remote machines.
Unix Editors. u Editors in Unix come in two general flavours: –modal editors have "modes" v generally input mode and command mode –input mode allows entry.
Tony Kombol.  Why text edit?  Many programs and features require configuration ▪ Configuration is kept in files ▪ Usually in the /etc directory  Changes.
Unix Session IV.
Basic Unix Commands CGS 3460, Lecture 6 Jan 23, 2006 Zhen Yang.
Text Editing February 2 nd, 2004 Class Meeting 3.
Chapter Three Text Editing1 System Programming Text Editing.
VI EDITOR University of Mississippi. Vi Editor What is Vi ? ▫Vi is a screen based editor. ▫The screen of your terminal will act as a window into the file.
1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.
Introduction to Unix (CA263) File Editing By Tariq Ibn Aziz.
Lesson 4-Mastering the Visual Editor. Overview Introducing the visual editor. Working in an existing file with vi. Understanding the visual editor. Navigating.
Chapter Three The UNIX Editors.
Isecur1ty training center Presented by : Eng. Mohammad Khreesha.
Chapter 12 C Programming Tools Graham Glass and King Ables, UNIX for Programmers and Users, Third Edition, Pearson Prentice Hall, Original Notes.
Text editing and more basic commands CS 2204 Class meeting 3 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
Makefiles CARYL RAHN. Separate compilation Large programs are generally separated into multiple files, e.g. main.c addmoney.c removemoney.c money.h With.
Vi editor Pronounced: `vee eye‘’. Agenda Describe the background of vi Editor Use vi editor to: create text files edit text files Our Goal is to create.
cs33201 Chapter 12 C Programming Tools Graham Glass and King Ables, UNIX for Programmers and Users, Third Edition, Pearson Prentice Hall, 2003.
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.
C P ROGRAMMING T OOLS. C OMPILING AND R UNNING S INGLE M ODULE P ROGRAM.
CSc 352 An Introduction to make Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
UNIX Development: g++ and make CS 2204 Class meeting 8 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
CS:414 introduction to Unix and Linux
The make utility (original presentation courtesy of Alark Joshi)
Brief Intro to Make CST494/ Gannod.
Makefiles Caryl Rahn.
Guide To UNIX Using Linux Third Edition
Computer Engineering 1nd Semester
Vi Editor.
Unix Fundamentals - Part iii vi Editor
Vim.
Vi Introduction Tony Kombol.
Linux 104 Training Module File Editing.
Lecture 3 More on editors: emacs and vi COP 3344 Introduction to UNIX.
IT244 - Introduction to Linux / Unix Instructor: Bo Sheng
Text Editors Vim (Chapter 6) Emacs (Chapter 7)
Chapter 2 Basic vi Editor.
CSCI The UNIX System Editing files
SPL – PS1 Introduction to C++.
The make utility (original presentation courtesy of Alark Joshi)
Presentation transcript:

LINUX System : Lecture 5 text editor, compilation (make), … Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University

vi One of the most popular text editor in UNIX O’Reilly says that its Vim tutorial sells twice as many copies as for Emacs Ubiquitous Runs on all UNIX machines Essentially all unix and unix-like systems come with vi built-in vim : extended version of vi

Text Editor in UNIX : vi To invoke vi, type “vi” in shell prompt $vi [file [file …]] Filename is often specified. It is not required to specifying filename

vi mode Input (insertion) mode Actually edit the text Command (escape) mode The keyboard input is interpreted as a command Mode switch Command ModeInput Mode ESC i, I, o, O, s, a key

Quit vi :wq Save current file and quit zz Same as :wp :q Just quit :q! Quit without save

Cursor movement h : move backward by letter j : move down to the next line k : move up to the previous line l : move forward by letter b : move backward by word w : move forward by word $ : move to the end of the current line ^ : move to the beginning of the current line Ctrl-F : move forward to next screen Ctrl-B : move backward to previous screen

Edit Mode Commands x delete the letter beneath the cursor r Replace current character u undo cw Change current word dw Delete current word Cut, Copy, Paste dd cut (delete) current line yy Copy current line p paste

Pattern search In command mode, press ‘/’ or ‘?’ and search pattern (a word or words) /search_pattern Search after cursor ?search_pattern Search before cursor

Line number Display line number :set number :set nu Remove line number :set nonumber :set nonu :1 Go to line 1 :25 Go to line 25

Switch to insertion mode i Insert characters a Append characters o Open a new line below the current line and add text I Insert text at the beginning of the current line A Add text to the end of the current line O Open a new line above the current line and add text

replace :s/pattern/replace Replace in currrent line :%s/pattern/replace Globally replace Example) :s/from/FROM

Other commands u Undo. redo J Join (merge) next line Copy lines :from,to y (ex) : 5,8 y

Execute shell command :!ls –l :!cat test.txt

File Save :w :w filename :wq

C/C++ compile UNIX itself was written in C Most UNIX utilities and applications were written in C/C++ It is hard to understand UNIX without understanding C/C++ Some UNIX has its own C/C++ compiler and some other UNIX do not. GNU C/C++ compiler is commonly used C compiler cc [-option] C-files gcc [-option] C-files

C/C++ compile $ gcc hello.c $ g++ hello.cpp Source codes (hello.c, hello.cpp) are compiled executable file (a.out) is created

Compile option -c $ gcc –c hello.c only object code hello.o is created. -o Specify the name of executable file $ gcc –o hello hello.c or $ gcc –o hello hello.o (when hello.o already exists) -g : debug mode

Compile Option -O, -O[level 0~3] Optimization $ gcc –O –o hello hello.c -Os : size 최적화 -S generates code with assembly language $ gcc –S hello.c ( generates hello.s )

Compile Option -E 전처리 과정 결과를 화면에 보이는 옵션 -v 컴파일 과정 출력 -D[ 매크로 ], -D[ 매크로 ]=[ 매크로값 ] > gcc –DDEBUG –o like like.c > gcc –DPACKAGE=\”likeU\” –o like like.c

Compile Option -l link a library -lxyz means linking libxyz.a -lm means linking libm.a $ gcc –o math_hello math_hello.c –lm -I Specify include path for preprocessor Example) -I /usr/include - L Specify library path for preprocessor Example) –L /usr/lib

Library 만들기 Library 미리 컴파일된 object 파일의 집합 자주 사용하는 함수들을 모아두어 쉽게 사용하는 것이 목적 프로그램에 Link 하여 사용 “ar” command > gcc –c file1.c file2.c > ar r libmy.a file1.o file2.o # libmy.a 생성됨 > gcc –o like like.c –L./ -lmy

Multi-Module Program One program consists of multiple number of source files. Problem of single-module program Multiple number of programmers cannot participate in the development Hard to reuse ( ex. Function reusability )

Multi-Module Program Main module + modules with reusable funcitons Modules with reusable functions In header (.h) file Function prototype Constant definition Global variable declaration In source (.c,.cpp) file Function implementation

Multi-Module Program Compile each module with –c option and create object filess (.o) $ gcc –c hello1.c $ gcc –c hello2.c Link each object files to create an executable file $ gcc –o hello hello1.o hello2.o

Compile Multi-Module Program $ gcc –o prog1 file1.c file2.c file3.c Effective Compilation Compile only the modified source files and source files that are dependent on the modified source files. Consider dependency Use make utility

Makefile Makefile specifies dependency of source files for correct and effective compilation $make [-f makefile_name] Default : makefile or Makefile as input

Makefile To manage executable file using “make”, Makefile must be created first Makefile includes interdependency list of source files Makefile sometimes has.mk suffix Makefile format targetList: dependencyList commandList targetList : object file (or executable file) list dependencyList : or files that are dependent on the files in targetList commandList : command that generates object file from files in dependencyList commandList should start with “tab”

Makefile Example prog1: file1.o file2.o file3.o gcc –o prog1 file1.o file2.o file3.o # if one of file1.o, file2.o, and file3.o is modified, #, above linking is performed to (re)generate “prog1” file1.o: file1.c mydefs.h gcc –c file1.c # if one of file1.c and mydefs.h is modified, # above compilation is performed to generate file1.o file2.o: file2.c mydefs.h gcc –c file2.c file3.o: file3.c gcc –c file3.c clean : rm file1.o file2.o file3.o

Make : dependency tree Executable file becomes root of the tree Target becomes parent node, and dependency files become children nodes. initial dependency tree prog1 file1.ofile2.ofile3.o final dependency tree prog1 file1.ofile2.ofile3.o file1.cmydefs.h file2.cfile3.c

Compilation Steps make finds the first target “prog1” and sees that it depends on the object files file1.o file2.o file3.o make next looks to see if any of the three object files are listed as targets. They are so make looks at each target to see what it depends on. make sees that file1.o depends on the files file1.c and mydefs.h. Now make looks to see if either of these files are listed as targets and since they aren't file1.o 가 이미 존재하지 않은 경우 : it executes the commands given in file1.o's rule and compiles file1.c to get the object file. file1.o 가 이미 존재하는 경우 dependent file 의 수정 시간이 file1.o 의 수정시간 이전일 경우 : do nothing dependent file 의 수정 시간이 file1.o 의 수정시간 이전일 경우 : file1.o 생성룰 실행 make looks at the targets file2.o and file3.o and compiles these object files in a similar fashion. make now has all the object files required to make prog1 and does so by executing the commands in its rule.

Phony Target Target that is not a name of a file Just have a list of commands to execute Common example : removing all object files clean : rm *.o > make clean

Macro Example OBJS = file1.o file2.o file3.o CC = gcc prog1 : ${OBJS} ${CC} –o prog1 ${OBJS} file1.o : file1.c mydefs.h ${CC} –c file1.c file2.o : file2.c mydefs.h ${CC} –c file2.c file3.o : file3.c ${CC} –c file3.c clean : rm ${OBJS} Command line macro % make prog1 DEBUG_FLAG=-g

Internal Macro Internally defined macros are ones that are predefined in make make –p CXX = CC CXXFLAGS = -O GFLAGS = CFLAGS = -O CC = cc LDFLAGS = LD = ld LFLAGS = MAKE = make MAKEFLAGS = b

Suffix Rule / Pattern Rule “make” has a set of default rules to build a program (ex) for c program,.o object files are made from.c source files The suffix rule that make uses for a C program is.c.o : ${CC} –c $< $< means the source file of the current (single) dependency. Note that the same could be done using pattern rule : %.o: %.c ${CC} -c $< # %.c means every file with suffix.c make -p

Shortened Makefile OBJS = file1.o file2.o file3.o prog1 : ${OBJS} ${CC} -o ${OBJS} # CC is internally defined # means current target filename file1.o file2.o : mydefs.h clean : rm ${OBJS}