Optimization of General Purpose Makefile I wrote a makefile that would generate a simple executable from the example directory structure.
project/
  source/
  include/
  makefile

The makefile itself comes equipped with dependency tracking, and automatically generates two directories named build and dependency. Currently the makefile I made works, yet it takes anywhere from three to five seconds to build the executable on my machine. I was wondering whether my makefile source code was setup inefficiently, or am I just being impatient?
target    := driver.exe
compiler  := g++
ccflags   := -Wall -Werror -pedantic -pedantic-errors -O2 -std=c++17
src_dir   := source
build_dir := build
deps_dir  := dependency
ccfiles   := $(wildcard $(src_dir)/*.cc)
objects   := $(patsubst $(src_dir)/%.cc, $(build_dir)/%.o, $(ccfiles))

deps := $(patsubst $(build_dir)/%.o, $(deps_dir)/%.d, $(objects))
-include $(deps)
deps_flags = -MMD -MF $(@:$(build_dir)/%.o=$(deps_dir)/%.d)

$(target): $(objects)
    @$(compiler) -o $@ $^
    @echo &quot;Successfully built &quot;$@&quot;!&quot;

$(build_dir)/%.o: $(src_dir)/%.cc | setup
    @$(compiler) $(cflags) -o $@ -c $&lt; $(deps_flags)
    @echo &quot;Successfully built &quot;$&lt;&quot; into &quot;$@&quot;!&quot;

.PHONY: setup
setup:
    @mkdir -p $(build_dir) $(deps_dir)

.PHONY: clean
clean:
    rm -rf $(target) $(build_dir) $(deps_dir)
Instead of defining your own compiler variable, I would override the implicit CXX variable. This also goes for the implicit CXXFLAGS (instead of your ccflags).
This allows other users to easily change the compiler used when using a different environment than you.
You might also want to remove all the leading @ in favour of make -s