Make polishing

This commit is contained in:
Imbus 2024-04-08 01:14:45 +02:00
parent 7c747ad404
commit 5f94263789

View file

@ -22,9 +22,11 @@ CFLAGS += -Wno-unused-macros
CFLAGS += -O3 CFLAGS += -O3
CFLAGS += -g CFLAGS += -g
GITHASH = $(shell git rev-parse --short HEAD)
# Specify the target binary (call it whatever) # Specify the target binary (call it whatever)
TARGET = build/bin.elf TARGET = build/program
TARGET_TAR = $(TARGET).tar.zst TARGET_TAR = $(TARGET)-$(GITHASH).tar.zst
TARGET_SIG = $(TARGET_TAR).minisig TARGET_SIG = $(TARGET_TAR).minisig
SRCS := $(wildcard src/*.c) SRCS := $(wildcard src/*.c)
@ -32,45 +34,41 @@ SRCS := $(wildcard src/*.c)
# Specify the object files in the build directory # Specify the object files in the build directory
OBJS := $(patsubst src/%.c,build/%.o,$(SRCS)) OBJS := $(patsubst src/%.c,build/%.o,$(SRCS))
all : $(TARGET) all: $(TARGET)
release : $(TARGET)
@strip $(TARGET)
@upx -q --force-overwrite $(TARGET) -o $(TARGET).upx > /dev/null
@minisign -Sm $(TARGET)
@tar --zstd -cvf $(TARGET).tar.zst $(TARGET) $(TARGET).minisig 1>/dev/null
@zip $(TARGET).zip $(TARGET) $(TARGET).minisig 1>/dev/null
@7za a $(TARGET).7z $(TARGET) $(TARGET).minisig 1>/dev/null
# For convenience # For convenience
run : $(TARGET) run: $(TARGET)
@./$(TARGET) @./$(TARGET)
# Create the build directory
mkbuilddir: mkbuilddir:
@mkdir -p build @mkdir -p build
# Link the object files into the target binary # Link the object files into the target binary
$(TARGET) : $(OBJS) $(TARGET): $(OBJS)
@$(CC) $(CFLAGS) -o $@ $^ @$(CC) $(CFLAGS) -o $@ $^
@echo -e "LD \t$^" @echo -e "LD \t$^"
# Compile the source files into object files # Compile the source files into object files
build/%.o : src/%.c | mkbuilddir build/%.o: src/%.c | mkbuilddir
@$(CC) $(CFLAGS) -c -o $@ $< || (rm -f $@ && exit 1) @$(CC) $(CFLAGS) -c -o $@ $< || (rm -f $@ && exit 1)
@echo -e "CC \t$<" @echo -e "CC \t$<"
# Print the size of the target binary # Print the size of the target binary
size : $(TARGET) size: $(TARGET)
$(SIZE) $(TARGET) $(SIZE) $(TARGET)
# Clean up the build directory # Clean up the build directory
clean : clean:
rm -r build rm -r build
rm -f build/*.o rm -f build/*.o
rm -f $(TARGET)* rm -f $(TARGET)*
# Create a signed release # Create a signed release
tar: $(TARGET_TAR) $(TARGET_SIG) tar: $(TARGET_TAR)
# Sign the tar
sign: $(TARGET_SIG)
$(TARGET_SIG): $(TARGET_TAR) $(TARGET_SIG): $(TARGET_TAR)
minisign -Sm $< minisign -Sm $<
@ -79,4 +77,4 @@ $(TARGET_TAR): $(TARGET)
strip $< strip $<
tar --zstd -cvf $@ $< tar --zstd -cvf $@ $<
.PHONY : all clean size mkbuilddir run gdb .PHONY: all clean size mkbuilddir run tar sign