shell функция в make-файлах

Содержание
Introduction
Для чего используется CURDIR
Пример
Related Articles

Для чего используются shell

shell это функция, которая может общаться с окружением вне make-файла

Вот что написано в официальной документации здесь и здесь

8.13 The shell Function The shell function is unlike any other function other than the wildcard function (see The Function wildcard) in that it communicates with the world outside of make. The shell function performs the same function that backquotes (‘`’) perform in most shells: it does command expansion. This means that it takes as an argument a shell command and evaluates to the output of the command. The only processing make does on the result is to convert each newline (or carriage-return / newline pair) to a single space. If there is a trailing (carriage-return and) newline it will simply be removed. The commands run by calls to the shell function are run when the function calls are expanded (see How make Reads a Makefile). Because this function involves spawning a new shell, you should carefully consider the performance implications of using the shell function within recursively expanded variables vs. simply expanded variables (see The Two Flavors of Variables). After the shell function or ‘!=’ assignment operator is used, its exit status is placed in the .SHELLSTATUS variable. Here are some examples of the use of the shell function: contents := $(shell cat foo) sets contents to the contents of the file foo, with a space (rather than a newline) separating each line. files := $(shell echo *.c) sets files to the expansion of ‘*.c’. Unless make is using a very strange shell, this has the same result as ‘$(wildcard *.c)’ (as long as at least one ‘.c’ file exists).

Пример

Пример вывода текущей директори на экран.

GNUmakefile создан в директории

/home/andrei/sandbox

vi /home/andrei/sandbox/GNUmakefile

.PHONY: show-curdir show-curdir: @echo "CURDIR is:" @echo ${CURDIR}

make show-curdir

CURDIR is:
/home/andrei/sandbox

Проверить существование директории

Нужно проверить есть ли в sandbox поддиректория cpp с C++ кодом или нет

Для этого нужена команда -d

.PHONY: check-cpp check-cpp: @if [ -d ${CURDIR}/cpp ]; then \ echo ${CURDIR}/cpp" exists"; \ else echo ${CURDIR}/cpp" does not exist"; \ fi

make check-cpp

/home/andrei/sandbox/cpp does not exist

mkdir cpp
make check-cpp

/home/andrei/sandbox/cpp exists

Похожие статьи
make
Основы make
PHONY
CURDIR
shell
wget + make
Переменные в Make файлах
ifeq: Условные операторы
filter
-c: Компиляция
Linux
Bash
C
C++
C++ Header файлы
Configure make install
DevOps
Docker
OpenBSD
Errors make

Поиск по сайту

Подпишитесь на Telegram канал @aofeed чтобы следить за выходом новых статей и обновлением старых

Перейти на канал

@aofeed

Задать вопрос в Телеграм-группе

@aofeedchat

Контакты и сотрудничество:
Рекомендую наш хостинг beget.ru
Пишите на info@urn.su если Вы:
1. Хотите написать статью для нашего сайта или перевести статью на свой родной язык.
2. Хотите разместить на сайте рекламу, подходящую по тематике.
3. Реклама на моём сайте имеет максимальный уровень цензуры. Если Вы увидели рекламный блок недопустимый для просмотра детьми школьного возраста, вызывающий шок или вводящий в заблуждение - пожалуйста свяжитесь с нами по электронной почте
4. Нашли на сайте ошибку, неточности, баг и т.д. ... .......
5. Статьи можно расшарить в соцсетях, нажав на иконку сети: