94 lines
1.9 KiB
Makefile
94 lines
1.9 KiB
Makefile
#dd Compiler and assembler
|
|
CC = gcc
|
|
CXX = g++
|
|
AS = as
|
|
LD = ld
|
|
OBJDUMP = objdump
|
|
SIZE = size
|
|
|
|
CFLAGS += -std=c++23
|
|
CFLAGS += -Wall
|
|
CFLAGS += -Wextra
|
|
CFLAGS += -Werror
|
|
CFLAGS += -Wno-unused-parameter
|
|
CFLAGS += -Wno-unused-variable
|
|
CFLAGS += -Wno-unused-function
|
|
CFLAGS += -Wno-unused-but-set-variable
|
|
CFLAGS += -Wno-unused-value
|
|
CFLAGS += -Wno-unused-label
|
|
CFLAGS += -Wno-unused-result
|
|
CFLAGS += -Wno-unused-local-typedefs
|
|
CFLAGS += -Wno-unused-const-variable
|
|
CFLAGS += -Wno-unused-macros
|
|
CFLAGS += -lsodium
|
|
CFLAGS += -O3
|
|
CFLAGS += -g
|
|
|
|
GITHASH = $(shell git rev-parse --short HEAD)
|
|
|
|
# Specify the target binary (call it whatever)
|
|
TARGET = build/program
|
|
TARGET_TAR = $(TARGET)-$(GITHASH).tar.zst
|
|
TARGET_SIG = $(TARGET_TAR).minisig
|
|
|
|
SRCS := $(wildcard src/*.cpp)
|
|
HDRS := $(wildcard src/*.hpp)
|
|
|
|
# Specify the object files in the build directory
|
|
OBJS := $(patsubst src/%.cpp,build/%.o,$(SRCS))
|
|
|
|
# Print green after success
|
|
all: $(TARGET)
|
|
make size
|
|
@echo -e "\033[0;32m[Success]\033[0m"
|
|
|
|
# For convenience
|
|
run: $(TARGET)
|
|
@./$(TARGET)
|
|
|
|
# Create the build directory
|
|
mkbuilddir:
|
|
@mkdir -p build
|
|
|
|
# Link the object files into the target binary
|
|
$(TARGET): $(OBJS)
|
|
@$(CXX) $(CFLAGS) -o $@ $^
|
|
@echo -e "LD \t$^"
|
|
|
|
# Compile the source files into object files
|
|
build/%.o: src/%.cpp | mkbuilddir
|
|
@$(CXX) $(CFLAGS) -c -o $@ $< || (rm -f $@ && exit 1)
|
|
@echo -e "CC \t$<"
|
|
|
|
# Print the size of the target binary
|
|
size: $(TARGET)
|
|
$(SIZE) $(TARGET)
|
|
|
|
# Format with clang-format
|
|
format: $(SRCS) $(HDRS)
|
|
clang-format -i $^
|
|
|
|
# Clean up the build directory
|
|
clean:
|
|
rm -r build
|
|
rm -f build/*.o
|
|
rm -f $(TARGET)*
|
|
|
|
# Create a signed release
|
|
tar: $(TARGET_TAR)
|
|
|
|
# Sign the tar
|
|
sign: $(TARGET_SIG)
|
|
|
|
# Check the assembly
|
|
asm: $(TARGET)
|
|
$(OBJDUMP) -d $(TARGET)
|
|
|
|
$(TARGET_SIG): $(TARGET_TAR)
|
|
minisign -Sm $<
|
|
|
|
$(TARGET_TAR): $(TARGET)
|
|
strip $<
|
|
tar --zstd -cvf $@ $<
|
|
|
|
.PHONY: all clean size mkbuilddir run tar sign
|