kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

maint.mk (2254B)


      1 # mk/maint.mk
      2 # ===========================================================================
      3 # Developer maintenance targets: source formatting, the clangd compilation
      4 # database, optimizer benchmarking, and clean.
      5 
      6 .PHONY: format compile-commands bench-opt code-size clean
      7 
      8 # Format only the .c/.h files changed in the working tree (staged, unstaged, or
      9 # new/untracked), restricted to the formatted roots and excluding test/pp. When
     10 # nothing has changed, fall back to formatting every source file.
     11 format:
     12 	@files=$$( { git diff --name-only --diff-filter=ACMR HEAD -- '*.c' '*.h'; \
     13 	             git ls-files --others --exclude-standard -- '*.c' '*.h'; } 2>/dev/null \
     14 	           | grep -E '^(src|include|driver|lang|test|rt)/' \
     15 	           | grep -vE '^test/pp/' \
     16 	           | sort -u ); \
     17 	if [ -n "$$files" ]; then \
     18 	  echo "$$files" | xargs clang-format -i --style=google; \
     19 	  echo "$$files" | sed 's/^/formatted /'; \
     20 	else \
     21 	  echo "no changed sources; formatting all"; \
     22 	  find src include driver lang test rt -path test/pp -prune -o \( -name '*.c' -o -name '*.h' \) -print | xargs clang-format -i --style=google; \
     23 	fi
     24 
     25 # Regenerate the clangd compilation database (build/compile_commands.json).
     26 # clangd auto-discovers it under build/; re-run after adding/removing sources
     27 # or after `make clean`.
     28 compile-commands:
     29 	python3 scripts/gen_compile_commands.py
     30 
     31 bench-opt:
     32 	$(MAKE) RELEASE=1 bin
     33 	@KIT='$(abspath build/release/kit)' bash scripts/opt_bench.sh
     34 
     35 # Regenerate doc/CODE_SIZE.md: per-component cloc line counts plus a binary
     36 # code-size section attributed from the release linker map. Requires cloc.
     37 # The map step relinks the release objects explicitly (not via libkit.a) so the
     38 # full object paths survive in the map and dead_strip still prunes unused code.
     39 RELMAP = build/release/kit.map
     40 ifeq ($(HOST_OS),darwin)
     41 RELMAP_LDFLAG = -Wl,-map,$(RELMAP)
     42 else
     43 RELMAP_LDFLAG = -Wl,-Map=$(RELMAP)
     44 endif
     45 
     46 code-size:
     47 	$(MAKE) RELEASE=1 bin
     48 	$(MAKE) RELEASE=1 $(RELMAP)
     49 	bash scripts/code_size.sh $(RELMAP)
     50 
     51 # Release binary relinked with a linker map (consumed by code-size).
     52 $(RELMAP): $(DRIVER_OBJS) $(LIB_OBJS)
     53 	$(CC) $(HOST_LDFLAGS) $(RELMAP_LDFLAG) -o $(BIN) $(DRIVER_OBJS) $(LIB_OBJS) $(HOST_LDLIBS)
     54 
     55 clean:
     56 	rm -rf $(BUILD_DIR)