Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 4. Creating software for RPM packaging
Prepare your software source code for RPM packaging on Red Hat Enterprise Linux (RHEL).
4.1. What is source code Link kopierenLink in die Zwischenablage kopiert!
Source code is human-readable instructions to the computer that describe how to perform a computation. Source code is expressed by using a programming language.
The following versions of the Hello World program written in three different programming languages cover major RPM Package Manager use cases:
Hello Worldwritten in BashThe bello project implements
Hello Worldin Bash. The implementation contains only thebelloshell script. The purpose of this program is to outputHello Worldon the command line.The
bellofile has the following contents:#!/bin/bash printf "Hello World\n"
#!/bin/bash printf "Hello World\n"Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Hello Worldwritten in PythonThe pello project implements
Hello Worldin Python. The implementation contains only thepello.pyprogram. The purpose of the program is to outputHello Worldon the command line.The
pello.pyfile has the following contents:#!/usr/bin/python3 print("Hello World")#!/usr/bin/python3 print("Hello World")Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Hello Worldwritten in CThe cello project implements
Hello Worldin C. The implementation contains only thecello.candMakefilefiles. The resultingtar.gzarchive therefore has two files in addition to theLICENSEfile. The purpose of the program is to outputHello Worldon the command line.The
cello.cfile has the following contents:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
The packaging process is different for each version of the Hello World program.
4.2. Methods of creating software Link kopierenLink in die Zwischenablage kopiert!
You can convert the human-readable source code into machine code by natively compiling or interpreting software.
4.2.1. Natively compiled software Link kopierenLink in die Zwischenablage kopiert!
Natively compiled software is software written in a programming language that compiles to machine code with a resulting binary executable file. Natively compiled software is standalone software.
Natively compiled RPM packages are architecture-specific.
If you compile such software on a computer that uses a 64-bit (x86_64) AMD or Intel processor, it does not run on a 32-bit (x86) AMD or Intel processor. The resulting package has the architecture specified in its name.
4.2.2. Interpreted software Link kopierenLink in die Zwischenablage kopiert!
Some programming languages, such as Bash or Python, do not compile to machine code. Instead, a language interpreter or a language virtual machine executes the programs' source code step-by-step without prior transformations.
Software written entirely in interpreted programming languages is not architecture-specific. Therefore, the resulting RPM package has the noarch string in its name.
You can either raw-interpret or byte-compile software written in interpreted languages:
Raw-interpreted software
You do not need to compile this type of software. Raw-interpreted software is directly executed by the interpreter.
Byte-compiled software
You must first compile this type of software into bytecode, which is then executed by the language virtual machine.
NoteSome byte-compiled languages can be either raw-interpreted or byte-compiled.
Note that the way you build and package software by using RPM is different for these two software types.
4.3. Building software from source Link kopierenLink in die Zwischenablage kopiert!
Build software written in compiled languages from source code into executable software artifacts.
4.3.1. Building software from natively compiled code Link kopierenLink in die Zwischenablage kopiert!
Build software written in a compiled language into an executable by using manual or automated building.
4.3.1.1. Manually building a sample C program Link kopierenLink in die Zwischenablage kopiert!
Manually build software written in a compiled language.
A sample Hello World program written in C (cello.c) has the following contents:
Procedure
Invoke the C compiler from the GNU Compiler Collection to compile the source code into binary:
gcc -g -o cello cello.c
$ gcc -g -o cello cello.cCopy to Clipboard Copied! Toggle word wrap Toggle overflow Run the resulting binary
cello:./cello
$ ./celloCopy to Clipboard Copied! Toggle word wrap Toggle overflow Hello World
Hello WorldCopy to Clipboard Copied! Toggle word wrap Toggle overflow
4.3.1.2. Setting automated building for a sample C program Link kopierenLink in die Zwischenablage kopiert!
In practice, all software uses automated building. Set up automated building by creating the Makefile file and then running the GNU make utility.
Procedure
Create the
Makefilefile with the following content in the same directory ascello.c:cello: gcc -g -o cello cello.c clean: rm cello
cello: gcc -g -o cello cello.c clean: rm celloCopy to Clipboard Copied! Toggle word wrap Toggle overflow Note that the lines under
cello:andclean:must begin with a tabulation character (tab).Build the software:
make
$ makeCopy to Clipboard Copied! Toggle word wrap Toggle overflow make: 'cello' is up to date.
make: 'cello' is up to date.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Because a build is already available in the current directory, repeat the following steps:
Enter the
make cleancommand:make clean
$ make cleanCopy to Clipboard Copied! Toggle word wrap Toggle overflow rm cello
rm celloCopy to Clipboard Copied! Toggle word wrap Toggle overflow Enter the
makecommand:make
$ makeCopy to Clipboard Copied! Toggle word wrap Toggle overflow gcc -g -o cello cello.c
gcc -g -o cello cello.cCopy to Clipboard Copied! Toggle word wrap Toggle overflow Note that trying to build the program again at this point has no effect because the GNU
makesystem detects the existing binary:make
$ makeCopy to Clipboard Copied! Toggle word wrap Toggle overflow make: 'cello' is up to date.
make: 'cello' is up to date.Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Run the program:
./cello
$ ./celloCopy to Clipboard Copied! Toggle word wrap Toggle overflow Hello World
Hello WorldCopy to Clipboard Copied! Toggle word wrap Toggle overflow
4.3.2. Interpreting source code Link kopierenLink in die Zwischenablage kopiert!
Byte-compile a source code written in a compiled language and make a source code written in a shell scripting language directly executable.
- Byte-compiling
The procedure for byte-compiling software varies depending on the following factors:
- Programming language
- Language’s virtual machine
- Tools and processes used with that language
NoteYou can byte-compile software written, for example, in Python. Python software intended for distribution is often byte-compiled, but not in the way described in this document. The described procedure aims not to conform to the community standards, but to be simple. For real-world Python guidelines, see Software Packaging and Distribution.
You can also raw-interpret Python source code. However, the byte-compiled version is faster. Therefore, RPM packagers prefer to package the byte-compiled version for distribution to end users.
- Raw-interpreting
- Software written in shell scripting languages, such as Bash, is always executed by raw-interpreting.
4.3.2.1. Byte-compiling a sample Python program Link kopierenLink in die Zwischenablage kopiert!
Byte-compile a sample Python source code to improve software performance. Python code can also be raw-interpreted, but byte-compiled code runs faster.
By choosing byte-compiling over raw-interpreting of Python source code, you can create faster software.
A sample Hello World program written in the Python programming language (pello.py) has the following contents:
print("Hello World")
print("Hello World")
Procedure
Byte-compile the
pello.pyfile:python -m compileall pello.py
$ python -m compileall pello.pyCopy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that a byte-compiled version of the file is created:
ls pass:[pycache]
$ ls pass:[pycache]Copy to Clipboard Copied! Toggle word wrap Toggle overflow pello.cpython-311.pyc
pello.cpython-311.pycCopy to Clipboard Copied! Toggle word wrap Toggle overflow Note that the package version in the output might differ depending on which Python version is installed.
Run the program in
pello.py:python pello.py
$ python pello.pyCopy to Clipboard Copied! Toggle word wrap Toggle overflow Hello World
Hello WorldCopy to Clipboard Copied! Toggle word wrap Toggle overflow
4.3.2.2. Raw-interpreting a sample Bash program Link kopierenLink in die Zwischenablage kopiert!
Make a Bash source code directly executable.
A sample Hello World program written in Bash shell built-in language (bello) has the following contents:
#!/bin/bash printf "Hello World\n"
#!/bin/bash
printf "Hello World\n"
The shebang (#!) sign at the top of the bello file is not part of the programming language source code.
Use the shebang to turn a text file into an executable. The system program loader parses the line containing the shebang to get a path to the binary executable, which is then used as the programming language interpreter.
Procedure
Make the file with source code executable:
chmod +x bello
$ chmod +x belloCopy to Clipboard Copied! Toggle word wrap Toggle overflow Run the created file:
./bello
$ ./belloCopy to Clipboard Copied! Toggle word wrap Toggle overflow Hello World
Hello WorldCopy to Clipboard Copied! Toggle word wrap Toggle overflow