SlideShare a Scribd company logo
Chapter 11.
PROGRAMMING LINUX
LINUX AND OPEN SOURCE SOFTWARE
1-1
Contents
 Using programming tools
 Using GNU C Compiler (gcc)
 Project management tools: make, automake, autoconf
 Graphical DevelopmentTools
• IDEs and SDKs
• Kdevelp Client
 Using popular languages
 Java
 Javascript
 PHP
 Python
 Etc.
1-2
Using GNU C Compiler (gcc)
 “GNU is an extensive collection of free software (383
packages as of January 2022), which can be used as an
operating system or can be used in parts with other operating
systems” (Wikipedia).
 GNU cc (gcc) is the GNU project’s compiler suite. It
compiles programs written in C,C++, or Objective C.
 The gcc features
 Preprocessing
 Compilation
 Assembly
 Linking
1-3
Example: gcc
1-4
1. /*
2. * Listing 3.1
3. * hello.c – Canonical “Hello, world!” program 4 4 */
4. #include <stdio.h>
5. int main(void)
6. {
7. fprintf(stdout, “Hello, Linux programming world!n”);
8. return 0;
9. }
$ gcc hello.c -o hello
$ ./hello
Hello, Linux programming world!
Complie and run
1-5
$ gcc –E hello.c -o hello.cpp
$ gcc -x cpp-output -c hello.cpp -o hello.o
Stop compilation
after pre-procesing
See content of stdio.h and
compile to an object code
$ gcc hello.o -o hello
Link the object file
$ gcc killerapp.c helper.c -o killerapp
Use code from
other file
1-6
Project management using GNU make
 Projects composed of multiple source files typically
require long, complex compiler invocations.
 make simplifies this by storing these difficult command lines in
the Makefile
 make also minimizes rebuild times because it is smart enough to
determine which files have changed, and thus only rebuilds files
whose components have changed
 make maintains a database of dependency information for your
projects and so can verify that all of the files necessary for
building a program are available each time you start a build.
1-7
Writing Makefiles
 A makefile is a text file database containing rules that tell
make what to build and how to build it.A rule consists of
the following:
 A target, the “thing” make ultimately tries to create
 A list of one or more dependencies, usually files, required to
build the target
 A list of commands to execute in order to create the target
from the specified dependencies
 Makefile
1-8
target : dependency dependency [...]
command
command
[...]
Makefile examples
 It is the makefile for building a text editor imaginatively
named editor
1-9
1 editor : editor.o screen.o keyboard.o
2 gcc -o editor editor.o screen.o keyboard.o
3
4 editor.o : editor.c editor.h keyboard.h screen.h
5 gcc -c editor.c
6
7 screen.o : screen.c screen.h
8 gcc -c screen.c
9
10 keyboard.o : keyboard.c keyboard.h
11 gcc -c keyboard.c
12
13 clean :
14 rm editor *.o
To compile editor, you would simply type make in the directory where the makefile
exists.
Default target
Dependencies
Rules
Target
Makefile excercise
 Examine the example Makefile 1 in
1-10
https://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/
Makefile: variable
 To simplify editing and maintaining makefiles, make allows
you to create and use variables.
 To obtainVARNAME’s value, enclose it in parentheses and
prefix it with a $:
1-11
VARNAME = some_text [...]
$(VARNAME)
Makefile: variable
1-12
1 OBJS = editor.o screen.o keyboard.o
2 HDRS = editor.h screen.h keyboard.h
3 editor : $(OBJS)
4 gcc -o editor $(OBJS)
5
6 editor.o : editor.c $(HDRS)
7 gcc -c editor.c
8
9 screen.o : screen.c screen.h
10 gcc -c screen.c
11
12 keyboard.o : keyboard.c keyboard.h
13 gcc -c keyboard.c
14
15 .PHONY : clean
16
17 clean :
18 rm editor $(OBJS)
Variables
Default target
Rules
PHONY to skip checking filename “clean”
Environment,Automatic, PredefinedVariables
 make allows the use of environment variables
 make reads every variable defined in its environment and
creates variables with the same name and value
 make provides a long list of predefined and automatic
