C-testing-grounds/makefile

80 lines
1.6 KiB
Makefile
Raw Normal View History

2024-04-08 00:41:29 +02:00
# 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
2024-04-08 01:14:45 +02:00
GITHASH = $(shell git rev-parse --short HEAD)
2024-04-08 00:41:29 +02:00
# Specify the target binary (call it whatever)
2024-04-08 01:14:45 +02:00
TARGET = build/program
TARGET_TAR = $(TARGET)-$(GITHASH).tar.zst
2024-04-08 00:41:29 +02:00
TARGET_SIG = $(TARGET_TAR).minisig
SRCS := $(wildcard src/*.c)
# Specify the object files in the build directory
OBJS := $(patsubst src/%.c,build/%.o,$(SRCS))
2024-04-08 01:14:45 +02:00
all: $(TARGET)
2024-04-08 00:41:29 +02:00
# For convenience
2024-04-08 01:14:45 +02:00
run: $(TARGET)
2024-04-08 00:41:29 +02:00
@./$(TARGET)
2024-04-08 01:14:45 +02:00
# Create the build directory
2024-04-08 00:41:29 +02:00
mkbuilddir:
@mkdir -p build
# Link the object files into the target binary
2024-04-08 01:14:45 +02:00
$(TARGET): $(OBJS)
2024-04-08 00:41:29 +02:00
@$(CC) $(CFLAGS) -o $@ $^
@echo -e "LD \t$^"
# Compile the source files into object files
2024-04-08 01:14:45 +02:00
build/%.o: src/%.c | mkbuilddir
2024-04-08 00:41:29 +02:00
@$(CC) $(CFLAGS) -c -o $@ $< || (rm -f $@ && exit 1)
@echo -e "CC \t$<"
# Print the size of the target binary
2024-04-08 01:14:45 +02:00
size: $(TARGET)
2024-04-08 00:41:29 +02:00
$(SIZE) $(TARGET)
# Clean up the build directory
2024-04-08 01:14:45 +02:00
clean:
2024-04-08 00:41:29 +02:00
rm -r build
rm -f build/*.o
rm -f $(TARGET)*
# Create a signed release
2024-04-08 01:14:45 +02:00
tar: $(TARGET_TAR)
# Sign the tar
sign: $(TARGET_SIG)
2024-04-08 00:41:29 +02:00
$(TARGET_SIG): $(TARGET_TAR)
minisign -Sm $<
$(TARGET_TAR): $(TARGET)
strip $<
tar --zstd -cvf $@ $<
2024-04-08 01:14:45 +02:00
.PHONY: all clean size mkbuilddir run tar sign