Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions gnumake/custom/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.PHONY: clean

# Compiler flags
CC=gcc
CFLAGS=-Wall -Wextra -std=c99

# Checks if executables exist
GREETING_EXISTS := $(or $(and $(wildcard greeting),1),)
TWOPARTER_EXISTS := $(or $(and $(wildcard twoparter),1),)

# Builds two executables, greeting and twoparter
all: greeting twoparter

# Builds greeting with default compilation settings
greeting: greeting.c

# Builds executable from multiple .c files and a .h header
twoparter: part1.c part2.c header.h
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^

# Removes executables if they exist
clean:
ifdef GREETING_EXISTS
rm greeting
endif
ifdef TWOPARTER_EXISTS
rm twoparter
Comment on lines +23 to +27
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ifdef GREETING_EXISTS / ifdef TWOPARTER_EXISTS will always evaluate true here because both variables are assigned unconditionally (and are non-empty). This makes clean try to remove files even when they don’t exist, and rm will fail the target. Prefer rm -f greeting twoparter, or use ifneq ($(wildcard greeting),) style checks instead of ifdef.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by assigning NULL value instead of 0 in variables

endif