Skip to content

Commit

Permalink
Put build artifacts in build/ so as not to pollute src/ directory. (#19)
Browse files Browse the repository at this point in the history
* Put build artifacts in build/ so as not to pollute src/ directory.

`make clean` becomes simpler, and update gitignore to ignore  `build` directory.

* Create `build/` directory if doesn't exist already.

* Delete entire build/ directory rather than contents only.
  • Loading branch information
SanjitRaman authored Feb 21, 2024
1 parent 71b6a1b commit 2c42dd8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
bin/
build/
.vscode
*.o
*.tab.hpp
Expand Down
28 changes: 12 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
CXXFLAGS += -std=c++20 -W -Wall -g -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -fsanitize=address -static-libasan -O0 -rdynamic -I include

SOURCES := $(wildcard src/*.cpp)
DEPENDENCIES := $(patsubst %.cpp,%.d,$(SOURCES))

OBJECTS := $(patsubst %.cpp,%.o,$(SOURCES))
OBJECTS += src/parser.tab.o src/lexer.yy.o
DEPENDENCIES := $(patsubst src/%.cpp,build/%.d,$(SOURCES))

OBJECTS := $(patsubst src/%.cpp,build/%.o,$(SOURCES))
OBJECTS += build/parser.tab.o build/lexer.yy.o

.PHONY: default clean with_coverage coverage

Expand All @@ -19,14 +18,17 @@ bin/c_compiler: $(OBJECTS)

-include $(DEPENDENCIES)

%.o: %.cpp Makefile
build/%.o: src/%.cpp Makefile
@mkdir -p $(@D)
g++ $(CXXFLAGS) -MMD -MP -c $< -o $@

src/parser.tab.cpp src/parser.tab.hpp: src/parser.y
bison -v -d src/parser.y -o src/parser.tab.cpp
build/parser.tab.cpp build/parser.tab.hpp: src/parser.y
@mkdir -p build
bison -v -d src/parser.y -o build/parser.tab.cpp

src/lexer.yy.cpp : src/lexer.flex src/parser.tab.hpp
flex -o src/lexer.yy.cpp src/lexer.flex
build/lexer.yy.cpp: src/lexer.flex build/parser.tab.hpp
@mkdir -p build
flex -o build/lexer.yy.cpp src/lexer.flex

with_coverage : CXXFLAGS += --coverage
with_coverage : bin/c_compiler
Expand All @@ -43,11 +45,5 @@ coverage/index.html :

clean :
@rm -rf coverage/
@rm -rf src/*.o
@rm -rf src/*.d
@rm -rf src/*.gcno
@rm -rf build/
@rm -rf bin/
@rm -f src/*.tab.hpp
@rm -f src/*.tab.cpp
@rm -f src/*.yy.cpp
@rm -f src/*.output

0 comments on commit 2c42dd8

Please sign in to comment.