
SRC_DIR := ./src
BUILD_DIR := ./build

EXEC ?= cpu-schedulers
INSTALL ?= $(PREFIX)/bin/

# Find all the C files we want to compile
SRCS := $(shell find $(SRC_DIR) -name '*.c')
OBJS := $(SRCS:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o)

.PHONY: build install clean

build: $(BUILD_DIR)/$(EXEC)
install: build
	mkdir -p $(INSTALL)
	cp $(BUILD_DIR)/$(EXEC) $(INSTALL)


# Link
$(BUILD_DIR)/$(EXEC): $(OBJS)
	$(CC) $^ -o $@ $(LDFLAGS)

# Compile
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
	mkdir -p $(dir $@)
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@


clean:
	rm -r $(BUILD_DIR)
