#
# Makefile for building telephone executable.
#
# Both executables use csapp.c and csapp.h for shared functionality,
# and they are built independently.
#

SHELL = /bin/bash
CC = gcc
CLANG_FORMAT = clang-format

CFLAGS = -g -Og -Wall -Wno-unused-result -std=c99 -MMD
CPPFLAGS = -D_FORTIFY_SOURCE=2 -D_XOPEN_SOURCE=700 -I.
LDLIBS = -lpthread -lm
LDLIBS += -Wl,-rpath

# Default target: build both executables.
all: telephone

# Build telephone executable.
telephone: telephone.o csapp.o
	$(CC) $(CFLAGS) -o $@ telephone.o csapp.o $(LDLIBS)

# Generic rule for building .o files from .c files.
%.o: %.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<

# Clean up build artifacts.
clean:
	rm -f *.o *.d telephone

# Include dependency files generated by the -MMD flag.
-include *.d
