760 likes | 917 Views
INF160 IS Development Environments AUBG, COS dept. Lecture 05 Title: Tools for Building Software (Extract from Syllabus) Reference: Doar, Chap 5. Lecture Contents:. Intro to Building Software How SW gets built Using separate command line statements
E N D
INF160 IS Development Environments AUBG, COS dept Lecture 05 Title: Tools for Building Software (Extract from Syllabus) Reference: Doar, Chap 5
Lecture Contents: • Intro to Building Software • How SW gets built • Using separate command line statements • Using batch processing (MSDOS *.bat files) • Using MAKE-like utilities • Exploring the Project concept within IDE
Instead of Introduction • SDLC = ISLC = PDM • Discussed: 4 stages or 6 – 7 -12 stages • Building Software Cycle • Describes how a source code is converted into an executable program, that can run on a computer • The process of converting source code into executable program is “Building Software”.
Instead of Introduction • Source code is what developers write in HLL (VB, C++, C#, Java) or in scripting languages (Perl, Python), or in low level language (Assembly language). • Building SW or simply Build is the process in which a build tool uses other tools (text editors, compilers, interpreters, linkers, loaders) to convert the source code into working product to be used by other people.
Instead of Introduction • This lecture presents classification of build tools including • Techniques • Technologies For Building Software.
Build tools classified • Using separate command line OS statements. • Using batch processing (*.bat files) • Using special purpose utilities (make, jar, ant,…) • Exploring the solution/project concept (IDEs)
Using separate command line statements • No need to discuss. • Just to remind: introductory lecture on PL INF160lec03. • Separate command line statement used to invoke: • Text editor (Notepad, WordPpad, TextPad) • Compiler (vbc, cl, csc, javac) • Interpreter (java) • Execution of user application
Running text editor from command window To use NotePad, type notepad <file name> from the DOS prompt. To use WordPad, type write <file name> from the DOS prompt.
Compiling and Running VB programs • Using any text editor, type the source text of a VB demo program like this: Module myModule Sub Main() Console.WriteLine(“Hello from VB”) Console.ReadLine() End Sub End Module • Save the VB program as prog1.vb file.
Compiling and Running VB programs • The VB compiler is named vbc. • Run the compiler with statement like this: vbc prog1.vb • Run the application with a statement like this: prog1
Compiling and Running C++ programs • Using any text editor, type the source text of a C++ demo program like this: #include <iostream> using namespace std; void main() { cout << endl <<"Hello from C++"<<endl; system("pause"); } • Save the C++ program as prog2.cpp file.
Compiling and Running C++ programs • The C++ compiler is named cl. • Run the compiler with statement like this: cl prog2.cpp • Run the application with a statement like this: prog2
Compiling and Running C# programs • Using text editor, type the source text of a C# demo program like this: using System; namespace myNamespace { public class myClass { public static void Main(string[] args) { Console.WriteLine("Hello from C#"); Console.ReadLine(); } // end of Main } // end of class } // end of namespace Save the C# program as prog3.cs file.
Compiling and Running C# programs • Using any text editor, type the source text of a C# demo program like this: // no using System; namespace myNamespace { public class myClass { public static void Main(string[] args) { System.Console.WriteLine("Hello from C#"); System.Console.ReadLine(); } } } Save the C# program as prog3.cs file.
Compiling and Running C# programs • The C# compiler is named csc. • Run the compiler with statement like this: csc prog3.cs • Run the application with a statement like this: prog3
Compiling and Running Java programs • Using any text editor, type the source text of a Java demo program like this: public class prog4 { public static void main(String[] args) { System.out.println("Hello from Java"); } } • Save the Java program as prog4.java file.
Compiling and Running Java programs • The Java compiler is named javac. • Run the compiler with statement like this: javac prog4.java • Run the application with a statement like this: java prog4
Practical session 1 • Create your version of 4 demo programs in VBasic, CPP, C# and Java • Save the files as • Prog1.vb • Prog2.cpp • Prog3.cs • Prog4.java • Call the OS command line statements to activate the compilers • Run the executable code generated by the compilers • How many command line statements do you need?
Using batch processing (MSDOS *.bat files) • Using .bat files, one may achieve same effect as described on previous slide typing one only stmt • How? • The .bat file contents are structured to include OS command line statements in proper order
Using batch processing (MSDOS *.bat files) Given a list of four command line statements: C:\>Edit Proba.xxx C:\>Compiler Proba.xxx C:\>Linker Proba.obj C:\>Proba.exe Drawback: The user has to type 4 times one command line statement. In order to avoid it, batch processing is introduced.
Using batch processing (MSDOS *.bat files) All the OS commands are saved in a batch file (.bat). fileProc1.batcontents:Edit Prog.xxx Compiler Prog.obj Linker Prog.obj Prog.exe Running the bat file: C:\>Proc1 Advantage: the user types one only command, but all 4 steps are processed Restriction: this bat file operates only on program named Prog How to achieve more flexibility? See next slide
Using batch processing (MSDOS *.bat files) Bat files and parameter processing using %1 … %10 notation: Example 1: File Proc2.batcontents: Edit %1.cpp Bcc %1 %1 Running the bat file:C:\>Proc2 Prog1 C:\>Proc2 Prog2 C:\>Proc2 Prog3
Using batch processing (MSDOS *.bat files) Example 2:FileProc3.batcontents: Edit %1.cpp Bcc -c %1 Tlink %1.obj+C0S.obj,,,\LIB\Cs.lib %1 To run the .bat file:C:\>Proc3 Prog1 C:\>Proc3 Prog2 C:\>Proc3 Prog3
Practical session 2 • Create 4 batch processing files including OS command line statements to edit, compile and run your VBasic, CPP, C# and Java programs • Save the files as • VBasicBat1.bat • CppBat1.bat • CsharpBat1.bat • JavaBat1.bat • Call the .bat file name as OS command line statements • All the commands from within the bat file are being executed • How many command line statements do you need?
Practical session 2 • Sample .bat file oriented to process VBasic source program saved as file prog1.vb: • .bat File name: VBasicBat1.bat • .bat File contents: dir notepad prog1.vb dir vbc prog1.vb dir prog1.exe • How to call the .bat file: VBasicBat1
Practical session 2 • Sample .bat file oriented to process any VBasic program saved as .vb file • .bat File name: VBasicBat2.bat • .bat File contents: notepad %1.vb vbc %1.vb %1.exe • How to call the .bat file: VBasicBat2 prog1 VBasicBat2 prog11
Practical session 2 • Follow the same style and build a pair of .bat files oriented to process C++ programs: CppBat1.bat CppBat2.bat
Practical session 2 • Follow the same style and build a pair of .bat files oriented to process C++ programs: CsharpBat1.bat CsharpBat2.bat
Practical session 2 • Follow the same style and build a pair of .bat files oriented to process Java programs: JavaBat1.bat JavaBat2.bat
Practical session 3 • Write a program to read two integer values and to display: • their sum as a result and • the factorial of the result. • Save the source texts as • Prog11.vb • Prog22.cpp • Prog33.cs • Prog44.java • Build the corresponding executables using batch processing.
Lecture part 2 • Building Software Tools • Part 2
Using MAKE-like utilities • Drawback of batch processing: • All commands within the .bat file are always executed, are unconditionally executed • No check of the dependency tree for the current program • Instead of running all programs, it is an attractive idea to run those commands only that are must because of partial changes in the source code
Using MAKE-like utilities • How to eliminate the .bat files drawback? • We need a tool to trace the dependency tree for the SW project: how the file components of a SW project depend on each other • The well known and popular tool to achieve the formulated goal is the make utility program
Using MAKE-like utilities • The Windows version of make utility program is known as nmake.exe • The commands expected to be run under make control are saved in advance into an input file usually named makefile or Makefile or any file name whose extension is .mak.
Using MAKE-like utilities • The input file contents include a collection of: • Comment lines, • Macro definitions • Rules and • OS command line statements.
Using MAKE-like utilities • Comment lines serve to inform the user • Comments are ignored by the utility program • Each comment line starts with #
Using MAKE-like utilities • Macro definitions serve for simple preprocessing text substitution before the main activities start running. • Macro definition format: MacroName = SubstitutionText • Macro reference or macro call format $(MacroName)
Using MAKE-like utilities • Rules describe the dependency btw the file components of the project using the following format <target> : <source(s)> <target> is written starting from beginning of the current line. No leading spaces allowed.
Using MAKE-like utilities • Commands are command line statements that follow the rule and are to be executed in order to achieve the goal (target). Each command is preceded by the tab ‘\t’ ctrl character.
Examples of MAKE input file contents # makefilefeep1 # to test make with LEX, YACC and C compiler # 3 rules. Each has a separate unique one command # # rule 1 a.out : y.tab.c lex.yy.c cc y.tab.c lex.yy.c # rule 2 y.tab.c : FeepProektm.y yacc -d FeepProektm.y # rule 3 lex.yy.c : FeepProektm.lex lex FeepProektm.lex
Examples of MAKE input file contents # to test make with FLEX, Bison and C compiler # 3 rules. Each rule has a separate unique command # a.out : FeepProektm.tab.c lex.yy.c cc FeepProektm.tab.c lex.yy.c FeepProektm.tab.c : FeepProektm.y bison -d FeepProektm.y lex.yy.c : FeepProektm.lex flex FeepProektm.lex
Examples of MAKE input file contents # Clean up everything cleanall : clean -del *.exe # Clean up everything but the .EXEs clean : -del *.obj -del *.map -del hello_c.c -del hello_s.c -del hello.h
Using MAKE-like utilities • Example: to prepare contents of a make input file oriented to process VBasic program saved as a file prog1.vb. • Makefile contents: # this is a demo make file prog1.exe : prog1.vb vbc prog1.vb • How to activate make utility: C:\>nmake /f MakeFile
Using MAKE-like utilities • Example: to prepare contents of a make input file including macro definition and macro reference oriented to process VBasic program saved as a file prog1.vb. • Makefile contents: # this is a demo make file FilName = prog1 $(FilName).exe : $(FilName).vb vbc $(FilName).vb • How to activate make utility: C:\>nmake /f MakeFile
Using MAKE-like utilities • Protocol of running nmake: