Files
mcaselector-lite/Makefile

117 lines
3.3 KiB
Makefile

# Copyright (C)2026 MCA-Selector-Lite
# Licensed under GPL-2.0-only. For further information,
# view `git log`, and the COPYING and CONTRIBUTORS files
# at www.github.com/thepigeongenerator/mcaselector-lite.
SHELL = /bin/sh
.SUFFIXES:
VERSION = 0.0
NAME = mcaselector-lite
# Include a .config.mk, if it exists.
# Allowing users to write persistent configurations
-include .config.mk
XXD ?= xxd
TAR ?= tar
SPARSE ?= sparse
SRC := $(shell find src/ -name '*.c' -print)
OBJ := $(addsuffix .o,$(SRC))
DEP := $(addsuffix .d,$(SRC))
CFLAGS := -O2 $(CFLAGS) -g -std=gnu17\
-Wall -Wextra -Wpedantic -Wno-pointer-arith -Wvla
CPPFLAGS := -DNDEBUG $(CPPFLAGS) -DGLFW_INCLUDE_NONE\
-Iinclude
LDFLAGS := -flto $(LDFLAGS)
LDLIBS := $(LDLIBS) -lm
# Use pkg-config to locate dependencies, and set the correct flags.
ifeq (,$(shell command -v pkg-config))
$(error Failed to locate pkg-config, please make sure it is installed or acessible through PATH.)
else
CPPFLAGS += $(shell pkg-config --cflags-only-I libarchive)
LDFLAGS += $(shell pkg-config --libs-only-L libarchive)
LDLIBS += $(shell pkg-config --libs-only-l libarchive)
endif
msg = @printf '%-8s %s\n' "$(1)" "$(2)"
# Set Q to @ to silence commands being printed, unless --no-silent has been set
ifeq (0, $(words $(findstring --no-silent,$(MAKEFLAGS))))
Q=@
endif
# detect if we're compiling on Windows, meaning
# a lot of things considered "standard" are unavailable.
ifeq ($(OS),Windows_NT)
NAME := $(NAME).exe
# BUG: I am purposefully neglecting this
LDLIBS += -lopengl32 -lgdi32 $(warning Detected Windows_NT, please refer to the documentation if you encounter issues.)
endif
# Default target; compiles everything.
PHONY = all
all: bin/$(NAME) bin/stripped_$(NAME)
# Install a binary on a POSIX-compliant system.
PHONY += install
install: bin/$(NAME)
install -m0755 bin/$(NAME) $(DESTDIR)/bin/$(NAME)
# Install a stripped binary on a POSIX-compliant system
PHONY += install-strip
install-strip: bin/$(NAME).stripped
install -m0755 bin/stripped_$(NAME) $(DESTDIR)/bin/$(NAME)
PHONY += uninstall
uninstall:
$(RM) $(DESTDIR)/bin/$(NAME)
PHONY += check-sparse
check-sparse: $(SRC)
-$(Q)$(SPARSE) $(CFLAGS) $(CPPFLAGS) $(SRC)
PHONY += check-gcc
check-gcc: $(SRC)
-$(Q)$(CC) -fanalyzer $(CFLAGS) $(CPPFLAGS) $(SRC)
PHONY += clean
clean:
-$(Q)$(RM) $(OBJ) $(DEP)
-$(Q)$(RM) -r bin/
PHONY += CONTRIBUTORS
CONTRIBUTORS:
$(Q)printf "# This file is generated by \`make $@\`, if editing manually, keep it sorted.\n" >CONTRIBUTORS~
$(Q)printf "# List of all contributors of the project:\n" >>CONTRIBUTORS~
$(Q)git log --format='%aN <%aE>%n%cN <%cE>' | sort -u >>CONTRIBUTORS~
$(Q)mv CONTRIBUTORS~ CONTRIBUTORS
# Links together the object files into the final binary.
bin/$(NAME): $(OBJ) | bin/
$(Q)$(call msg,LD,$@)
$(Q)$(CC) $(LDFLAGS) $(LDLIBS) -o $@ $^
bin/stripped_$(NAME): $(OBJ) | bin/
$(Q)$(call msg,LD,$@)
$(Q)$(CC) -s $(LDFLAGS) $(LDLIBS) -o $@ $^
# Compiles C sources into object files
%.c.o: %.c
$(Q)$(call msg,CC,$@)
$(Q)$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
%/:
$(Q)$(call msg,MKDIR,$@)
$(Q)mkdir $@
# Generate and include dependencies,
# ignoring any errors that may occur when doing so.
%.c.d: %.c; $(Q)$(CC) -MM $(CPPFLAGS) -MF $@ $<
ifeq (0, $(words $(findstring $(MAKECMDGOALS), clean)))
-include $(DEP)
endif
.PHONY: $(PHONY)