variables, too.
1-13
AUTOMATIC VARIABLES
Variable Description
$@ The filename of a rule’s target
$< The name of the first dependency in a rule
$^ Space-delimited list of all the dependencies in a rule
$? Space-delimited list of all the dependencies in a rule that are newer thanthe
target
$(@D) The directory part of a target filename, if the target is in a subdirectory
$(@F) The filename part of a target filename, if the target is in a subdirectory
PREDEFINED VARIABLES
Variable Description
AR Archive-maintenance programs; default value = ar
AS Program to do assembly; default value = as
CC Program for compiling C programs; default value = cc
CPP C Preprocessor program; default value = cpp
RM Program to remove files; default value = “rm -f”
ARFLAGS Flags for the archive-maintenance program; default = rv
ASFLAGS Flags for the assembler program; no default
CFLAGS Flags for the C compiler; no default
CPPFLAGS Flags for the C preprocessor; no default
LDFLAGS Flags for the linker (ld); no default
1-14
Excercise
 Examine the example Makefile 2 in
1-15
https://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/
Implicit Rules
 make comes with a comprehensive set of implicit, or
predefined, rules
1-16
1 OBJS = editor.o screen.o keyboard.o
2 editor : $(OBJS)
3 cc -o editor $(OBJS)
4
5 .PHONY : clean
6
7 clean :
8 rm editor $(OBJS)
the makefile lacks
rules for building
targets
(dependencies)
make will look for C source files named editor.c, screen.c, and keyboard.c,
compile them to object files (editor.o, screen.o, and keyboard.o), and finally,
build the default editor target.
Pattern Rules
 Pattern rules look like normal rules, except that the
target contains exactly one character (%) that matches
any nonempty string.
1-17
%.o : %.c
tells make to build any object file somename.o from a source file somename.c.
%.o : %.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
It defines a rule that makes any file x.o from x.c.
This rule uses the automatic variables $< and $@ to substitute the names of the
first dependency and the target each time the rule is applied. The variables
$(CC), $(CFLAGS), and $(CPPFLAGS)
Excercise
 Examine the example Makefile 3 & Makefile 4 in
1-18
https://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/
Useful Makefile Targets
 make
1-19
• clean
• install
• uninstall
• dist
• test
• archive
• bugreport
# a sample makefile for a skeleton program
CC= gcc
INS= install
INSDIR = /usr/local/bin
LIBDIR= -L/usr/X11R6/lib
LIBS= -lXm -lSM -lICE -lXt -lX11
SRC= skel.c
OBJS= skel.o
PROG= skel
skel: ${OBJS}
${CC} -o ${PROG} ${SRC} ${LIBDIR} ${LIBS}
install: ${PROG}
${INS} -g root -o root ${PROG} ${INSDIR}
Excercise
 Examine the example Makefile 5 in
1-20
https://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/
GNU Automake
 The primary goal of Automake is to generate ‘Makefile’ in
compliant with the GNU Makefile Standards.
 A secondary goal for Automake is that it work well with
other free software, and, specifically, GNU tools.
 Automake helps the maintainer with five large tasks, and
countless minor ones.The basic functional areas are:
• Build
• Check
• Clean
• Install and uninstall
• Distribution
1-21
Building configure.in (or configure.ac)
 The configure script ‘configure.in’ is responsible for
getting ready to build the software on your specific
system. It makes sure all of the dependencies for the rest
of the build and install process are available, and finds out
whatever it needs to know to use those dependencies.
 A configure script ‘configure.in’ examines your system,
and uses the information it finds to convert
a Makefile.in template into a Makefile
 To run the configure script
1-22
./configure
Building configure.in (or configure.ac)
1-23
AC_INIT (package, version, bug-report-address)
AC_OUTPUT([file...[,extra_cmds[,init_cmds]]])
Invoke before any test
Invoke after any test
unique_file_in_source_dir is a file present in the source code directory. The call to
AC_INIT creates shell code in the generated configure script that looks for
unique_file_in_source_dir to make sure that it is in the correct directory.
AC_OUTPUT creates the output files, such as Makefiles and other (optional) output
files
file is a space separated list of output files.
Configure.in
Structuring the file Configure.ac
1-24
AC_INIT
Tests for programs
Tests for libraries
Tests for header files
Tests for typedefs
Tests for structures
Tests for compiler behavior
Tests for library functions
Tests for system services
AC_OUTPUT
Configure.in
Tests for Programs
1-25
Tests for Library Functions
1-26
Tests for Header Files
1-27
Tests for Structures
1-28
Tests for typedefs
1-29
Tests of Compiler Behavior
1-30
Tests for System Services
1-31
Using the autoconf
 This program builds an executable shell script named
