coreutils

General Software Utilities
git clone http://git.omkov.net/coreutils
Log | Tree | Refs | README | LICENCE | Download

AuthorJakob Wakeling <[email protected]>
Date2024-04-14 02:04:57
Commita0833470e8f796b539c8de745aab2f5c2c7312a0
Parent60762e4948dabba401775c448a4fbfef23d11880

Replace build script with Makefile

Diffstat

M .gitignore | 1 -
D BuildUNIX.sh | 10 ----------
M CMakeLists.txt | 8 ++++++--
A Makefile | 13 +++++++++++++
M README.md | 3 ++-

5 files changed, 21 insertions, 14 deletions

diff --git a/.gitignore b/.gitignore
index f563e5a..9580025 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,5 +2,4 @@
 /.vscode/
 /bin/
 /build/
-/compile_commands.json
 /lib/
diff --git a/BuildUNIX.sh b/BuildUNIX.sh
deleted file mode 100755
index d59505f..0000000
--- a/BuildUNIX.sh
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/usr/bin/env sh
-dir="$(dirname $(realpath "$0"))"
-
-cmake -S "${dir}" -B "${dir}/build" \
-	-DCMAKE_BUILD_TYPE:STRING=Release \
-	-DCMAKE_EXPORT_COMPILE_COMMANDS=1
-
-cmake --build "${dir}/build"
-
-mv -f "${dir}/build/compile_commands.json" "${dir}/compile_commands.json"
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 23071d6..3472872 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,11 +1,14 @@
-cmake_minimum_required(VERSION 3.14)
+cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
 project(coreutils LANGUAGES C)
 
-set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
+set(CMAKE_C_STANDARD 23)
+set(CMAKE_C_STANDARD_REQUIRED TRUE)
+
 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
+set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
 set(CMAKE_STATIC_LIBRARY_PREFIX "")
 
-file(GLOB SRC_UTIL CONFIGURE_DEPENDS ${PROJECT_SOURCE_DIR}/src/util/*)
+file(GLOB_RECURSE SRC_UTIL CONFIGURE_DEPENDS ${PROJECT_SOURCE_DIR}/src/util/*)
 
 add_library(libutil STATIC ${SRC_UTIL})
 
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..e994e06
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,13 @@
+.PHONY: all build test help
+all: help
+
+build: ## Build the project
+	@cmake -S . -B ./build -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=1
+	@cmake --build ./build
+
+test: build ## Run unit tests
+	@(cd ./build && ctest)
+
+help: ## Display help information
+	@grep -E '^[a-zA-Z_-]+:.*?##.*$$' $(MAKEFILE_LIST) | \
+		awk 'BEGIN {FS = ":.*?## *"}; {printf "\033[36m%-6s\033[0m %s\n", $$1, $$2}'
diff --git a/README.md b/README.md
index 2ff6bd0..b73e8e1 100644
--- a/README.md
+++ b/README.md
@@ -50,11 +50,12 @@ A collection of general software utilities commonly found on UNIX systems.
 
 ### Dependencies
 
+- A C23 capable compiler, to build
 - CMake >= 3.14, to build
 
 ### Building
 
-To build **coreutils** on UNIX, run `BuildUNIX.sh`.
+To build **coreutils**, run `make build`.
 
 ### Running