Created
April 2, 2024 05:55
-
-
Save KevinAlavik/dd02b16369314784c0c9a0eb7e6dad3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CC ?= gcc | |
CFLAGS := -Wall -Wno-newline-eof -pedantic -Werror -Wshadow -Wstrict-aliasing -Wstrict-overflow -O3 | |
LDFLAGS := | |
BIN_DIR := bin | |
OBJ_DIR := build | |
SRC_DIR := src | |
DESTDIR ?= /usr/local/bin | |
TARGET_NAME := main | |
TARGET := $(BIN_DIR)/$(TARGET_NAME) | |
SRC := $(wildcard $(addsuffix /*.c*, $(SRC_DIR)) $(addsuffix /*.c*, $(SRC_DIR)/devices)) | |
OBJ := $(addprefix $(OBJ_DIR)/, $(addsuffix .o, $(notdir $(basename $(SRC))))) | |
.PHONY: all | |
all: $(TARGET) | |
$(TARGET): $(OBJ) | |
@mkdir -p $(@D) | |
@printf " LD $(notdir $@)\n" | |
@$(CC) $(LDFLAGS) $(OBJ) -o $@ | |
$(OBJ_DIR)/%.o: $(SRC_DIR)/devices/%.c | |
@mkdir -p $(@D) | |
@printf " CC $<\n" | |
@$(CC) $(CFLAGS) -c $< -o $@ | |
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | |
@mkdir -p $(@D) | |
@printf " CC $<\n" | |
@$(CC) $(CFLAGS) -c $< -o $@ | |
.PHONY: install | |
install: $(TARGET) | |
@install -m 755 $(TARGET) $(DESTDIR) | |
.PHONY: format | |
format: | |
@clang-format -i $(shell find src -name "*.c" -o -name "*.h") | |
.PHONY: clean | |
clean: | |
@rm -rf $(BIN_DIR) $(BUILD_DIR) $(OBJ_DIR) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment