CURDIR Make Bash

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

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

CURDIR это предпочтительный вариант для указывания на текущую директорию.

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

For your convenience, when GNU make starts (after it has processed any -C options) it sets the variable CURDIR to the pathname of the current working directory.

This value is never touched by make again: in particular note that if you include files from other directories the value of CURDIR does not change.

The value has the same precedence it would have if it were set in the makefile (by default, an environment variable CURDIR will not override this value).

Note that setting this variable has no impact on the operation of make (it does not cause make to change its working directory, for example).

Пример

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

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

Article author: Andrei Olegovich

Похожие статьи
make
Linux
Bash
C
C++
C++ Header files
Configure make install
DevOps
Docker
OpenBSD
Errors make

Search this site

Subscribe to Telegram channel @aofeed to follow new articles and updates to old ones

Go to channel

@aofeed

Ask a question in the Telegram group

@aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: