diff options
| author | Jacob McDonnell <jacob@jacobmcdonnell.com> | 2025-05-29 20:10:01 -0400 |
|---|---|---|
| committer | Jacob McDonnell <jacob@jacobmcdonnell.com> | 2025-05-29 20:10:01 -0400 |
| commit | 5b05099d44ae6ac962be108f4c0da7493a9305c7 (patch) | |
| tree | 1b796b3ff1491e83f26c9ba09fd6c48feac7c994 | |
| -rw-r--r-- | LICENSE | 21 | ||||
| -rw-r--r-- | README.md | 9 | ||||
| -rw-r--r-- | file-list.txt | 5 | ||||
| -rw-r--r-- | makefile | 28 | ||||
| -rwxr-xr-x | scripts/copy.sh | 6 | ||||
| -rw-r--r-- | src/hello.c | 20 | ||||
| -rw-r--r-- | src/io.c | 27 | ||||
| -rw-r--r-- | src/io.h | 10 | ||||
| -rw-r--r-- | src/makefile | 29 | ||||
| -rw-r--r-- | version.txt | 1 |
10 files changed, 156 insertions, 0 deletions
@@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Jacob McDonnell + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..8896af7 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# Simple Build System + +This is a simple build system based around makefiles & shell scripts. To adapt this system to your own project you will need to edit the following files: + +- file-list.txt +- version.txt +- makefile + +When you call make, the makefile will call make in the src directory with the target make rule. So if you modify the target rule, that will be called. All of the files in file-list.txt will be copied from the left path to the right path in the build directory. diff --git a/file-list.txt b/file-list.txt new file mode 100644 index 0000000..b08ed0d --- /dev/null +++ b/file-list.txt @@ -0,0 +1,5 @@ +src/hello --> hello +src --> src +LICENSE --> LICENSE +version.txt --> version.txt +README.md --> README.md diff --git a/makefile b/makefile new file mode 100644 index 0000000..922e9e2 --- /dev/null +++ b/makefile @@ -0,0 +1,28 @@ +VERSION = $(shell cat version.txt) +TARGET_APPLICATION = hello +BUILD_DIR = $(TARGET_APPLICATION)-$(VERSION) +TARGET_FILE_LIST = file-list.txt +SUB_DIRS = src +SCRIPT_DIR = scripts +TARBALL = $(BUILD_DIR).tgz + +all: $(TARBALL) + +clean: + $(MAKE) -C src $@ + rm -rf $(BUILD_DIR) $(TARBALL) $(TARBALL).checksum + +$(TARBALL): $(BUILD_DIR) $(TARGET_FILE_LIST) $(TARGET_APPLICATION) + $(SCRIPT_DIR)/copy.sh $(BUILD_DIR) $(TARGET_FILE_LIST) + tar cvfz $(TARBALL) $(BUILD_DIR)/* + sha256sum $(TARBALL) > $(TARBALL).checksum + +$(TARGET_APPLICATION): src + $(MAKE) -C $^ $@ + + +$(BUILD_DIR): + mkdir $@ + +.PHONY: all + diff --git a/scripts/copy.sh b/scripts/copy.sh new file mode 100755 index 0000000..293ceea --- /dev/null +++ b/scripts/copy.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +while read e; do + $(echo $e | sed -E "s/(.*[^ ]) +--> +([^ ].*)/cp -r \1 $1\/\2/") +done < $2 + diff --git a/src/hello.c b/src/hello.c new file mode 100644 index 0000000..b69ccdf --- /dev/null +++ b/src/hello.c @@ -0,0 +1,20 @@ +#include <stdio.h> +#include <stdbool.h> +#include <string.h> +#include "io.h" + +int main(void) { + char buffer[BUFSIZ] = {0}; + if (!ReadFile("version.txt", BUFSIZ, buffer)) { + return -1; + } + + char *b = strrchr(buffer, '\n'); + if (b != NULL) { + *b = '\0'; + } + + printf("Hello %s\n", buffer); + return 0; +} + diff --git a/src/io.c b/src/io.c new file mode 100644 index 0000000..78f679a --- /dev/null +++ b/src/io.c @@ -0,0 +1,27 @@ +#include <stdio.h> +#include <stdbool.h> + +bool ReadFile(const char * const path, const size_t n, char * const buffer) { + FILE *fp = fopen(path, "r"); + if (fp == NULL) { + perror("ReadFile: fopen"); + return false; + } + + int j = 0; + size_t i = 0; + for (; i < n - 1; i++) { + j = fgetc(fp); + if (j == EOF) { + break; + } + buffer[i] = (char)j; + } + + buffer[i] = '\0'; + + bool ret = (!ferror(fp) && feof(fp)); + fclose(fp); + return ret; +} + diff --git a/src/io.h b/src/io.h new file mode 100644 index 0000000..7555ee5 --- /dev/null +++ b/src/io.h @@ -0,0 +1,10 @@ +#ifndef _IO_H +#define _IO_H + +#include <stddef.h> +#include <stdbool.h> + +bool ReadFile(const char * const path, const size_t n, char * const buffer); + +#endif + diff --git a/src/makefile b/src/makefile new file mode 100644 index 0000000..ce91b59 --- /dev/null +++ b/src/makefile @@ -0,0 +1,29 @@ +CC = gcc-14 +CFLAGS = -Wall \ + -Werror \ + -Wextra \ + -Wpedantic \ + -std=c17 +SOURCE_DIR = . +SOURCES = hello.c io.c +OBJECT_DIR = object +OBJECTS = $(SOURCES:%.c=$(OBJECT_DIR)/%.o) +TARGET = hello + +all: $(TARGET) + +debug: CFLAGS += -g -O0 +debug: $(TARGET) + +clean: + rm -rf $(TARGET) $(OBJECT_DIR) + +$(TARGET): $(OBJECTS) | $(BIN_DIR) + $(CC) $(CFLAGS) -o $@ $^ + +$(OBJECT_DIR)/%.o: %.c | $(OBJECT_DIR) + $(CC) $(CFLAGS) -c $^ -o $@ + +$(OBJECT_DIR) $(BIN_DIR): + mkdir $@ + diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..45c7a58 --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +v0.0.1 |
