mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-10-31 00:32:38 +01:00 
			
		
		
		
	Added BUILDDIR, a bit of script reworking
Now littlefs's Makefile can work with a custom build directory for compilation output. Just set the BUILDDIR variable and the Makefile will take care of the rest. make BUILDDIR=build size This makes it very easy to compare builds with different compile-time configurations or different cross-compilers. This meant most of code.py's build isolation is no longer needed, so revisted the scripts and cleaned/tweaked a number of things. Also bought code.py in line with coverage.py, fixing some of the inconsistencies that were created while developing these scripts. One change to note was removing the inline measuring logic, I realized this feature is unnecessary thanks to GCC's -fkeep-static-functions and -fno-inline flags.
This commit is contained in:
		
							
								
								
									
										81
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										81
									
								
								Makefile
									
									
									
									
									
								
							| @@ -1,28 +1,43 @@ | ||||
| TARGET = lfs.a | ||||
| ifdef BUILDDIR | ||||
| # make sure BUILDDIR ends with a slash | ||||
| override BUILDDIR := $(BUILDDIR)/ | ||||
| # bit of a hack, but we want to make sure BUILDDIR directory structure | ||||
| # is correct before any commands | ||||
| $(if $(findstring n,$(MAKEFLAGS)),, $(shell mkdir -p \ | ||||
| 	$(BUILDDIR) \ | ||||
| 	$(BUILDDIR)bd \ | ||||
| 	$(BUILDDIR)tests)) | ||||
| endif | ||||
|  | ||||
| # overridable target/src/tools/flags/etc | ||||
| ifneq ($(wildcard test.c main.c),) | ||||
| override TARGET = lfs | ||||
| TARGET ?= $(BUILDDIR)lfs | ||||
| else | ||||
| TARGET ?= $(BUILDDIR)lfs.a | ||||
| endif | ||||
|  | ||||
| CC ?= gcc | ||||
| AR ?= ar | ||||
| SIZE ?= size | ||||
| CTAGS ?= ctags | ||||
| NM ?= nm | ||||
| GCOV ?= gcov | ||||
| LCOV ?= lcov | ||||
|  | ||||
| SRC += $(wildcard *.c bd/*.c) | ||||
| OBJ := $(SRC:.c=.o) | ||||
| DEP := $(SRC:.c=.d) | ||||
| ASM := $(SRC:.c=.s) | ||||
| SRC ?= $(wildcard *.c bd/*.c) | ||||
| OBJ := $(SRC:%.c=%.o) | ||||
| DEP := $(SRC:%.c=%.d) | ||||
| ASM := $(SRC:%.c=%.s) | ||||
| ifdef BUILDDIR | ||||
| override OBJ := $(addprefix $(BUILDDIR),$(OBJ)) | ||||
| override DEP := $(addprefix $(BUILDDIR),$(DEP)) | ||||
| override ASM := $(addprefix $(BUILDDIR),$(ASM)) | ||||
| endif | ||||
|  | ||||
| ifdef DEBUG | ||||
| override CFLAGS += -O0 -g3 | ||||
| else | ||||
| override CFLAGS += -Os | ||||
| endif | ||||
| ifdef WORD | ||||
| override CFLAGS += -m$(WORD) | ||||
| endif | ||||
| ifdef TRACE | ||||
| override CFLAGS += -DLFS_YES_TRACE | ||||
| endif | ||||
| @@ -31,13 +46,23 @@ override CFLAGS += -std=c99 -Wall -pedantic | ||||
| override CFLAGS += -Wextra -Wshadow -Wjump-misses-init -Wundef | ||||
|  | ||||
| ifdef VERBOSE | ||||
| override SCRIPTFLAGS += -v | ||||
| override TESTFLAGS += -v | ||||
| override CODEFLAGS += -v | ||||
| override COVERAGEFLAGS += -v | ||||
| endif | ||||
| ifdef EXEC | ||||
| override TESTFLAGS += $(patsubst %,--exec=%,$(EXEC)) | ||||
| override TESTFLAGS += --exec="$(EXEC)" | ||||
| endif | ||||
| ifdef BUILDDIR | ||||
| override TESTFLAGS += --build-dir="$(BUILDDIR:/=)" | ||||
| override CODEFLAGS += --build-dir="$(BUILDDIR:/=)" | ||||
| endif | ||||
| ifneq ($(NM),nm) | ||||
| override CODEFLAGS += --nm-tool="$(NM)" | ||||
| endif | ||||
|  | ||||
|  | ||||
| # commands | ||||
| .PHONY: all build | ||||
| all build: $(TARGET) | ||||
|  | ||||
| @@ -48,44 +73,46 @@ asm: $(ASM) | ||||
| size: $(OBJ) | ||||
| 	$(SIZE) -t $^ | ||||
|  | ||||
| .PHONY: tags | ||||
| tags: | ||||
| 	$(CTAGS) --totals --c-types=+p $(shell find -name '*.h') $(SRC) | ||||
|  | ||||
| .PHONY: code | ||||
| code: | ||||
| 	./scripts/code.py $(SCRIPTFLAGS) | ||||
| code: $(OBJ) | ||||
| 	./scripts/code.py $^ $(CODEFLAGS) | ||||
|  | ||||
| .PHONY: coverage | ||||
| coverage: | ||||
| 	./scripts/coverage.py $(SCRIPTFLAGS) | ||||
| 	./scripts/coverage.py $(BUILDDIR)tests/*.toml.info $(COVERAGEFLAGS) | ||||
|  | ||||
| .PHONY: test | ||||
| test: | ||||
| 	./scripts/test.py $(TESTFLAGS) $(SCRIPTFLAGS) | ||||
| 	./scripts/test.py $(TESTFLAGS) | ||||
| .SECONDEXPANSION: | ||||
| test%: tests/test$$(firstword $$(subst \#, ,%)).toml | ||||
| 	./scripts/test.py $@ $(TESTFLAGS) $(SCRIPTFLAGS) | ||||
| 	./scripts/test.py $@ $(TESTFLAGS) | ||||
|  | ||||
| # rules | ||||
| -include $(DEP) | ||||
| .SUFFIXES: | ||||
|  | ||||
| lfs: $(OBJ) | ||||
| $(BUILDDIR)lfs: $(OBJ) | ||||
| 	$(CC) $(CFLAGS) $^ $(LFLAGS) -o $@ | ||||
|  | ||||
| %.a: $(OBJ) | ||||
| $(BUILDDIR)%.a: $(OBJ) | ||||
| 	$(AR) rcs $@ $^ | ||||
|  | ||||
| %.o: %.c | ||||
| $(BUILDDIR)%.o: %.c | ||||
| 	$(CC) -c -MMD $(CFLAGS) $< -o $@ | ||||
|  | ||||
| %.s: %.c | ||||
| $(BUILDDIR)%.s: %.c | ||||
| 	$(CC) -S $(CFLAGS) $< -o $@ | ||||
|  | ||||
| %.gcda.gcov: %.gcda | ||||
| 	( cd $(dir $@) ; $(GCOV) -ri $(notdir $<) ) | ||||
|  | ||||
| # clean everything | ||||
| .PHONY: clean | ||||
| clean: | ||||
| 	rm -f $(TARGET) | ||||
| 	rm -f $(OBJ) | ||||
| 	rm -f $(DEP) | ||||
| 	rm -f $(ASM) | ||||
| 	rm -f tests/*.toml.* | ||||
| 	rm -f sizes/* | ||||
| 	rm -f results/* | ||||
| 	rm -f $(BUILDDIR)tests/*.toml.* | ||||
|   | ||||
		Reference in New Issue
	
	Block a user