4.3. Building software from source


During the software building process, the source code is turned into software artifacts that you can package by using RPM.

4.3.1. Building software from natively compiled code

You can build software written in a compiled language into an executable by using one of the following methods:

  • Manual building
  • Automated building

4.3.1.1. Manually building a sample C program

You can use manual building to build software written in a compiled language.

A sample Hello World program written in C (cello.c) has the following contents:

#include <stdio.h>

int main(void) {
    printf("Hello World\n");
    return 0;
}

Procedure

  1. Invoke the C compiler from the GNU Compiler Collection to compile the source code into binary:

    $ gcc -g -o cello cello.c
  2. Run the resulting binary cello:

    $ ./cello
    Hello World

4.3.1.2. Setting automated building for a sample C program

Large-scale software commonly uses automated building. You can set up automated building by creating the Makefile file and then running the GNU make utility.

Procedure

  1. Create the Makefile file with the following content in the same directory as cello.c:

    cello:
    	gcc -g -o cello cello.c
    clean:
    	rm cello

    Note that the lines under cello: and clean: must begin with a tabulation character (tab).

  2. Build the software:

    $ make
    make: 'cello' is up to date.
  3. Because a build is already available in the current directory, enter the make clean command, and then enter the make command again:

    $ make clean
    rm cello
    
    $ make
    gcc -g -o cello cello.c

    Note that trying to build the program again at this point has no effect because the GNU make system detects the existing binary:

    $ make
    make: 'cello' is up to date.
  4. Run the program:

    $ ./cello
    Hello World

4.3.2. Interpreting source code

You can convert the source code written in an interpreted programming language into machine code by using one of the following methods:

  • 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

      참고

      You 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

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")

Procedure

  1. Byte-compile the pello.py file:

    $ python -m compileall pello.py
  2. Verify that a byte-compiled version of the file is created:

    $ ls __pycache__
    pello.cpython-311.pyc

    Note that the package version in the output might differ depending on which Python version is installed.

  3. Run the program in pello.py:

    $ python pello.py
    Hello World

4.3.2.2. Raw-interpreting a sample Bash program

A sample Hello World program written in Bash shell built-in language (bello) has the following contents:

#!/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

  1. Make the file with source code executable:

    $ chmod +x bello
  2. Run the created file:

    $ ./bello
    Hello World
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2026 Red Hat
맨 위로 이동