CURDIR Make Bash

Contents
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

Related Articles
make
Linux
Bash
C
C++
C++ Header files
Configure make install
DevOps
Docker
OpenBSD
Errors make

Search on this site

Subscribe to @aofeed channel for updates

Visit Channel

@aofeed

Feedback and Questions in Telegram

@aofeedchat