3.6. The %autosetup and %setup macros


You can use the %autosetup macro to unpack the source archives and apply patches automatically without manually specifying each patch by using the %patch directive.

중요

%autosetup applies patches in the order they appear in the spec file. Always consider keeping sources and patches sorted by their number in spec to avoid unexpected actions. Alternatively, avoid the numbering entirely by using %patchlist or non-numbered Patch entries.

You can also use the %setup macro to unpack the source archives for building RPM packages.

중요

Use the %autosetup macro whenever possible, instead of the %setup macro.

3.6.1. The %autosetup macro options

You can use the following %autosetup macro options to control its behavior. %autosetup also accepts all %setup macro options.

참고

You can combine the %autosetup macro options.

Expand
표 3.2. The %autosetup macro options
Macro optionDescription

-v

Use the -v option to enable the verbosity of the %autosetup macro.

-N

Use the -N option to disable automatic patch application.

-S<vcs_name>

Use the -S<vcs_name> option to specify the version control system (VCS) to use, for example, git_am, git, patch, or gendiff.

-p

Use the -p option to control patch prefix stripping. For more information, see the patch(1) man page on your system.

3.6.2. The %autopatch macro options

The %autopatch macro applies all patches in the order stated in a spec file. You can use the following %autopatch macro options to control its behavior.

참고

You can combine the %autopatch macro options.

Expand
표 3.3. The %autopatch macro options
Macro optionDescription

-v

Use the -v option to enable the verbosity of the %autopatch macro.

-q

Use the -q option to turn off warnings if no matching patches are detected.

-p

Use the -p option to control patch prefix stripping. For more information, see the patch(1) man page on your system.

-m<patch_number>

Use the -m<patch_number> option to apply a range of patches starting from the specified patch number.

-M<patch_number>

Use the -M<patch_number> to apply a range of patches up to the specified patch number.

3.6.3. The %setup macro options

You can use the following %setup macro options for controlling the unpacking of source archives.

참고

You can combine the %setup macro options.

Expand
표 3.4. The %setup macro options
Macro optionDescription

-q

Use the -q option to limit the verbosity of the %setup macro. Pass this option as the first option to the %setup macro.

-n

Use the -n option to specify the name of the directory from an expanded source code archive.

For example, you can use this option when the directory from the expanded source code archive has a different name from what is expected (%{<name>}-%{<version>}), which can lead to an error of the `%setup macro. For example, if the package name is cello, but the source code archive name is hello-1.0.tgz, and it contains the hello/ directory, the spec file must have the following contents:

Name: cello
Source0: https://example.com/%{name}/release/hello-%{version}.tar.gz
...
%prep
%setup -n hello

-c

Use the -c option to create a directory and then change to this directory before unpacking any sources, for example:

/usr/bin/mkdir -p cello-1.0
cd 'cello-1.0'

The directory is not changed after archive expansion.

-D

Use the -D option to disable deletion of the source code directory. You can use this option, for example, if the %setup macro is used several times. With the -D option, the following lines are not used:

rm -rf 'cello-1.0'

-T

Use the -T option to skip the default action of the %setup macro, which includes unpacking of the first source archive. This option removes the following line from the script:

/usr/bin/gzip -dc '/builddir/build/SOURCES/cello-1.0.tar.gz' | /usr/bin/tar -xvvof -

-b

Use the -b (before) option to expand specific sources before entering the working directory.

For example, examples are provided in a separate cello-1.0-examples.tar.gz archive, which expands into cello-1.0/examples. In this case, use -b 1 to expand Source1 before entering the working directory:

Source0: https://example.com/%{name}/release/%{name}-%{version}.tar.gz
Source1: %{name}-%{version}-examples.tar.gz
...
%prep
%setup -b 1

-a

Use the -a (after) to expand specific sources after entering the working directory. The argument is a source number from the spec file preamble section.

For example, the cello-1.0.tar.gz archive contains an empty examples directory. The examples are shipped in a separate examples.tar.gz archive, and they expand into the directory with the same name. In this case, use -a 1 to expand Source1 after entering the working directory:

Source0: https://example.com/%{name}/release/%{name}-%{version}.tar.gz
Source1: examples.tar.gz
...
%prep
%setup -a 1
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 소개

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

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

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

Red Hat 문서 정보

Legal Notice

Theme

© 2026 Red Hat
맨 위로 이동