# Default build directory

ifndef BUILD_DIR
BUILD_DIR = build
endif

# Default compiler and flags

ifeq ($(CC),cc)
CC = gcc
LD = $(CC)
endif

CFLAGS += -Wall -O2 -DENABLE_ALL_CHIPS

# Objects and targets

OBJDIR = $(BUILD_DIR)/obj
OBJS = $(patsubst src/%.c, %.o, $(wildcard src/*.c))

.PHONY: all clean $(OBJS)

all: $(OBJS:%=$(OBJDIR)/%)

clean:
	rm -rf $(BUILD_DIR)

$(OBJS:%=$(OBJDIR)/%): $(OBJDIR)/%.o : src/%.c src/%.h | $(OBJDIR)
	$(CC) $(CFLAGS) -c $< -o $@

$(OBJDIR):
	mkdir -p $@