configure (from configure.in) that, when executed,
automatically examines and tailors a client’s build from
source according to software resources, or dependencies
(such as programming tools, libraries, and associated
utilities) that are installed on the target host (your Linux
system).
1-32
Example
1-33
#include <stdio.h>
int
main(int argc, char* argv[])
{
printf("Hello worldn");
return 0;
}
AC_INIT([helloworld], [0.1], [george@thoughtbot.com])
AM_INIT_AUTOMAKE
AC_PROG_CC
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
AUTOMAKE_OPTIONS = foreign
bin_PROGRAMS = helloworld
helloworld_SOURCES = main.c
Helloworld.c Configure.in
Makefile.am
aclocal #generate m4 env
autoconf #generate configure
automake –add-missing
configure
Makefile.in
./configure # Generate Makefile from Makefile.in
make # Use Makefile to build the program
make install # Use Makefile to install the program
Graphical DevelopmentTools
 Ubuntu has a number of graphical prototyping and
development environments available
 integrated development environment (IDE)
• Eclipse
• NetBeans
• Visual Studio Code
• Oracle JDeveloper
 software development kit (SDK)
• Android development SDK
 the KDevelop Client (for Developing in KDE)
 The Glade Client (for Developing in GNOME)
1-34
Exercise
 Download and install Eclipse IDE for C/C++ (or Java, PHP, etc.)
 Check for Java installed: java –version
• Sudo apt install default-jre
 Check OS type (64/32bit): uname -a
 Download Eclipse C/C++ tarball file from
https://www.eclipse.org/downloads/eclipse-packages/
 Extract and install
• tar –xf <tarball file.gz>
 Run Eclipse: ./eclipse
 Set PATH to run from $HOME directory
• PATH = $PATH:$HOME/<install directory>
1-35
Note: to permanently set PATH env, edit file $HOME/.profile
Eclipse
1-36
Using Java on Linux
 Most Java development occurs in an IDE
 Eclipse (www.eclipse.org)
 NetBeans (www.netbeans.org)
1-37
Using JavaScript
 To use JavaScript on Ubuntu, you write programs in your
favorite text editor. Nothing special is needed.
 Put the script somewhere and open it with your web
browser.
 Information is often passed using JavaScript Object
Notation, or JSON
 JavaScript has spawned tons of extensions and
development kits, such as Node.js and JSP.
1-38
Using JavaScript
 Node.js
 Node.js is a popular JavaScript framework used for developing
server side applications.
1-39
sudo apt-get install nodejs
sudo apt-get install npm
sudo ln –s /usr/bin/nodejs /usr/bin/node
Console.log(“This is Ubuntu Node.js”)
~$ node hello.js Hello.js
Using Python
 Most versions of Linux and UNIX, including macOS, come
with Python preinstalled
1-40
matthew@seymour:~$ python
Python 3.6.4 (default, Dec27 2017, 13:02:49)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information
Using PHP
 Installation Apache
 Installation mySQL
 Installation PHP
1-41
sudo apt install php libapache2-mod-php
sudo apt install php-cli
sudo apt install php-cgi
sudo apt install php-mysql
sudo apt install apache2
sudo apt install mysql-server
sudo apt install mysql-server
Ad

More Related Content

Similar to LOSS_C11- Programming Linux 20221006.pdf (20)

Compiler design notes phases of compiler
Compiler design notes phases of compilerCompiler design notes phases of compiler
Compiler design notes phases of compiler
ovidlivi91
 
Makefile Martial Arts - Chapter 1. The morning of creation
Makefile Martial Arts - Chapter 1. The morning of creationMakefile Martial Arts - Chapter 1. The morning of creation
Makefile Martial Arts - Chapter 1. The morning of creation
Quyen Le Van
 
Gnubs pres-foss-cdac-sem
Gnubs pres-foss-cdac-semGnubs pres-foss-cdac-sem
Gnubs pres-foss-cdac-sem
Sagun Baijal
 
Gnubs-pres-foss-cdac-sem
Gnubs-pres-foss-cdac-semGnubs-pres-foss-cdac-sem
Gnubs-pres-foss-cdac-sem
Sagun Baijal
 
makefiles tutorial
makefiles tutorialmakefiles tutorial
makefiles tutorial
vsubhashini
 
Introduction to Makefile
Introduction to MakefileIntroduction to Makefile
Introduction to Makefile
Tusharadri Sarkar
 
Autotools pratical training
Autotools pratical trainingAutotools pratical training
Autotools pratical training
Thierry Gayet
 
Ch3 gnu make
Ch3 gnu makeCh3 gnu make
Ch3 gnu make
艾鍗科技
 
Makefile
MakefileMakefile
Makefile
Ionela
 
