Building programs LinuxChix-KE. What happens in your CPU? ● It executes a small set of instructions called "machine code" ● Each instruction is just a.

Slides:



Advertisements
Similar presentations
Configuration management
Advertisements

Software Development Languages and Environments. Programming languages High level languages are problem orientated contain many English words are easier.
Linux vs. Windows. Linux  Linux was originally built by Linus Torvalds at the University of Helsinki in  Linux is a Unix-like, Kernal-based, fully.
Java.  Java is an object-oriented programming language.  Java is important to us because Android programming uses Java.  However, Java is much more.
1 Real-Time System Design Developing a Cross Compiler and libraries for a target system.
CS 104 Introduction to Computer Science and Graphics Problems Software and Programming Language (2) Programming Languages 09/26/2008 Yang Song (Prepared.
Copyright Arshi Khan1 System Programming Instructor Arshi Khan.
Systems Software Operating Systems.
Linux Basics CS 302. Outline  What is Unix?  What is Linux?  Virtual Machine.
Lesson 4 Computer Software
CCSA 221 Programming in C CHAPTER 2 SOME FUNDAMENTALS 1 ALHANOUF ALAMR.
Parts of a Computer Why Use Binary Numbers? Source Code - Assembly - Machine Code.
Linux Operations and Administration
Systems Software & Operating systems
Standard Grade Computing System Software & Operating Systems.
CHAPTER FOUR COMPUTER SOFTWARE.
Introduction to Interactive Media Interactive Media Tools: Software.
Makefiles CISC/QCSE 810. BeamApp and Tests in C++ 5 source code files After any modification, changed source needs to be recompiled all object files need.
Introduction Use of makefiles to manage the build process Declarative, imperative and relational rules Environment variables, phony targets, automatic.
1 What is a Kernel The kernel of any operating system is the core of all the system’s software. The only thing more fundamental than the kernel is the.
Software – Applications software and programming languages.
CE Operating Systems Lecture 3 Overview of OS functions and structure.
Operating System What is an Operating System? A program that acts as an intermediary between a user of a computer and the computer hardware. An operating.
Introduction Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
What is a port The Ports Collection is essentially a set of Makefiles, patches, and description files placed in /usr/ports. The port includes instructions.
 Programming - the process of creating computer programs.
Chapter 9: Networking with Unix and Linux. Objectives: Describe the origins and history of the UNIX operating system Identify similarities and differences.
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
Chapter 1 Basic Concepts of Operating Systems Introduction Software A program is a sequence of instructions that enables the computer to carry.
11 Computers, C#, XNA, and You Session 1.1. Session Overview  Find out what computers are all about ...and what makes a great programmer  Discover.
ITP 109 Week 2 Trina Gregory Introduction to Java.
GNU Make Computer Organization II 1 © McQuain What is make ? make is a system utility for managing the build process (compilation/linking/etc).
OCR A Level F453: The function and purpose of translators Translators a. describe the need for, and use of, translators to convert source code.
LINUXCHIX WEBMAIL. Software run by an ISP or online service that provides access to send, receive, and review using only your Web browser. Users.
A Brief Introduction to Linux Cheng-Han Du. History.
OPERATING SYSTEMS DO YOU REQUIRE AN OPERATING SYSTEM IN YOUR SYSTEM?
UNIX U.Y: 1435/1436 H Operating System Concept. What is an Operating System?  The operating system (OS) is the program which starts up when you turn.
System is a set of interacting or interdependent components forming an integrated whole.
Unit 3 Computer Systems. What is software? unlike hardware it can’t be physically touched it’s the missing link between the computer hardware and the.
MET4750 Techniques for Earth System Modeling MET 5990 Techniques for Earth System Modeling and Research (
FreeBSD ports & packages. FreeBSD ports & packages - overview Different UNIX distributions use differents package systems for distributing software Debian.
Topic 2: Hardware and Software
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha Fall 2015
Introduction to programming
System Software EIT, © Author Gay Robertson, 2016.
Welcome to Linux Chap#1 Hanin Abdulrahman.
CPSC 315 – Programming Studio Spring 2012
Managing Software.
Application Development Theory
Teaching Computing to GCSE
Unit# 8: Introduction to Computer Programming
TRANSLATORS AND IDEs Key Revision Points.
Teaching Computing to GCSE
Programming Languages
Portability CPSC 315 – Programming Studio
Chapter 2: System Structures
Operating Systems Lecture 4.
Chapter 2: The Linux System Part 1
IS3440 Linux Security Unit 7 Securing the Linux Kernel
Lesson Objectives Aims Key Words Compiler, interpreter, assembler
Overview Unit testing Building Version control.
Chapter 2: Operating-System Structures
Outline Chapter 2 (cont) OS Design OS structure
FreeBSD ports & packages
Welcome to Linux Chap#1 Hanin Abdulrahman.
Section 1: Linux Basics and SLES9 Installation
Welcome to Linux Chap#1.
Chapter 2: Operating-System Structures
Chapter 3 Software.
Presentation transcript:

Building programs LinuxChix-KE

What happens in your CPU? ● It executes a small set of instructions called "machine code" ● Each instruction is just a pattern of bits ● Fast for computer to run – Modern processors run at gigahertz clock speeds: billions of instruction cycles per second ● Machine code is hard to read and write!

Let's look at some! ● A machine code program is informally known as "a binary" ● Example: our familiar /bin/ls less /bin/ls hexdump -C /bin/ls | less ● It's mostly binary code. There may be some text strings which the author included strings /bin/ls | less ● We can extract some more info: file /bin/ls ldd /bin/ls

How are binaries created? ● You can write them by hand, using assembly language – Done where speed is critical, e.g. some parts of kernel, some games – Called "low level" programming – Problem: different types of CPU have different machine codes; rewrite same program many times ● Or, you can write in a "high level" language, and then convert this to machine code ● The process is called "compiling"

Points to note ● You have to compile the program before you can run it ● Different systems have their own compilers – with care, you can write "portable" software which can be compiled on many different systems ● Compilers are programs themselves ● The machine-code generated by a compiler may not be as efficient as the code written by a good human

High level languages ● 'C' has a close relationship with Unix – Unix itself is written in C – With some work, Unix can be recompiled ("ported") for different processors – Not a very high level: you are still dealing closely with the Unix interface – Quite efficient machine code can be generated ● Many other languages exist – Higher-level languages can make the programmer's life easier but may run less efficiently – Different compiler for each one

Exercise 1: your first 'C' program ● Write a small program in C ● Compile it using the GNU C Compiler (gcc) ● Run it! ● Look at the binary

Source code ● The high-level version you write is called source code ● "Open source" (also called “free software”) – The author gives you the source code – Allows you to compile the software on different platforms – Allows you to see how it works and to make modifications ● "Closed source" – You are provided with binaries only – Very hard to read, very hard to change

Automated building ● A large application has many source files, and many commands are needed to build and link the individual parts ● When you change one source file, it might not be necessary to recompile everything – would be a waste of time ● So program writers tend to automate building using 'make'

Format of a Makefile ● Contains rules which say: – What file you are building (the "target") – What sources it comes from – The command needed to build it ● These rules are in a file called 'Makefile' ● When you run 'make', it works out which files to rebuild by looking at modification times – If any source file has a timestamp later than the target, the target needs to be rebuilt

Exercise 2: your first Makefile ● Create a Makefile for your application ● Change the source, use 'make' to rebuild it ● Run the binary to test

Point to note... ● There are different versions of 'make' ● BSD make and GNU make are different; Linux tends to come with GNU make ● But if you need it, you can install GNU make on your system (package "gmake")

Making portable applications ● There have been many different flavours of Unix released over time ● Programs need subtle changes to compile on different platforms – e.g. a particular feature may be available on one system but not another, or may work differently ● Often means changes to the Makefile for different targets ● Programmers can write a different Makefile for each OS... but it's a lot of work!

A solution - auto configuration ● run a shell script before you compile, which tests the system features available and writes out a suitable Makefile ● Most popular example: GNU autoconf – program author uses 'autoconf' to write the script – the script is called 'configure' and is distributed with the program – it takes template files and writes out the final versions (e.g. 'Makefile.in' is rewritten as 'Makefile')

So a typical build operation is:./configure make make install (as root)

autoconf also lets you set compile-time options ● e.g. software might normally install in '/usr/local' but you can force it elsewhere./configure --prefix=/opt ● You may also be able to disable or enable certain features in the final application ● Author usually documents the options in an INSTALL or README file

autoconf is not perfect ● It's a shell script – not all shells work identically – relies on programs in /bin and /sbin (which may vary between OSes) ● It's hard to write your own autoconf script – we won't attempt this – this is not a programming course anyway ● But generally it works well – a lot of work has gone into making autoconf work on a wide range of popular platforms

Where can you find open-source software to install? ● is a good index ● Use the web, use mailing lists ● There are advantages of downloading, compiling and building it yourself – You can get the very latest versions – You have full control over how it is built ● Main disadvantage is it can be difficult to uninstall – Might have to locate all the files which were installed, and remove them by hand

The FreeBSD ports collection ● Thousands of programs already catalogued ● Fully automates the process of downloading the source, unpacking, configuring, building, installing ● Applies any necessary patches to work under FreeBSD ● Tends to configure them consistently – /etc/rc.conf and /usr/local/etc/rc.d/* ● Records the installed files, so you can remove them using pkg_delete

Disadvantages of ports? ● It's BSD-specific ● Software version in the ports system is not always the latest ● When upgrading one port, you may end up updating others it depends on

FreeBSD packages ● These are actually just ports which have been compiled by someone else ● Easy to install: pkg_add ● No compilation time required – Esp. for huge programs: KDE, OpenOffice etc ● However, you don't have any control over compilation options ● Dependency issues – package foo-x.x.x requires package bar-y.y.y

FreeBSD itself is open source ● You can install (if you want) the source code – /usr/src/sys is the kernel – /usr/src/bin is the source for /bin programs – /usr/src/usr.bin is the source for /usr/bin programs –... etc ● You can rebuild individual parts, or the whole operating system – choose drivers, optimise for your CPU type,... ● Convenient if only one small component needs to be modified and rebuilt – e.g. a security advisory

Rebuilding /bin/ls # cd /usr/src/bin/ls # make # make install

Rebuilding the kernel ● Can remove unnecessary device drivers to save RAM – the GENERIC kernel contains lots of them – all drivers are built as loadable modules anyway ● Can add or remove features: e.g. firewalling, IPv6, IPSEC ● Can optimise kernel for your particular CPU – GENERIC kernel runs on 486 upwards

Exercise 3 ● Configure a new kernel ● Build and install it