# Makefile for COBOL project cleanup and building
# Created on: May 4, 2025

# Compiler settings
COBC = cobc
COBFLAGS = -x -g -debug -Wall
COBFLAGS_DEBUG = -x -g -debug -Wall -O0

# Source files
SOURCES = hello.cob hello.cbl hello2.cbl
C_SOURCES = hello.c hello2.c

# Executables
EXECS = hello hello2

# Default target
all: $(EXECS)

# Build rules
hello: hello.cob
	$(COBC) $(COBFLAGS) -o $@ $<

hello.cbl.exe: hello.cbl
	$(COBC) $(COBFLAGS_DEBUG) -o $@ $<

hello2: hello2.cbl
	$(COBC) $(COBFLAGS) -o $@ $<

# Clean up intermediate files and executables
clean:
	rm -f *.o *.so *.exe *.int *.lst *.idb *.c *.h *.i *.c.h
	rm -f id3cobol zero-ord

# Deep clean (includes all build artifacts)
distclean: clean
	rm -f *.log *.bak *~

# Debug build with optimizations disabled
debug: COBFLAGS = $(COBFLAGS_DEBUG)
debug: all

# Help target
help:
	@echo "Makefile targets:"
	@echo "  all        - Build all executables (default)"
	@echo "  clean      - Remove intermediate files (.i, .c, .c.h, etc.)"
	@echo "  distclean  - Remove intermediate files and executables"
	@echo "  debug      - Build with full debug options and no optimization"
	@echo "  hello      - Build only hello executable"
	@echo "  hello2     - Build only hello2 executable"
	@echo ""
	@echo "Examples:"
	@echo "  make clean      - Clean intermediate files"
	@echo "  make debug      - Build with debugging enabled"

# Prevent conflicts with files named like our targets
.PHONY: all clean distclean debug help