Skip to content
Open
Show file tree
Hide file tree
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
40 changes: 40 additions & 0 deletions gnumake/custom/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Compiler and flags
CC := gcc
CFLAGS := -Wall -Wextra -g

# Conditional block (debug vs release)
ifeq ($(DEBUG),1)
CFLAGS += -DDEBUG
else
CFLAGS += -O2
endif

# Targets
TARGETS := greeting parts

# Function to get executable name
make_exec = $(basename $(notdir $(1)))

# Default rule
all: $(TARGETS)

# Include extra rules
include extra.mk

# Build greeting executable from greeting.c
greeting: greeting.c
@echo "Compiling greeting.c..."
$(CC) $(CFLAGS) -o $(call make_exec,$<) $<

# Build parts executable using part1.c, part2.c and header.h
parts: part1.c part2.c header.h
@echo "Compiling parts (part1 + part2)..."
$(CC) $(CFLAGS) -o parts part1.c part2.c

# Clean rule
clean:
@echo "Cleaning executables..."
rm -f greeting parts

# Phony rules
.PHONY: all clean help
9 changes: 9 additions & 0 deletions gnumake/custom/extra.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Extra Makefile with additional rule

help:
@echo "Available commands:"
@echo " make - build all targets"
@echo " make greeting - build greeting program"
@echo " make parts - build parts program"
@echo " make clean - remove executables"
@echo " make DEBUG=1 - build with debug flags"