Makefiles Bioinfo
Makefiles BioinfoMakefiles Bioinfo
Makefiles Bioinfo
Giovanni Marco Dall'Olio
 
Programming in Linux Environment
Programming in Linux EnvironmentProgramming in Linux Environment
Programming in Linux Environment
Dongho Kang
 
Linux intro 5 extra: makefiles
Linux intro 5 extra: makefilesLinux intro 5 extra: makefiles
Linux intro 5 extra: makefiles
Giovanni Marco Dall'Olio
 
Don't Fear the Autotools
Don't Fear the AutotoolsDon't Fear the Autotools
Don't Fear the Autotools
Scott Garman
 
CMake Tutorial
CMake TutorialCMake Tutorial
CMake Tutorial
Fu Haiping
 
Course 102: Lecture 12: Basic Text Handling
Course 102: Lecture 12: Basic Text Handling Course 102: Lecture 12: Basic Text Handling
Course 102: Lecture 12: Basic Text Handling
Ahmed El-Arabawy
 
Linux intro 4 awk + makefile
Linux intro 4  awk + makefileLinux intro 4  awk + makefile
Linux intro 4 awk + makefile
Giovanni Marco Dall'Olio
 
LONI_MakeTutorial_Spring2012.pdf
LONI_MakeTutorial_Spring2012.pdfLONI_MakeTutorial_Spring2012.pdf
LONI_MakeTutorial_Spring2012.pdf
Utst
 
cmake.pdf
cmake.pdfcmake.pdf
cmake.pdf
Thejeswara Reddy
 
Linux operating system by Quontra Solutions
Linux operating system by Quontra SolutionsLinux operating system by Quontra Solutions
Linux operating system by Quontra Solutions
QUONTRASOLUTIONS
 
PowerPoint_merge.ppt on unix programming
PowerPoint_merge.ppt on unix programmingPowerPoint_merge.ppt on unix programming
PowerPoint_merge.ppt on unix programming
Priyadarshini648418
 
Compiler design notes phases of compiler
Compiler design notes phases of compilerCompiler design notes phases of compiler
Compiler design notes phases of compiler
ovidlivi91
 
Makefile Martial Arts - Chapter 1. The morning of creation
Makefile Martial Arts - Chapter 1. The morning of creationMakefile Martial Arts - Chapter 1. The morning of creation
Makefile Martial Arts - Chapter 1. The morning of creation
Quyen Le Van
 
Gnubs pres-foss-cdac-sem
Gnubs pres-foss-cdac-semGnubs pres-foss-cdac-sem
Gnubs pres-foss-cdac-sem
Sagun Baijal
 
Gnubs-pres-foss-cdac-sem
Gnubs-pres-foss-cdac-semGnubs-pres-foss-cdac-sem
Gnubs-pres-foss-cdac-sem
Sagun Baijal
 
makefiles tutorial
makefiles tutorialmakefiles tutorial
makefiles tutorial
vsubhashini
 
Autotools pratical training
Autotools pratical trainingAutotools pratical training
Autotools pratical training
Thierry Gayet
 
Makefile
MakefileMakefile
Makefile
Ionela
 
Programming in Linux Environment
Programming in Linux EnvironmentProgramming in Linux Environment
Programming in Linux Environment
Dongho Kang
 
Don't Fear the Autotools
Don't Fear the AutotoolsDon't Fear the Autotools
Don't Fear the Autotools
Scott Garman
 
CMake Tutorial
CMake TutorialCMake Tutorial
CMake Tutorial
Fu Haiping
 
Course 102: Lecture 12: Basic Text Handling
Course 102: Lecture 12: Basic Text Handling Course 102: Lecture 12: Basic Text Handling
Course 102: Lecture 12: Basic Text Handling
Ahmed El-Arabawy
 
LONI_MakeTutorial_Spring2012.pdf
LONI_MakeTutorial_Spring2012.pdfLONI_MakeTutorial_Spring2012.pdf
LONI_MakeTutorial_Spring2012.pdf
Utst
 
Linux operating system by Quontra Solutions
Linux operating system by Quontra SolutionsLinux operating system by Quontra Solutions
Linux operating system by Quontra Solutions
QUONTRASOLUTIONS
 
PowerPoint_merge.ppt on unix programming
PowerPoint_merge.ppt on unix programmingPowerPoint_merge.ppt on unix programming
PowerPoint_merge.ppt on unix programming
Priyadarshini648418
 

Recently uploaded (20)

