From dcfa7750a27dc550159c2f7968f1cad55430bdff Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Mon, 8 Apr 2024 00:41:29 +0200 Subject: [PATCH] Initial --- makefile | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.c | 6 ++++ 2 files changed, 88 insertions(+) create mode 100644 makefile create mode 100644 src/main.c diff --git a/makefile b/makefile new file mode 100644 index 0000000..7201c37 --- /dev/null +++ b/makefile @@ -0,0 +1,82 @@ +# Compiler and assembler +CC = gcc +AS = as +LD = ld +OBJDUMP = objdump +SIZE = size + +CFLAGS += -std=c2x +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 += -O3 +CFLAGS += -g + +# Specify the target binary (call it whatever) +TARGET = build/bin.elf +TARGET_TAR = $(TARGET).tar.zst +TARGET_SIG = $(TARGET_TAR).minisig + +SRCS := $(wildcard src/*.c) + +# Specify the object files in the build directory +OBJS := $(patsubst src/%.c,build/%.o,$(SRCS)) + +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 +run : $(TARGET) + @./$(TARGET) + +mkbuilddir: + @mkdir -p build + +# Link the object files into the target binary +$(TARGET) : $(OBJS) + @$(CC) $(CFLAGS) -o $@ $^ + @echo -e "LD \t$^" + +# Compile the source files into object files +build/%.o : src/%.c | mkbuilddir + @$(CC) $(CFLAGS) -c -o $@ $< || (rm -f $@ && exit 1) + @echo -e "CC \t$<" + +# Print the size of the target binary +size : $(TARGET) + $(SIZE) $(TARGET) + +# Clean up the build directory +clean : + rm -r build + rm -f build/*.o + rm -f $(TARGET)* + +# Create a signed release +tar: $(TARGET_TAR) $(TARGET_SIG) + +$(TARGET_SIG): $(TARGET_TAR) + minisign -Sm $< + +$(TARGET_TAR): $(TARGET) + strip $< + tar --zstd -cvf $@ $< + +.PHONY : all clean size mkbuilddir run gdb diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..6aad8a5 --- /dev/null +++ b/src/main.c @@ -0,0 +1,6 @@ +#include + +int main(int argc, const char **argv) { + printf("Hello, World!\n"); + return 0; +}