DBG		= gdb			# debugger
DBG_CMD		= "unset environment"	# debugger commands (initialization)
RUNAS		= setarch i686 -3	# x86, 3GB address space
ENV		= env -i		# empty environment
# LDFLAGS	+= -z norelro		# no RELRO
					# x86 (32-bit) code, stack protector,
					# debug information, warnings
CFLAGS		+= -m32 -fomit-frame-pointer -fstack-protector -ggdb3 \
			-Wall -Wpedantic -Wno-stringop-overflow


# phony targets
.PHONY: all esrv_run esrv_dbg clean

# build everything (default target)
all: esrv expl11

# run the server
esrv_run: esrv
	$(RUNAS) $(ENV) ./$<
# debug the server
esrv_dbg: esrv
	$(RUNAS) $(DBG) -iex=$(DBG_CMD) ./$<

# build the server
esrv: esrv.c
	$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@

# build the exploit
expl11: expl11.c
	$(CC) $(CFLAGS) $< -o $@

# clean
clean:
	$(RM) esrv expl11
