Sobes.tech
Middle

How do you build packages from source code? Provide examples of Bash scripts.

sobes.tech AI

Answer from AI

I use standard build tools such as Make, Autoconf, CMake, Maven (for Java), npm (for Node.js) depending on the project type and language. The process usually includes the following steps:

  1. Getting the source code: Cloning the repository or unpacking an archive.
  2. Configuring the build (if necessary): Running configuration scripts like ./configure.
  3. Compiling: Running the main build command, e.g., make.
  4. Installing: Placing the compiled files into target directories.

Examples of Bash scripts for building from source:

Simple project with Make:

# Getting the source code (example)
# git clone https://github.com/my_project/my_project.git
# cd my_project

# Build
make

# Install (if specified in the makefile)
# make install

Project with Autoconf/Make:

# Getting the source code (example)
# wget https://example.com/software-1.0.tar.gz
# tar -xzf software-1.0.tar.gz
# cd software-1.0

# Configuring the build
./configure --prefix=/usr/local

# Compiling
make

# Installing
# make install

Project with CMake:

# Getting the source code (example)
# git clone https://github.com/another_project/another_project.git
# cd another_project

# Creating a build directory (recommended)
mkdir build
cd build

# Configuring the build
cmake .. -DCMAKE_INSTALL_PREFIX=/opt/another_project

# Compiling
make

# Installing
# make install

In CI/CD pipelines, I often use more complex command combinations, including dependency management, testing, and packaging into various formats (deb, rpm, docker images).