Antepartum fetal surveillance---Dr. H.K.Cheema pdf.pdf
Antepartum fetal surveillance---Dr. H.K.Cheema pdf.pdfAntepartum fetal surveillance---Dr. H.K.Cheema pdf.pdf
Antepartum fetal surveillance---Dr. H.K.Cheema pdf.pdf
Dr H.K. Cheema
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
INDIA QUIZ FOR SCHOOLS | THE QUIZ CLUB OF PSGCAS | AUGUST 2024
INDIA QUIZ FOR SCHOOLS | THE QUIZ CLUB OF PSGCAS | AUGUST 2024INDIA QUIZ FOR SCHOOLS | THE QUIZ CLUB OF PSGCAS | AUGUST 2024
INDIA QUIZ FOR SCHOOLS | THE QUIZ CLUB OF PSGCAS | AUGUST 2024
Quiz Club of PSG College of Arts & Science
 
Statement by Linda McMahon on May 21, 2025
Statement by Linda McMahon on May 21, 2025Statement by Linda McMahon on May 21, 2025
Statement by Linda McMahon on May 21, 2025
Mebane Rash
 
The Pedagogy We Practice: Best Practices for Critical Instructional Design
The Pedagogy We Practice: Best Practices for Critical Instructional DesignThe Pedagogy We Practice: Best Practices for Critical Instructional Design
The Pedagogy We Practice: Best Practices for Critical Instructional Design
Sean Michael Morris
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
Module_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptxModule_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptx
drroxannekemp
 
How to Manage Manual Reordering Rule in Odoo 18 Inventory
How to Manage Manual Reordering Rule in Odoo 18 InventoryHow to Manage Manual Reordering Rule in Odoo 18 Inventory
How to Manage Manual Reordering Rule in Odoo 18 Inventory
Celine George
 
PUBH1000 Slides - Module 12: Advocacy for Health
PUBH1000 Slides - Module 12: Advocacy for HealthPUBH1000 Slides - Module 12: Advocacy for Health
PUBH1000 Slides - Module 12: Advocacy for Health
JonathanHallett4
 
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFAMCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
EUPHORIA GENERAL QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025EUPHORIA GENERAL QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
Quiz Club of PSG College of Arts & Science
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
Letter to Secretary Linda McMahon from U.S. Senators
Letter to Secretary Linda McMahon from U.S. SenatorsLetter to Secretary Linda McMahon from U.S. Senators
Letter to Secretary Linda McMahon from U.S. Senators
Mebane Rash
 
How to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 WebsiteHow to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 Website
Celine George
 
Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...
Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...
Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...
EduSkills OECD
 
PUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for HealthPUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for Health
JonathanHallett4
 
Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...
parmarjuli1412
 
Conditions for Boltzmann Law – Biophysics Lecture Slide
Conditions for Boltzmann Law – Biophysics Lecture SlideConditions for Boltzmann Law – Biophysics Lecture Slide
Conditions for Boltzmann Law – Biophysics Lecture Slide
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
PUBH1000 Slides - Module 10: Health Promotion
PUBH1000 Slides - Module 10: Health PromotionPUBH1000 Slides - Module 10: Health Promotion
PUBH1000 Slides - Module 10: Health Promotion
JonathanHallett4
 
IMPACT_OF_SOCIAL-MEDIA- AMONG- TEENAGERS
IMPACT_OF_SOCIAL-MEDIA- AMONG- TEENAGERSIMPACT_OF_SOCIAL-MEDIA- AMONG- TEENAGERS
IMPACT_OF_SOCIAL-MEDIA- AMONG- TEENAGERS
rajaselviazhagiri1
 
Antepartum fetal surveillance---Dr. H.K.Cheema pdf.pdf
Antepartum fetal surveillance---Dr. H.K.Cheema pdf.pdfAntepartum fetal surveillance---Dr. H.K.Cheema pdf.pdf
Antepartum fetal surveillance---Dr. H.K.Cheema pdf.pdf
Dr H.K. Cheema
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
Statement by Linda McMahon on May 21, 2025
Statement by Linda McMahon on May 21, 2025Statement by Linda McMahon on May 21, 2025
Statement by Linda McMahon on May 21, 2025
Mebane Rash
 
The Pedagogy We Practice: Best Practices for Critical Instructional Design
The Pedagogy We Practice: Best Practices for Critical Instructional DesignThe Pedagogy We Practice: Best Practices for Critical Instructional Design
The Pedagogy We Practice: Best Practices for Critical Instructional Design
Sean Michael Morris
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
Module_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptxModule_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptx
drroxannekemp
 
