mirror of
https://github.com/HerrCraziDev/tiny-kyoukai.git
synced 2025-12-13 09:36:16 +01:00
163 lines
4.7 KiB
Makefile
163 lines
4.7 KiB
Makefile
|
|
PROJECT_NAME = tiny-kyoukai
|
|
BUILD_DIR = build
|
|
SOURCE_DIR = src
|
|
HEADER_DIR = $(SOURCE_DIR)/includes
|
|
|
|
#------------------------------------------------------------------------------
|
|
# SETUP
|
|
#------------------------------------------------------------------------------
|
|
|
|
CC = gcc
|
|
CFLAGS = -std=c11 -g
|
|
LDFLAGS = -g
|
|
LIBS = x11 gtk4 gtk4-x11
|
|
STATIC_LIBS =
|
|
INCLUDES = -I$(HEADER_DIR)
|
|
ifdef LIBS
|
|
LDLIBS = $(shell pkg-config --libs $(LIBS))
|
|
INCLUDES += $(shell pkg-config --cflags $(LIBS))
|
|
endif
|
|
ifdef STATIC_LIBS
|
|
LDLIBS += -Wl,-Bstatic $(shell pkg-config --libs $(STATIC_LIBS)) -Wl,-Bdynamic
|
|
INCLUDES += $(shell pkg-config --cflags $(STATIC_LIBS))
|
|
endif
|
|
|
|
SRC = $(shell find $(SOURCE_DIR)/ -type f -name '*.c') main.c
|
|
NOM = $(basename $(notdir $(SRC)))
|
|
OBJ = $(addprefix $(BUILD_DIR)/,$(addsuffix .o, $(NOM)))
|
|
DEP = $(addprefix $(BUILD_DIR)/,$(addsuffix .d, $(NOM)))
|
|
|
|
# Variables for GResources (GTK)
|
|
RES_DIR = ressources
|
|
RES_PREFIX = kyou
|
|
|
|
RCC = glib-compile-resources
|
|
RCC_OPTS = --c-name $(RES_PREFIX)
|
|
|
|
RES_SRC = $(shell find $(RES_DIR)/ -type f -name '*.gresource.xml')
|
|
RES_NOM = $(basename $(notdir $(RES_SRC)))
|
|
RES = $(addprefix $(SOURCE_DIR)/,$(addsuffix .c, $(RES_NOM)))
|
|
RES_INC = $(addprefix $(HEADER_DIR)/,$(addsuffix .h, $(RES_NOM)))
|
|
RES_OBJ = $(addprefix $(BUILD_DIR)/,$(addsuffix .o, $(RES_NOM)))
|
|
RES_DEP = $(addprefix $(BUILD_DIR)/,$(addsuffix .dep, $(RES_NOM)))
|
|
|
|
# Add GResources objects to general prerequisites
|
|
OBJ := $(RES_OBJ) $(OBJ)
|
|
DEP += $(addprefix $(BUILD_DIR)/,$(addsuffix .d, $(RES_NOM)))
|
|
|
|
# Note: '.d' and '.dep' are different, as CC -MMD would overwrite the resource
|
|
# dependencies generated by glib-compile-resources, and '.d' concerns the
|
|
# '.o' objects made from '.gresource.c', not deps for the latter.
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
# MAIN BUILD RULES
|
|
#------------------------------------------------------------------------------
|
|
|
|
# Main rule
|
|
all: init build
|
|
|
|
# General build
|
|
build: $(PROJECT_NAME)
|
|
|
|
# Build all the .o files in src dir
|
|
$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.c Makefile
|
|
$(CC) $(CFLAGS) -MMD -MP -c $< $(INCLUDES) -o $(BUILD_DIR)/$(notdir $@)
|
|
|
|
# Build all the .o files in base dir
|
|
$(BUILD_DIR)/%.o: %.c Makefile
|
|
$(CC) $(CFLAGS) -MMD -MP -c $< $(INCLUDES) -o $(BUILD_DIR)/$(notdir $@)
|
|
|
|
# Main program
|
|
$(PROJECT_NAME): $(OBJ)
|
|
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
|
|
|
|
# Helloworld
|
|
kyoutest: $(BUILD_DIR)/helloworld.o
|
|
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
|
|
|
|
# Dependancies generated by GCC (for headers)
|
|
-include $(DEP)
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
# GRESOURCES
|
|
#------------------------------------------------------------------------------
|
|
|
|
# Build all GResources from .gresource.xml files in res dir
|
|
$(SOURCE_DIR)/%.gresource.c: $(RES_DIR)/%.gresource.xml $(HEADER_DIR)/%.gresource.h Makefile
|
|
$(eval DEPFILE = $(BUILD_DIR)/$(subst xml,dep,$(notdir $<)))
|
|
printf "$(SOURCE_DIR)/$$(basename $<): " | sed 's/xml/c/g' > $(DEPFILE)
|
|
$(RCC) --generate-dependencies $< --sourcedir=$(RES_DIR) | tr "\n" " " >> $(DEPFILE)
|
|
$(RCC) $< --generate-source $(RCC_OPTS) --target=$@ --sourcedir=$(RES_DIR)
|
|
|
|
# Generate header files from .gresource.xml files in res dir
|
|
$(HEADER_DIR)/%.gresource.h: $(RES_DIR)/%.gresource.xml Makefile
|
|
$(RCC) $< --generate-header $(RCC_OPTS) --target=$@ --sourcedir=$(RES_DIR)
|
|
|
|
# Dependencies generated above
|
|
-include $(RES_DEP)
|
|
|
|
# Utility to pre-generate resource headers
|
|
pregen-res: $(RES_INC)
|
|
|
|
test-res:
|
|
@echo RCC: $(RCC)
|
|
@echo RCC_OPTS: $(RCC_OPTS)
|
|
@echo RES_DIR: $(RES_DIR)
|
|
@echo RES_SRC: $(RES_SRC)
|
|
@echo RES: $(RES)
|
|
@echo RES_OBJ: $(RES_OBJ)
|
|
@echo RES_DEP: $(RES_DEP)
|
|
@echo RES_INC: $(RES_INC)
|
|
|
|
# Keep intermediate C files ! (remove with 'clear')
|
|
.PRECIOUS: $(RES_INC) $(RES)
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
# SILLY RULES
|
|
#------------------------------------------------------------------------------
|
|
|
|
always: SUSSYBAKA
|
|
@echo "Aloha :3"
|
|
|
|
SUSSYBAKA:
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
# UTILITIES
|
|
#------------------------------------------------------------------------------
|
|
|
|
rebuild: clean build
|
|
|
|
init: clear
|
|
mkdir -p $(BUILD_DIR)
|
|
|
|
test:
|
|
@echo CC: $(CC)
|
|
@echo CFLAGS: $(CFLAGS)
|
|
@echo LDFLAGS: $(LDFLAGS)
|
|
@echo LIBS: $(LIBS)
|
|
@echo LDLIBS: $(LDLIBS)
|
|
@echo SOURCE_DIR: $(SOURCE_DIR)
|
|
@echo HEADER_DIR: $(HEADER_DIR)
|
|
@echo OBJ: $(OBJ)
|
|
@echo SRC: $(SRC)
|
|
@echo DEP: $(DEP)
|
|
@echo INCLUDES: $(INCLUDES)
|
|
|
|
run: $(PROJECT_NAME)
|
|
./$(PROJECT_NAME)
|
|
|
|
clean:
|
|
@rm -if $(OBJ) $(DEP) $(RES) $(RES_DEP)
|
|
# @rm -rif *.o *.gch
|
|
# @rm -rif $(BUILD_DIR)/*.o $(BUILD_DIR)/*.gch
|
|
|
|
clear: clean
|
|
@rm -if $(PROJECT_NAME) $(RES_INC)
|
|
|
|
|
|
.PHONY: always init SUSSYBAKA test test-res clear clean run pregen-res |