diff options
| -rw-r--r-- | .editorconfig | 3 | ||||
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | Makefile | 14 | ||||
| -rw-r--r-- | README.md | 11 | ||||
| -rw-r--r-- | justfile | 18 | ||||
| -rw-r--r-- | src/cli.c | 4 | ||||
| -rw-r--r-- | src/preprocess.c | 4 | ||||
| -rw-r--r-- | tests/run.sh | 2 |
8 files changed, 44 insertions, 15 deletions
diff --git a/.editorconfig b/.editorconfig index 13a634c..c3ca3da 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,3 +8,6 @@ indent_style = space insert_final_newline = true max_line_length = 120 trim_trailing_whitespace = true + +[Makefile] +indent_style = tab @@ -1,3 +1,2 @@ -/main*.s -/ducc* +/build /tests/tmp diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6eb170a --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +SRC_DIR := src +BUILD_DIR := build +TARGET ?= ducc + +.PHONY: all +all: $(BUILD_DIR) $(BUILD_DIR)/$(TARGET) + +$(BUILD_DIR)/$(TARGET): main.c + $(CC) -MD -g -O0 -o $@ $< + +$(BUILD_DIR): + @mkdir -p $(BUILD_DIR) + +-include $(BUILD_DIR)/*.d @@ -6,7 +6,8 @@ Ducc is a toy C compiler, based on [my another tiny C compiler](https://github.c ## Dependencies * gcc -* [just](https://github.com/casey/just), a general-purpose task runner +* make +* [just](https://github.com/casey/just) ## Build @@ -15,6 +16,10 @@ Ducc is a toy C compiler, based on [my another tiny C compiler](https://github.c $ just build ``` +``` +$ just build-upto-5-gen +``` + ## Test @@ -22,6 +27,10 @@ $ just build $ just test ``` +``` +$ just test-self-hosted +``` + ## License @@ -7,13 +7,14 @@ build N="1": cc=gcc target=ducc elif [[ {{N}} = 2 ]]; then - cc=./ducc + cc=./build/ducc target=ducc{{N}} else - cc="./ducc$(({{N}} - 1))" + cc="./build/ducc$(({{N}} - 1))" target=ducc{{N}} fi - "$cc" -g -O0 -o "$target" main.c + # TODO: Remove --always-make once ducc supports -MD. + CC="$cc" TARGET="$target" make --always-make build-upto-5-gen: just build 1 @@ -23,9 +24,9 @@ build-upto-5-gen: just build 5 test-self-hosted: build-upto-5-gen - diff -u ./ducc2 ./ducc3 - diff -u ./ducc3 ./ducc4 - diff -u ./ducc4 ./ducc5 + diff -u ./build/ducc2 ./build/ducc3 + diff -u ./build/ducc3 ./build/ducc4 + diff -u ./build/ducc4 ./build/ducc5 test TESTCASE="all" $BIN="ducc": build #!/usr/bin/env bash @@ -37,11 +38,10 @@ test TESTCASE="all" $BIN="ducc": build fi test-all: - just test-self-hosted just test all ducc + just test-self-hosted just test all ducc2 clean: - rm -f main*.s - rm -f ducc* + rm -rf build rm -rf tests/tmp @@ -19,12 +19,16 @@ CliArgs* parse_cli_args(int argc, char** argv) { // ignore } else if (c == 'O') { // ignore + } else if (c == 'M') { + // ignore } else if (c == 'o') { if (argc <= i + 1) { fatal_error("-o requires filename"); } output_filename = argv[i + 1]; ++i; + } else { + fatal_error("unknown option: %s", argv[i]); } } if (positional_arguments_start == -1) { diff --git a/src/preprocess.c b/src/preprocess.c index b1810cd..75727d7 100644 --- a/src/preprocess.c +++ b/src/preprocess.c @@ -1535,8 +1535,8 @@ void pp_dump(Token* t, BOOL include_whitespace) { char* get_ducc_include_path() { const char* self_dir = get_self_dir(); - char* buf = calloc(strlen(self_dir) + strlen("/include") + 1, sizeof(char)); - sprintf(buf, "%s/include", self_dir); + char* buf = calloc(strlen(self_dir) + strlen("/../include") + 1, sizeof(char)); + sprintf(buf, "%s/../include", self_dir); return buf; } diff --git a/tests/run.sh b/tests/run.sh index 27bd6d0..728af52 100644 --- a/tests/run.sh +++ b/tests/run.sh @@ -1,6 +1,6 @@ set -e -export ducc="../../../$BIN" +export ducc="../../../build/$BIN" export testcase=$1 export tmp_dir="tests/tmp/$testcase" |