How to Manage Manual Reordering Rule in Odoo 18 Inventory
How to Manage Manual Reordering Rule in Odoo 18 InventoryHow to Manage Manual Reordering Rule in Odoo 18 Inventory
How to Manage Manual Reordering Rule in Odoo 18 Inventory
Celine George
 
PUBH1000 Slides - Module 12: Advocacy for Health
PUBH1000 Slides - Module 12: Advocacy for HealthPUBH1000 Slides - Module 12: Advocacy for Health
PUBH1000 Slides - Module 12: Advocacy for Health
JonathanHallett4
 
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFAMCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
Letter to Secretary Linda McMahon from U.S. Senators
Letter to Secretary Linda McMahon from U.S. SenatorsLetter to Secretary Linda McMahon from U.S. Senators
Letter to Secretary Linda McMahon from U.S. Senators
Mebane Rash
 
How to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 WebsiteHow to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 Website
Celine George
 
Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...
Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...
Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...
EduSkills OECD
 
PUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for HealthPUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for Health
JonathanHallett4
 
Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...
parmarjuli1412
 
PUBH1000 Slides - Module 10: Health Promotion
PUBH1000 Slides - Module 10: Health PromotionPUBH1000 Slides - Module 10: Health Promotion
PUBH1000 Slides - Module 10: Health Promotion
JonathanHallett4
 
IMPACT_OF_SOCIAL-MEDIA- AMONG- TEENAGERS
IMPACT_OF_SOCIAL-MEDIA- AMONG- TEENAGERSIMPACT_OF_SOCIAL-MEDIA- AMONG- TEENAGERS
IMPACT_OF_SOCIAL-MEDIA- AMONG- TEENAGERS
rajaselviazhagiri1
 
Ad

