From c53c7b6988cb1af558115309eaffafd4faf94412 Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Sat, 19 Oct 2024 13:06:27 +0200 Subject: [PATCH] Add actions --- .forgejo/workflows/build.yml | 21 +++++++++++++++++++++ Makefile | 28 +++++++++++----------------- 2 files changed, 32 insertions(+), 17 deletions(-) create mode 100644 .forgejo/workflows/build.yml diff --git a/.forgejo/workflows/build.yml b/.forgejo/workflows/build.yml new file mode 100644 index 0000000..57dbaac --- /dev/null +++ b/.forgejo/workflows/build.yml @@ -0,0 +1,21 @@ +on: [push] +jobs: + deploy: + runs-on: docker + container: alpine + steps: + - run: apt update + - name: Install toolchain + run: apt install --no-install-recommends -y gcc-x86-64-linux-gnu gcc-aarch64-linux-gnu make + - name: Install dependencies + run: apt install -y libelf-dev + - name: Clone repository + run: git clone https://git.m724.eu/Minecon724/crisc . + - name: Package for x86_64 + run: CC=x86_64-linux-gnu-gcc PROGRAM_NAME=crisc-x86_64 make + - name: Package for aarch64 + run: CC=aarch64-linux-gnu-gcc PROGRAM_NAME=crisc-aarch64 make + - name: Upload artifact + uses: https://github.com/actions/upload-artifact@v4 + with: + path: build/criscv-* \ No newline at end of file diff --git a/Makefile b/Makefile index 8bebe20..7e37940 100644 --- a/Makefile +++ b/Makefile @@ -1,24 +1,13 @@ # Compiler to use -CC := gcc +CC ?= gcc -# Compiler flags: -# -Wall: Enable all warnings -# -Wextra: Enable extra warnings -# -std=gnu23: Use GNU C23 standard -# -I include: Add 'include' directory to the include path -# -O3: Optimize code (level 3) -# -Wno-unused-variable: Disable warnings for unused variables -ifeq ($(DEBUG),1) - CFLAGS := -Wall -Wextra -std=gnu23 -I include -O0 -g -lelf -else - CFLAGS := -Wall -Wextra -std=gnu23 -I include -O3 -lelf -endif +BASE_CFLAGS := -Wall -Wextra -std=gnu23 -I include # Directory for build outputs BUILD_DIR := build # Name of the output program -PROGRAM_NAME := criscv +PROGRAM_NAME ?= criscv # Find all .c files in the source directory SRCS := $(wildcard src/*.c) @@ -30,12 +19,17 @@ OBJS := $(patsubst src/%.c,$(BUILD_DIR)/obj/%.o,$(SRCS)) TARGET := $(BUILD_DIR)/$(PROGRAM_NAME) +# Default target: build the executable +all: CFLAGS := $(BASE_CFLAGS) -O3 -lelf +all: $(TARGET) + +# Debug target +debug: CFLAGS := $(BASE_CFLAGS) -O0 -g -lelf +debug: $(TARGET) # Declare 'all' and 'clean' as phony targets (not files) -.PHONY: all clean +.PHONY: all debug static clean -# Default target: build the executable -all: $(TARGET) # Rule to link object files into the final executable $(TARGET): $(OBJS) | $(BUILD_DIR)