From a820f1f0322eaa55c75db9ac345e5233c6916ff2 Mon Sep 17 00:00:00 2001 From: TolaMironcenko Date: Sat, 7 Feb 2026 19:38:52 +0700 Subject: [PATCH] added cmake meson update makefile and update actions --- .gitea/workflows/actions.yaml | 53 +++++++++++++++++++++++++++++------ .gitignore | 4 ++- CMakeLists.txt | 16 +++++++++++ Makefile | 38 ++++++++++--------------- meson.build | 3 ++ src/{sudo.c => main.c} | 0 6 files changed, 82 insertions(+), 32 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 meson.build rename src/{sudo.c => main.c} (100%) diff --git a/.gitea/workflows/actions.yaml b/.gitea/workflows/actions.yaml index 6080ca2..0497311 100644 --- a/.gitea/workflows/actions.yaml +++ b/.gitea/workflows/actions.yaml @@ -3,14 +3,51 @@ run-name: ${{ gitea.actor }} on: [push] jobs: - Prepare-Build-Testing: - runs-on: alpine-sdk + Prepare-Build-Testing-With-Make: + runs-on: ubuntu-latest steps: - - name: prepare-container - run: echo "185.130.83.26 gitea.home.com" >> /etc/hosts - name: Check out repository code uses: actions/checkout@v3 - - name: Building binary - run: make - - name: Testing to run binary - run: ./bin/sudo ls + - name: Building binary with make + run: | + make -j$(nproc) && \ + chown 0:0 sudo && \ + chmod 4755 sudo + - name: Testing binary + run: ./sudo ls + + Prepare-Build-Testing-With-CMake: + runs-on: ubuntu-latest + steps: + - name: prepare-container + run: | + apt install -y cmake + - name: Check out repository code + uses: actions/checkout@v3 + - name: Building binary with CMake + run: | + mkdir build && \ + cd build && \ + cmake .. && \ + make -j$(nproc) && \ + chown 0:0 sudo && \ + chmod 4755 sudo + - name: Testing binary + run: ./build/sudo ls + + Prepare-Build-Testing-With-Meson: + runs-on: ubuntu-latest + steps: + - name: prepare-container + run: | + apt install -y meson + - name: Check out repository code + uses: actions/checkout@v3 + - name: Building binary with meson + run: | + meson setup build && \ + meson compile -C build && \ + chown 0:0 build/sudo && \ + chmod 4755 build/sudo + - name: Testing binary + run: ./build/sudo ls diff --git a/.gitignore b/.gitignore index 9b6cedc..cd5da50 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ bin .vscode sudo.pkg -sudo.pkg.gz \ No newline at end of file +sudo.pkg.gz +build +.cache diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..cf9ce12 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required (VERSION 3.6) +project(sudo LANGUAGES C) + +set(CMAKE_C_STANDARD 23) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +# include_directories(./src/libs/) +FILE(GLOB_RECURSE SOURCES src/*.c) + +# find_package(package-name REQUIRED) + +add_executable( + sudo + ${SOURCES} +) +# target_link_libraries(project_name package-name::package-name) diff --git a/Makefile b/Makefile index 8790478..77ec485 100644 --- a/Makefile +++ b/Makefile @@ -1,28 +1,20 @@ -CC=gcc -CFLAGS=-Wall -SOURCES=src/sudo.c -TARGET=bin/sudo +CC = gcc +CFLAGS = -Wall -g -std=gnu2x +LDFLAGS = +LIBS = +INCLUDES = -I./src/lib -I./src +SRCS = $(wildcard src/*.c src/lib/*.c) +OBJS = $(SRCS:.c=.o) +TARGET = sudo +CROSS_COMPILE = -default: all +all: $(TARGET) -all: build +$(TARGET): $(OBJS) + $(CROSS_COMPILE)$(CC) $(LDFLAGS) $^ -o $@ $(LIBS) -build: - @if [ ! -d bin ]; then \ - mkdir bin; \ - fi - $(CC) -o $(TARGET) $(SOURCES) $(CFLAGS) - chown -v 0:0 $(TARGET) - chmod 4755 $(TARGET) +%.o: %.c + $(CROSS_COMPILE)$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@ clean: - rm -v $(TARGET) - -package: - mkdir -pv sudo.pkg/usr/bin - cp -v $(TARGET) sudo.pkg/usr/bin/sudo - echo "/usr/bin/sudo" > sudo.pkg/list - printf "#!/bin/sh\nchown -v 0:0 /usr/bin/sudo\nchmod 4755 /usr/bin/sudo" > sudo.pkg/post_install - chmod +x sudo.pkg/post_install - tar -czvf sudo.pkg.gz sudo.pkg - \ No newline at end of file + rm -f $(OBJS) $(TARGET) $(shell find . -type f -name '*.log') users.db diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..1494f78 --- /dev/null +++ b/meson.build @@ -0,0 +1,3 @@ +project('sudo', 'c', default_options: ['cpp_std=c20']) +include_dirs = include_directories('src') +executable('sudo', 'src/main.c', include_directories: include_dirs, install: true) diff --git a/src/sudo.c b/src/main.c similarity index 100% rename from src/sudo.c rename to src/main.c