LOSS_C11- Programming Linux 20221006.pdf

  • 1. Chapter 11. PROGRAMMING LINUX LINUX AND OPEN SOURCE SOFTWARE 1-1
  • 2. Contents  Using programming tools  Using GNU C Compiler (gcc)  Project management tools: make, automake, autoconf  Graphical DevelopmentTools • IDEs and SDKs • Kdevelp Client  Using popular languages  Java  Javascript  PHP  Python  Etc. 1-2
  • 3. Using GNU C Compiler (gcc)  “GNU is an extensive collection of free software (383 packages as of January 2022), which can be used as an operating system or can be used in parts with other operating systems” (Wikipedia).  GNU cc (gcc) is the GNU project’s compiler suite. It compiles programs written in C,C++, or Objective C.  The gcc features  Preprocessing  Compilation  Assembly  Linking 1-3
  • 4. Example: gcc 1-4 1. /* 2. * Listing 3.1 3. * hello.c – Canonical “Hello, world!” program 4 4 */ 4. #include <stdio.h> 5. int main(void) 6. { 7. fprintf(stdout, “Hello, Linux programming world!n”); 8. return 0; 9. } $ gcc hello.c -o hello $ ./hello Hello, Linux programming world! Complie and run
  • 5. 1-5 $ gcc –E hello.c -o hello.cpp $ gcc -x cpp-output -c hello.cpp -o hello.o Stop compilation after pre-procesing See content of stdio.h and compile to an object code $ gcc hello.o -o hello Link the object file $ gcc killerapp.c helper.c -o killerapp Use code from other file
  • 6. 1-6
  • 7. Project management using GNU make  Projects composed of multiple source files typically require long, complex compiler invocations.  make simplifies this by storing these difficult command lines in the Makefile  make also minimizes rebuild times because it is smart enough to determine which files have changed, and thus only rebuilds files whose components have changed  make maintains a database of dependency information for your projects and so can verify that all of the files necessary for building a program are available each time you start a build. 1-7
  • 8. Writing Makefiles  A makefile is a text file database containing rules that tell make what to build and how to build it.A rule consists of the following:  A target, the “thing” make ultimately tries to create  A list of one or more dependencies, usually files, required to build the target  A list of commands to execute in order to create the target from the specified dependencies  Makefile 1-8 target : dependency dependency [...] command command [...]
  • 9. Makefile examples  It is the makefile for building a text editor imaginatively named editor 1-9 1 editor : editor.o screen.o keyboard.o 2 gcc -o editor editor.o screen.o keyboard.o 3 4 editor.o : editor.c editor.h keyboard.h screen.h 5 gcc -c editor.c 6 7 screen.o : screen.c screen.h 8 gcc -c screen.c 9 10 keyboard.o : keyboard.c keyboard.h 11 gcc -c keyboard.c 12 13 clean : 14 rm editor *.o To compile editor, you would simply type make in the directory where the makefile exists. Default target Dependencies Rules Target
  • 10. Makefile excercise  Examine the example Makefile 1 in 1-10 https://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/
  • 11. Makefile: variable  To simplify editing and maintaining makefiles, make allows you to create and use variables.  To obtainVARNAME’s value, enclose it in parentheses and prefix it with a $: 1-11 VARNAME = some_text [...] $(VARNAME)
  • 12. Makefile: variable 1-12 1 OBJS = editor.o screen.o keyboard.o 2 HDRS = editor.h screen.h keyboard.h 3 editor : $(OBJS) 4 gcc -o editor $(OBJS) 5 6 editor.o : editor.c $(HDRS) 7 gcc -c editor.c 8 9 screen.o : screen.c screen.h 10 gcc -c screen.c 11 12 keyboard.o : keyboard.c keyboard.h 13 gcc -c keyboard.c 14 15 .PHONY : clean 16 17 clean : 18 rm editor $(OBJS) Variables Default target Rules PHONY to skip checking filename “clean”
  • 13. Environment,Automatic, PredefinedVariables  make allows the use of environment variables  make reads every variable defined in its environment and creates variables with the same name and value  make provides a long list of predefined and automatic variables, too. 1-13 AUTOMATIC VARIABLES Variable Description $@ The filename of a rule’s target $< The name of the first dependency in a rule $^ Space-delimited list of all the dependencies in a rule $? Space-delimited list of all the dependencies in a rule that are newer thanthe target $(@D) The directory part of a target filename, if the target is in a subdirectory $(@F) The filename part of a target filename, if the target is in a subdirectory
  • 14. PREDEFINED VARIABLES Variable Description AR Archive-maintenance programs; default value = ar AS Program to do assembly; default value = as CC Program for compiling C programs; default value = cc CPP C Preprocessor program; default value = cpp RM Program to remove files; default value = “rm -f” ARFLAGS Flags for the archive-maintenance program; default = rv ASFLAGS Flags for the assembler program; no default CFLAGS Flags for the C compiler; no default CPPFLAGS Flags for the C preprocessor; no default LDFLAGS Flags for the linker (ld); no default 1-14
  • 15. Excercise  Examine the example Makefile 2 in 1-15 https://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/
  • 16. Implicit Rules  make comes with a comprehensive set of implicit, or predefined, rules 1-16 1 OBJS = editor.o screen.o keyboard.o 2 editor : $(OBJS) 3 cc -o editor $(OBJS) 4 5 .PHONY : clean 6 7 clean : 8 rm editor $(OBJS) the makefile lacks rules for building targets (dependencies) make will look for C source files named editor.c, screen.c, and keyboard.c, compile them to object files (editor.o, screen.o, and keyboard.o), and finally, build the default editor target.
  • 17. Pattern Rules  Pattern rules look like normal rules, except that the target contains exactly one character (%) that matches any nonempty string. 1-17 %.o : %.c tells make to build any object file somename.o from a source file somename.c. %.o : %.c $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@ It defines a rule that makes any file x.o from x.c. This rule uses the automatic variables $< and $@ to substitute the names of the first dependency and the target each time the rule is applied. The variables $(CC), $(CFLAGS), and $(CPPFLAGS)
  • 18. Excercise  Examine the example Makefile 3 & Makefile 4 in 1-18 https://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/
  • 19. Useful Makefile Targets  make 1-19 • clean • install • uninstall • dist • test • archive • bugreport # a sample makefile for a skeleton program CC= gcc INS= install INSDIR = /usr/local/bin LIBDIR= -L/usr/X11R6/lib LIBS= -lXm -lSM -lICE -lXt -lX11 SRC= skel.c OBJS= skel.o PROG= skel skel: ${OBJS} ${CC} -o ${PROG} ${SRC} ${LIBDIR} ${LIBS} install: ${PROG} ${INS} -g root -o root ${PROG} ${INSDIR}
  • 20. Excercise  Examine the example Makefile 5 in 1-20 https://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/
  • 21. GNU Automake  The primary goal of Automake is to generate ‘Makefile’ in compliant with the GNU Makefile Standards.  A secondary goal for Automake is that it work well with other free software, and, specifically, GNU tools.  Automake helps the maintainer with five large tasks, and countless minor ones.The basic functional areas are: • Build • Check • Clean • Install and uninstall • Distribution 1-21
  • 22. Building configure.in (or configure.ac)  The configure script ‘configure.in’ is responsible for getting ready to build the software on your specific system. It makes sure all of the dependencies for the rest of the build and install process are available, and finds out whatever it needs to know to use those dependencies.  A configure script ‘configure.in’ examines your system, and uses the information it finds to convert a Makefile.in template into a Makefile  To run the configure script 1-22 ./configure
  • 23. Building configure.in (or configure.ac) 1-23 AC_INIT (package, version, bug-report-address) AC_OUTPUT([file...[,extra_cmds[,init_cmds]]]) Invoke before any test Invoke after any test unique_file_in_source_dir is a file present in the source code directory. The call to AC_INIT creates shell code in the generated configure script that looks for unique_file_in_source_dir to make sure that it is in the correct directory. AC_OUTPUT creates the output files, such as Makefiles and other (optional) output files file is a space separated list of output files. Configure.in
  • 24. Structuring the file Configure.ac 1-24 AC_INIT Tests for programs Tests for libraries Tests for header files Tests for typedefs Tests for structures Tests for compiler behavior Tests for library functions Tests for system services AC_OUTPUT Configure.in
  • 26. Tests for Library Functions 1-26
  • 27. Tests for Header Files 1-27
  • 30. Tests of Compiler Behavior 1-30
  • 31. Tests for System Services 1-31
  • 32. Using the autoconf  This program builds an executable shell script named configure (from configure.in) that, when executed, automatically examines and tailors a client’s build from source according to software resources, or dependencies (such as programming tools, libraries, and associated utilities) that are installed on the target host (your Linux system). 1-32
  • 33. Example 1-33 #include <stdio.h> int main(int argc, char* argv[]) { printf("Hello worldn"); return 0; } AC_INIT([helloworld], [0.1], [[email protected]]) AM_INIT_AUTOMAKE AC_PROG_CC AC_CONFIG_FILES([Makefile]) AC_OUTPUT AUTOMAKE_OPTIONS = foreign bin_PROGRAMS = helloworld helloworld_SOURCES = main.c Helloworld.c Configure.in Makefile.am aclocal #generate m4 env autoconf #generate configure automake –add-missing configure Makefile.in ./configure # Generate Makefile from Makefile.in make # Use Makefile to build the program make install # Use Makefile to install the program
  • 34. Graphical DevelopmentTools  Ubuntu has a number of graphical prototyping and development environments available  integrated development environment (IDE) • Eclipse • NetBeans • Visual Studio Code • Oracle JDeveloper  software development kit (SDK) • Android development SDK  the KDevelop Client (for Developing in KDE)  The Glade Client (for Developing in GNOME) 1-34
  • 35. Exercise  Download and install Eclipse IDE for C/C++ (or Java, PHP, etc.)  Check for Java installed: java –version • Sudo apt install default-jre  Check OS type (64/32bit): uname -a  Download Eclipse C/C++ tarball file from https://www.eclipse.org/downloads/eclipse-packages/  Extract and install • tar –xf <tarball file.gz>  Run Eclipse: ./eclipse  Set PATH to run from $HOME directory • PATH = $PATH:$HOME/<install directory> 1-35 Note: to permanently set PATH env, edit file $HOME/.profile
  • 37. Using Java on Linux  Most Java development occurs in an IDE  Eclipse (www.eclipse.org)  NetBeans (www.netbeans.org) 1-37
  • 38. Using JavaScript  To use JavaScript on Ubuntu, you write programs in your favorite text editor. Nothing special is needed.  Put the script somewhere and open it with your web browser.  Information is often passed using JavaScript Object Notation, or JSON  JavaScript has spawned tons of extensions and development kits, such as Node.js and JSP. 1-38
  • 39. Using JavaScript  Node.js  Node.js is a popular JavaScript framework used for developing server side applications. 1-39 sudo apt-get install nodejs sudo apt-get install npm sudo ln –s /usr/bin/nodejs /usr/bin/node Console.log(“This is Ubuntu Node.js”) ~$ node hello.js Hello.js
  • 40. Using Python  Most versions of Linux and UNIX, including macOS, come with Python preinstalled 1-40 matthew@seymour:~$ python Python 3.6.4 (default, Dec27 2017, 13:02:49) [GCC 7.2.0] on linux Type "help", "copyright", "credits" or "license" for more information
  • 41. Using PHP  Installation Apache  Installation mySQL  Installation PHP 1-41 sudo apt install php libapache2-mod-php sudo apt install php-cli sudo apt install php-cgi sudo apt install php-mysql sudo apt install apache2 sudo apt install mysql-server sudo apt install mysql-server