aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-08-23 10:15:46 +0900
committernsfisis <nsfisis@gmail.com>2025-08-23 18:44:30 +0900
commit86cb94c72347d7439980e69a69797d6f8a1688d6 (patch)
tree4c262aeb3da553c1227ede44465f050dfa5831aa
parent8646e6f693fd935c6cb81e776a6c92a3fd093a33 (diff)
downloadducc-86cb94c72347d7439980e69a69797d6f8a1688d6.tar.gz
ducc-86cb94c72347d7439980e69a69797d6f8a1688d6.tar.zst
ducc-86cb94c72347d7439980e69a69797d6f8a1688d6.zip
feat: use "make" as builder
-rw-r--r--.editorconfig3
-rw-r--r--.gitignore3
-rw-r--r--Makefile14
-rw-r--r--README.md11
-rw-r--r--justfile18
-rw-r--r--src/cli.c4
-rw-r--r--src/preprocess.c4
-rw-r--r--tests/run.sh2
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
diff --git a/.gitignore b/.gitignore
index d821e9c..fbd12ac 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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
diff --git a/README.md b/README.md
index 6ead681..5a69b1e 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/justfile b/justfile
index d6528a9..d932989 100644
--- a/justfile
+++ b/justfile
@@ -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
diff --git a/src/cli.c b/src/cli.c
index a54bf5d..c8bb60c 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -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"