Reworked the building process

This commit is contained in:
Tomas Rivera
2026-04-13 17:59:37 +02:00
parent 112756f3e1
commit 74566df6d0
8 changed files with 107 additions and 49 deletions
+11 -41
View File
@@ -1,52 +1,22 @@
# Configuration
CONFIG_DIR := $(HOME)/.config/notewrapper
CONFIG_FILE := $(CONFIG_DIR)/config.json
CACHE_DIR := $(HOME)/.cache/notewrapper
# Compiler and flags
CC := gcc
CFLAGS := -Wall -O2 `pkg-config --cflags libcjson ncurses`
LDFLAGS := `pkg-config --libs libcjson ncurses`
DEBUG ?= 0
ifeq ($(DEBUG),1)
CFLAGS += -g
endif
CFLAGS := -Wall -Wextra -O2 \
$(shell pkg-config --cflags libcjson ncurses)
# Sources and target
SRC_DIR := src
SRC := $(SRC_DIR)/main.c $(SRC_DIR)/ui.c $(SRC_DIR)/utils.c $(SRC_DIR)/notes.c
LDFLAGS := $(shell pkg-config --libs libcjson ncurses)
SRC := src/main.c src/ui.c src/utils.c src/notes.c
TARGET := notewrapper
# Phony targets
.PHONY: all clean run install_config create_cache_dir
.PHONY: all run clean
# Default target
all: install_config create_cache_dir $(TARGET)
all: $(TARGET)
# Build target
$(TARGET): $(SRC)
@$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS)
@echo "Built $(TARGET) successfully."
$(TARGET):
$(CC) $(CFLAGS) $(SRC) -o $(TARGET) $(LDFLAGS)
# Run program
run: $(TARGET)
@./$(TARGET)
./$(TARGET)
# Clean build artifacts
clean:
@rm -f $(TARGET)
@echo "Cleaned $(TARGET)."
# Install default config if it does not exist
install_config:
@mkdir -p $(CONFIG_DIR)
@if [ ! -f $(CONFIG_FILE) ]; then \
cp ./config.json $(CONFIG_FILE); \
echo "config.json installed to $(CONFIG_FILE)"; \
else \
echo "$(CONFIG_FILE) already exists, skipping installing default config file"; \
fi
# creates a dir in ~/.cache/ which is used to store data, such as time of last backup
create_cache_dir:
@mkdir -p $(CACHE_DIR)
rm -f $(TARGET)