How to Use the Command `makepkg` (with examples)

How to Use the Command `makepkg` (with examples)

Makepkg is a command used in Arch Linux to create packages that can be used with the pacman package manager. It uses the PKGBUILD file in the current working directory by default. This article will illustrate each of the following use cases of the makepkg command.

Use case 1: Make a package

Code:

makepkg

Motivation: Creating packages is an essential task when working with Arch Linux. By running makepkg without any arguments, it will use the PKGBUILD file in the current working directory to create a package.

Explanation: Running makepkg without any arguments will use the PKGBUILD file in the current working directory as the source for creating a package. This command will handle the build process and collect all necessary files to create the package.

Example Output:

==> Making package: package-name 1.0-1 (timestamp)
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> Retrieving sources...
==> Validating source files with sha256sums...
    file.tar.gz ... Passed
==> Extracting sources...
==> Starting build()...
...
==> Package package-name created.

Use case 2: Make a package and install its dependencies

Code:

makepkg --syncdeps

Motivation: When creating a package, it’s important to ensure that all dependencies are installed. By using --syncdeps option, makepkg will automatically install the required dependencies before starting the build process.

Explanation: The --syncdeps option tells makepkg to automatically install any missing dependencies required by the package. This helps to ensure a successful build by automatically resolving and installing all necessary dependencies.

Example Output:

==> Making package: package-name 1.0-1 (timestamp)
==> Checking runtime dependencies...
==> Missing dependencies:
  - dependency1
  - dependency2
==> Installing missing dependencies...
...
==> Starting build()...
...
==> Package package-name created.

Use case 3: Make a package, install its dependencies, then install it to the system

Code:

makepkg --syncdeps --install

Motivation: After successfully creating a package, it may be beneficial to install it directly to the system. This can simplify the process of testing and using the package on the local machine without the need to manually install it.

Explanation: The --install option tells makepkg to automatically install the created package to the system after a successful build. Combined with --syncdeps, it ensures that all dependencies are installed before building the package.

Example Output:

==> Making package: package-name 1.0-1 (timestamp)
==> Checking runtime dependencies...
==> Missing dependencies:
  - dependency1
  - dependency2
==> Installing missing dependencies...
...
==> Starting build()...
...
==> Package package-name created.
==> Installing package-name package to /usr/local...

Use case 4: Make a package, but skip checking the source’s hashes

Code:

makepkg --skipchecksums

Motivation: When building a package, makepkg verifies the integrity of the source files by checking their hashes. However, in some cases, you may want to skip this verification step, such as when modifying the source files locally.

Explanation: By using the --skipchecksums option, makepkg skips the verification of source file hashes. This can be useful when you have made local modifications to the source files and don’t want makepkg to fail the build due to checksum mismatches.

Example Output:

==> Making package: package-name 1.0-1 (timestamp)
==> Skipping source checksums checks...
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> Retrieving sources...
==> Extracting sources...
==> Starting build()...
...
==> Package package-name created.

Use case 5: Clean up work directories after a successful build

Code:

makepkg --clean

Motivation: After a successful build, makepkg leaves behind work directories containing intermediate files. By using the --clean option, these directories can be automatically cleaned up, ensuring a tidier project structure.

Explanation: The --clean option tells makepkg to remove any work directories created during the build process. These directories typically contain intermediate files that are no longer needed after a successful build.

Example Output:

==> Making package: package-name 1.0-1 (timestamp)
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> Retrieving sources...
==> Validating source files with sha256sums...
    file.tar.gz ... Passed
==> Extracting sources...
==> Starting build()...
...
==> Package package-name created.
==> Cleaning up work directories...

Use case 6: Verify the hashes of the sources

Code:

makepkg --verifysource

Motivation: Ensuring the integrity of source files is crucial when building packages. By using the --verifysource option, makepkg performs a hash verification on the source files, ensuring they have not been tampered with.

Explanation: The --verifysource option tells makepkg to verify the hashes of the source files. It compares the calculated hashes with the expected ones specified in the PKGBUILD file, ensuring the integrity and authenticity of the source files.

Example Output:

==> Making package: package-name 1.0-1 (timestamp)
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> Retrieving sources...
==> Validating source files with sha256sums...
    file.tar.gz ... Passed
==> Extracting sources...
==> Starting build()...
...
==> Package package-name created.

Use case 7: Generate and save the source information into .SRCINFO

Code:

makepkg --printsrcinfo > .SRCINFO

Motivation: The .SRCINFO file provides crucial information about the package, such as its version, dependencies, and build information. By generating and saving the source information into .SRCINFO, it can be used for submitting the package to AUR (Arch User Repository) or other package repositories.

Explanation: The --printsrcinfo option tells makepkg to generate the source information in the .SRCINFO format. The command makepkg --printsrcinfo > .SRCINFO redirects the generated information to the .SRCINFO file in the current working directory.

Example Output: Running this command will not produce any visible output. However, the .SRCINFO file in the current working directory will contain the generated source information.

Conclusion:

The makepkg command is a powerful tool for creating packages in Arch Linux. By understanding and utilizing the different use cases illustrated in this article, you can effectively build packages, handle dependencies, verify source integrity, and manage work directories, among other tasks.

Related Posts

How to use the command 'kubectl logs' (with examples)

How to use the command 'kubectl logs' (with examples)

The kubectl logs command is used to show the logs for containers running inside a pod in a Kubernetes cluster.

Read More
How to use the command "husky" (with examples)

How to use the command "husky" (with examples)

Husky is a tool that simplifies working with Git hooks. Git hooks are scripts that run automatically in response to certain actions in Git, such as committing or pushing changes.

Read More
Using autopkgtest command (with examples)

Using autopkgtest command (with examples)

Case 1: Build the package in the current directory and run all tests directly on the system autopkgtest -- null Motivation: This use case is useful when you want to build and test a package that is located in the current directory.

Read More