CC = gcc
CFLAGS = -Wall -Wextra -no-pie -lm -g -std=c99
SRC = $(wildcard *.c)
TGT = $(subst .c,,$(SRC))
BUILD_DIR = build
DUMP_DIR = dump

$(BUILD_DIR)/%_32: %.c
	$(shell mkdir -p $(BUILD_DIR))
	$(CC) $(CFLAGS) -m32 -o $@ $<


$(BUILD_DIR)/%_64: %.c
	$(shell mkdir -p $(BUILD_DIR))
	$(CC) $(CFLAGS) -m64 -o $@ $<

$(DUMP_DIR)/%_32.txt: $(BUILD_DIR)/%_32
		$(shell mkdir -p $(DUMP_DIR))
		objdump -Sd $< > $@

$(DUMP_DIR)/%_64.txt: $(BUILD_DIR)/%_64
		$(shell mkdir -p $(DUMP_DIR))
		objdump -Sd $< > $@

build: $(addprefix $(BUILD_DIR)/, $(addsuffix _32, $(TGT))) \
	   $(addprefix $(BUILD_DIR)/, $(addsuffix _64, $(TGT)))


dump:  $(addprefix $(DUMP_DIR)/, $(addsuffix _32.txt, $(TGT))) \
	   $(addprefix $(DUMP_DIR)/, $(addsuffix _64.txt, $(TGT)))


PHONY: clean
clean:
	@rm -rf $(BUILD_DIR)
	@rm -rf $(DUMP_DIR)
