From 0e53931fee0178c4f4ac4e2e6b355b103b5e8c42 Mon Sep 17 00:00:00 2001 From: Sol Boucher Date: Thu, 5 Mar 2015 15:38:03 -0800 Subject: cbfstool: Clean up in preparation for adding new files This enables more warnings on the cbfstool codebase and fixes the issues that surface as a result. A memory leak that used to occur when compressing files with lzma is also found and fixed. Finally, there are several fixes for the Makefile: - Its autodependencies used to be broken because the target for the .dependencies file was misnamed; this meant that Make didn't know how to rebuild the file, and so would silently skip the step of updating it before including it. - The ability to build to a custom output directory by defining the obj variable had bitrotted. - The default value of the obj variable was causing implicit rules not to apply when specifying a file as a target without providing a custom value for obj. - Add a distclean target for removing the .dependencies file. BUG=chromium:461875 TEST=Build an image with cbfstool both before and after. BRANCH=None Change-Id: I951919d63443f2b053c2e67c1ac9872abc0a43ca Signed-off-by: Sol Boucher Original-Commit-Id: 49293443b4e565ca48d284e9a66f80c9c213975d Original-Change-Id: Ia7350c2c3306905984cfa711d5fc4631f0b43d5b Original-Signed-off-by: Sol Boucher Original-Reviewed-on: https://chromium-review.googlesource.com/257340 Original-Reviewed-by: Julius Werner Original-Reviewed-by: Stefan Reinauer Reviewed-on: http://review.coreboot.org/9937 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi --- util/cbfstool/Makefile | 55 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 22 deletions(-) (limited to 'util/cbfstool/Makefile') diff --git a/util/cbfstool/Makefile b/util/cbfstool/Makefile index 05a96ee90a..258fba3ec2 100644 --- a/util/cbfstool/Makefile +++ b/util/cbfstool/Makefile @@ -1,50 +1,61 @@ -obj ?= $(shell pwd) +obj ?= . HOSTCC ?= $(CC) -CFLAGS ?= -g -CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes -CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs -CFLAGS += -Wstrict-aliasing -Wshadow -Werror -CBFSTOOL_BINARY:=$(obj)/cbfstool +CFLAGS += -Og -g3 +CFLAGS += -std=c99 -Werror -Wall -Wextra +CFLAGS += -Wcast-qual -Wmissing-prototypes -Wredundant-decls -Wshadow +CFLAGS += -Wstrict-prototypes -Wwrite-strings +CPPFLAGS += -D_POSIX_C_SOURCE=200809L # strdup() from string.h +LINKFLAGS += -g3 -CBFSTOOL_COMMON:=cbfstool.o common.o cbfs_image.o compress.o fit.o +CBFSTOOL_BINARY:=$(obj)/cbfstool +CBFSTOOL_COMMON:=common.o cbfs_image.o compress.o fit.o CBFSTOOL_COMMON+=elfheaders.o cbfs-mkstage.o cbfs-mkpayload.o xdr.o +CBFSTOOL_COMMON+=linux_trampoline.o cbfs-payload-linux.o # LZMA CBFSTOOL_COMMON+=lzma/lzma.o CBFSTOOL_COMMON+=lzma/C/LzFind.o lzma/C/LzmaDec.o lzma/C/LzmaEnc.o -CBFSTOOL_COMMON+=linux_trampoline.o cbfs-payload-linux.o - CBFSTOOL_COMMON:=$(addprefix $(obj)/,$(CBFSTOOL_COMMON)) RMODTOOL_BINARY:=$(obj)/rmodtool -RMODTOOL_COMMON:=rmodtool.o rmodule.o common.o elfheaders.o xdr.o +RMODTOOL_COMMON:=rmodule.o common.o elfheaders.o xdr.o RMODTOOL_COMMON:=$(addprefix $(obj)/,$(RMODTOOL_COMMON)) -all: dep $(CBFSTOOL_BINARY) $(RMODTOOL_BINARY) +.PHONY: all +all: .dependencies $(CBFSTOOL_BINARY) $(RMODTOOL_BINARY) +$(obj)/%: $(obj)/%.o + mkdir -p $(dir $@) + $(HOSTCC) $(LINKFLAGS) -o $@ $^ $(LDLIBS) $(obj)/%.o: %.c - $(HOSTCC) $(CFLAGS) -c -o $@ $< + mkdir -p $(dir $@) + $(HOSTCC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< +.PHONY: clean clean: - rm -f $(CBFSTOOL_COMMON) $(CBFSTOOL_BINARY) - rm -f $(RMODTOOL_COMMON) $(RMODTOOL_BINARY) + $(RM) $(CBFSTOOL_COMMON) $(CBFSTOOL_BINARY).o $(CBFSTOOL_BINARY) + $(RM) $(RMODTOOL_COMMON) $(RMODTOOL_BINARY).o $(RMODTOOL_BINARY) +.PHONY: distclean +distclean: clean + $(RM) .dependencies tags: ctags *.[ch] -$(obj)/cbfstool:$(CBFSTOOL_COMMON) - $(HOSTCC) $(CFLAGS) -o $@ $^ +.dependencies: + @$(HOSTCC) $(CPPFLAGS) $(CFLAGS) -MM -MG *.c > $@ + @$(HOSTCC) $(CPPFLAGS) $(CFLAGS) -MM lzma/*.c >> $@ + @$(HOSTCC) $(CPPFLAGS) $(CFLAGS) -MM lzma/C/*.c >> $@ + @sed -i 's|.*:.*|$$(obj)/&|' $@ -$(obj)/rmodtool:$(RMODTOOL_COMMON) - $(HOSTCC) $(CFLAGS) -o $@ $^ +$(CBFSTOOL_BINARY): $(CBFSTOOL_COMMON) +$(RMODTOOL_BINARY): $(RMODTOOL_COMMON) -dep: - @$(HOSTCC) $(CFLAGS) -MM *.c > .dependencies - @$(HOSTCC) $(CFLAGS) -MM lzma/*.c >> .dependencies - @$(HOSTCC) $(CFLAGS) -MM lzma/C/*.c >> .dependencies +# Tolerate lzma sdk warnings +$(obj)/lzma/C/LzmaEnc.o: CFLAGS += -Wno-sign-compare -Wno-cast-qual -include .dependencies -- cgit v1.2.3