SlideShare a Scribd company logo
1 of 41
Download to read offline
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

More Related Content

Similar to LOSS_C11- Programming Linux 20221006.pdf

Gnubs pres-foss-cdac-sem
Gnubs pres-foss-cdac-semGnubs pres-foss-cdac-sem
Gnubs pres-foss-cdac-sem
Sagun Baijal
 

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

(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net
 
Makefile Generation From Autotools
Makefile Generation From AutotoolsMakefile Generation From Autotools
Makefile Generation From Autotools
 
Autotools
AutotoolsAutotools
Autotools
 
Introduction to GNU Make Programming Language
Introduction to GNU Make Programming LanguageIntroduction to GNU Make Programming Language
Introduction to GNU Make Programming Language
 
Makefile for python projects
Makefile for python projectsMakefile for python projects
Makefile for python projects
 
Readme
ReadmeReadme
Readme
 
A05
A05A05
A05
 
Prog1-L1.pdf
Prog1-L1.pdfProg1-L1.pdf
Prog1-L1.pdf
 
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
 
Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008
 
Basic Make
Basic MakeBasic Make
Basic Make
 
From gcc to the autotools
From gcc to the autotoolsFrom gcc to the autotools
From gcc to the autotools
 
C PROGRAMMING
C PROGRAMMINGC PROGRAMMING
C PROGRAMMING
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
 
Software Build processes and Git
Software Build processes and GitSoftware Build processes and Git
Software Build processes and Git
 
Gnubs-pres-foss-cdac-sem
Gnubs-pres-foss-cdac-semGnubs-pres-foss-cdac-sem
Gnubs-pres-foss-cdac-sem
 
Gnubs pres-foss-cdac-sem
Gnubs pres-foss-cdac-semGnubs pres-foss-cdac-sem
Gnubs pres-foss-cdac-sem
 
Ch3 gnu make
Ch3 gnu makeCh3 gnu make
Ch3 gnu make
 
Basics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxBasics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptx
 
Srgoc dotnet
Srgoc dotnetSrgoc dotnet
Srgoc dotnet
 

Recently uploaded

Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 

Recently uploaded (20)

Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Our Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdfOur Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdf
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of Play
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 

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], [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
  • 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