# Using if-else Conditionals in a Makefile

DevFeed: [Using if-else Conditionals in a Makefile](<https://devfeed.tech/articles/using-if-else-conditionals-in-a-makefile-4515.md>)

Original publisher: [Read original article](<https://feeds.feedblitz.com/~/919796387/0/baeldung/linux~Using-ifelse-Conditionals-in-a-Makefile>)

Author: baeldung

Published: 2025-06-06T09:36:00Z

Content type: tutorial

Language: en

Sources: [Baeldung - Linux](<https://devfeed.tech/sources/baeldung-linux.md>)

Topics: [make](<https://devfeed.tech/topics/make.md>), [conditionals](<https://devfeed.tech/topics/conditionals.md>), [Bash](<https://devfeed.tech/topics/bash.md>), [Programming](<https://devfeed.tech/topics/programming.md>)

Tags: [awk](<https://devfeed.tech/tags/awk.md>), [bash](<https://devfeed.tech/tags/bash.md>), [build](<https://devfeed.tech/tags/build.md>), [building](<https://devfeed.tech/tags/building.md>), [building-make-popular](<https://devfeed.tech/tags/building-make-popular.md>), [cc](<https://devfeed.tech/tags/cc.md>), [command](<https://devfeed.tech/tags/command.md>), [commands](<https://devfeed.tech/tags/commands.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [conditional](<https://devfeed.tech/tags/conditional.md>), [conditionals](<https://devfeed.tech/tags/conditionals.md>), [debug](<https://devfeed.tech/tags/debug.md>), [debugging](<https://devfeed.tech/tags/debugging.md>), [directives](<https://devfeed.tech/tags/directives.md>), [disk-space](<https://devfeed.tech/tags/disk-space.md>), [echo](<https://devfeed.tech/tags/echo.md>), [endif](<https://devfeed.tech/tags/endif.md>), [environment](<https://devfeed.tech/tags/environment.md>), [error](<https://devfeed.tech/tags/error.md>), [file](<https://devfeed.tech/tags/file.md>), [linux](<https://devfeed.tech/tags/linux.md>), [make](<https://devfeed.tech/tags/make.md>), [popular](<https://devfeed.tech/tags/popular.md>), [scripting](<https://devfeed.tech/tags/scripting.md>), [shell](<https://devfeed.tech/tags/shell.md>)

## AI overview

Makefile conditionals use directives such as `ifeq` and `ifneq` to compare strings, and `ifdef` and `ifndef` to check whether variables are defined. The examples select compiler flags, provide a default compiler, and choose OS-specific behavior. For file checks inside a recipe, the article uses a shell `if`; Make's `$(if ...)` function supports inline conditional values. It also demonstrates checking disk space with `$(shell ...)` and stopping with `$(error ...)`. Recipe lines generally run in separate shell instances, so shell variables do not carry across lines.

## Source excerpt

Learn how to use if-else conditional statements inside of Makefiles. The post Using if-else Conditionals in a Makefile first appeared on Baeldung on Linux. Related Stories How to Identify the Package Manager of a Linux System Background Jobs in a Loop in Bash Executing Commands in Gnuplot through Shell Script