Skip to content

Commit

Permalink
Recompile only when source code is modified
Browse files Browse the repository at this point in the history
  • Loading branch information
wberube committed Sep 15, 2024
1 parent f6fdafd commit 4a9f455
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/.vscode/settings.json
/obj
/src/**/*.o
/toolchain
divinus
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ toolchain() {
fi
rm -f $1.$EXT
fi
make -j $(nproc) -C src -B CC=$PWD/toolchain/$1/bin/$2-$PRE-gcc OPT="$OPT $3"
make -j $(nproc) -C src CC=$PWD/toolchain/$1/bin/$2-$PRE-gcc OPT="$OPT $3"
}

if [ "$2" = "debug" ]; then
Expand Down
18 changes: 12 additions & 6 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
OBJ := $(shell find ./ -name '*.c' | sed -e "s/\.c/\.o/")

%.o: %.c
@mkdir -p ../obj/$(shell dirname $<)
$(CC) $< -I src $(OPT) -c -o ../obj/$@
SRC = $(shell find ./ -name '*.c')
OBJ = ../divinus

.PHONY: clean divinus
divinus: $(OBJ)
$(CC) $(addprefix ../obj/,$^) -rdynamic $(OPT) -o ../$@

$(OBJ): $(SRC:%.c=%.o)
$(CC) $^ -rdynamic $(OPT) -o $@

%.o: %.c Makefile
$(CC) -c $< -o $@

clean:
rm -rf $(SRC:%.c=%.o) $(OBJ)

0 comments on commit 4a9f455

Please sign in to comment.