CC ?= gcc
CFLAGS ?= -O0 -g -fno-pie -fno-stack-protector -fcf-protection=none -Wall -Wextra
LDFLAGS ?= -no-pie
ARM_CC ?= arm-linux-gnueabi-gcc
ARM_STRIP ?= arm-linux-gnueabi-strip
ARM_CFLAGS ?= -O0 -g -fno-pie -fno-stack-protector -Wall -Wextra -marm
ARM_LDFLAGS ?= -no-pie
MIPS_CC ?= mips-linux-gnu-gcc
MIPS_STRIP ?= mips-linux-gnu-strip
MIPS_CFLAGS ?= -O0 -g -fno-pie -fno-stack-protector -Wall -Wextra
MIPS_LDFLAGS ?= -no-pie

SRC := src/evalme.c
OUT := bin/evalme
STRIPPED := strip/evalme
ARM_OUT := bin/evalme-arm
ARM_STRIPPED := strip/evalme-arm
MIPS_OUT := bin/evalme-mips
MIPS_STRIPPED := strip/evalme-mips

.PHONY: all arm mips multiarch clean

all: $(OUT) $(STRIPPED)

arm: $(ARM_OUT) $(ARM_STRIPPED)

mips: $(MIPS_OUT) $(MIPS_STRIPPED)

multiarch: arm mips

$(OUT): $(SRC) | bin
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<

$(STRIPPED): $(OUT) | strip
	strip -o $@ $<

$(ARM_OUT): $(SRC) | bin
	$(ARM_CC) $(ARM_CFLAGS) $(ARM_LDFLAGS) -o $@ $<

$(ARM_STRIPPED): $(ARM_OUT) | strip
	$(ARM_STRIP) -o $@ $<

$(MIPS_OUT): $(SRC) | bin
	$(MIPS_CC) $(MIPS_CFLAGS) $(MIPS_LDFLAGS) -o $@ $<

$(MIPS_STRIPPED): $(MIPS_OUT) | strip
	$(MIPS_STRIP) -o $@ $<

bin strip:
	mkdir -p $@

clean:
	rm -f $(OUT) $(STRIPPED) \
	  $(ARM_OUT) $(ARM_STRIPPED) \
	  $(MIPS_OUT) $(MIPS_STRIPPED)
