# Format String Attack -- server-code Makefile.
#
# Two settings make this build portable across host Ubuntu versions:
#
#  * STD (-std=gnu17): the default on the SEED 20.04 VM's gcc 9, so it changes
#    nothing there; it is added so the build also works on newer gcc (14+),
#    which defaults to C23 and would reject server.c's old-style prototype.
#
#  * -static on ALL targets: the container image is Ubuntu 20.04 (glibc 2.31),
#    but you may be compiling on a newer host (e.g. Ubuntu 22.04/24.04) with a
#    newer glibc. A dynamically-linked binary built there asks the container for
#    a GLIBC version it does not have ("GLIBC_2.34 not found") and the server
#    exits immediately. Linking statically bakes libc into each binary, so the
#    same binary runs inside the 20.04 container regardless of your host.

STD      = -std=gnu17
FLAGS    = -z execstack
FLAGS_32 = -static -m32
FLAGS_64 = -static
TARGET   = server format-32 format-64

L = 100

all: $(TARGET)

server: server.c
	gcc $(STD) -static -o server server.c

format-32: format.c
	gcc $(STD) -DBUF_SIZE=$(L) $(FLAGS) $(FLAGS_32) -o $@ format.c

format-64: format.c
	gcc $(STD) -DBUF_SIZE=$(L) $(FLAGS) $(FLAGS_64) -o $@ format.c

clean:
	rm -f badfile $(TARGET)

install:
	cp server ../fmt-containers
	cp format-* ../fmt-containers
