From patchwork Wed Dec 10 21:28:26 2008 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Frysinger X-Patchwork-Id: 13331 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A80A3DDF7B for ; Thu, 11 Dec 2008 08:30:51 +1100 (EST) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.68 #1 (Red Hat Linux)) id 1LAWbj-0001RC-2y; Wed, 10 Dec 2008 21:28:35 +0000 Received: from smtp.gentoo.org ([140.211.166.183]) by bombadil.infradead.org with esmtps (Exim 4.68 #1 (Red Hat Linux)) id 1LAWbf-0001Pk-Uo for linux-mtd@lists.infradead.org; Wed, 10 Dec 2008 21:28:32 +0000 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with ESMTP id 9BFCE65565 for ; Wed, 10 Dec 2008 21:28:27 +0000 (UTC) From: Mike Frysinger To: linux-mtd@lists.infradead.org Subject: [PATCH] unify all common build system parts Date: Wed, 10 Dec 2008 16:28:26 -0500 Message-Id: <1228944506-5792-1-git-send-email-vapier@gentoo.org> X-Mailer: git-send-email 1.6.0.4 X-Spam-Score: 0.0 (/) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.9 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Rather than duplicating the same thing over and over in every Makefile, move it all to common.mk. Other things fixed here: - doing subdirs in parallel - fix src!=build compiling in subdirs Signed-off-by: Mike Frysinger --- Makefile | 77 +++++++++++----------------------------- common.mk | 58 ++++++++++++++++++++++++++++++ mkfs.ubifs/Makefile | 20 +++++----- ubi-utils/Makefile | 77 ++++++++++++++-------------------------- ubi-utils/new-utils/Makefile | 79 +++++++++++++++-------------------------- 5 files changed, 145 insertions(+), 166 deletions(-) create mode 100644 common.mk diff --git a/Makefile b/Makefile index 8319599..ac623e3 100644 --- a/Makefile +++ b/Makefile @@ -1,30 +1,15 @@ # -*- sh -*- -PREFIX=/usr -EXEC_PREFIX=$(PREFIX) -SBINDIR=$(EXEC_PREFIX)/sbin -MANDIR=$(PREFIX)/share/man -INCLUDEDIR=$(PREFIX)/include - -#CROSS=arm-linux- -CC := $(CROSS)gcc -CFLAGS ?= -O2 -g -CFLAGS += -Wall CPPFLAGS += -I./include $(ZLIBCPPFLAGS) $(LZOCPPFLAGS) -ifeq ($(origin CROSS),undefined) - BUILDDIR := . -else -# Remove the trailing slash to make the directory name - BUILDDIR := $(CROSS:-=) -endif - ifeq ($(WITHOUT_XATTR), 1) CPPFLAGS += -DWITHOUT_XATTR endif -RAWTARGETS = ftl_format flash_erase flash_eraseall nanddump doc_loadbios \ +SUBDIRS = mkfs.ubifs ubi-utils + +TARGETS = ftl_format flash_erase flash_eraseall nanddump doc_loadbios \ ftl_check mkfs.jffs2 flash_lock flash_unlock flash_info \ flash_otp_info flash_otp_dump mtd_debug flashcp nandwrite nandtest \ jffs2dump \ @@ -33,68 +18,48 @@ RAWTARGETS = ftl_format flash_erase flash_eraseall nanddump doc_loadbios \ serve_image recv_image \ sumtool #jffs2reader -TARGETS = $(foreach target,$(RAWTARGETS),$(BUILDDIR)/$(target)) - SYMLINKS = -%: %.o - $(CC) $(CFLAGS) $(LDFLAGS) -g -o $@ $^ - -$(BUILDDIR)/%.o: %.c - mkdir -p $(BUILDDIR) - $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< -g -Wp,-MD,$(BUILDDIR)/.$( cscope.files @cscope -bR @rm cscope.files -install: ${TARGETS} +install:: ${TARGETS} mkdir -p ${DESTDIR}/${SBINDIR} install -m 0755 ${TARGETS} ${DESTDIR}/${SBINDIR}/ diff --git a/ubi-utils/Makefile b/ubi-utils/Makefile index 63058e1..3be813a 100644 --- a/ubi-utils/Makefile +++ b/ubi-utils/Makefile @@ -3,77 +3,54 @@ # KERNELHDR := ../include -DESTDIR := /usr/local -SBINDIR=/usr/sbin -MANDIR=/usr/share/man -INCLUDEDIR=/usr/include -CC := $(CROSS)gcc CFLAGS ?= -O2 -g -Werror -CFLAGS += -Wall -Wwrite-strings -W CPPFLAGS += -I./inc -I./src -I$(KERNELHDR) \ -std=gnu99 -DPACKAGE_VERSION=\"1.0\" PERLPROGS = mkpfi ubicrc32.pl -NTARGETS = ubiattach ubicrc32 ubidetach ubimkvol ubinfo ubinize \ - ubirmvol ubiupdatevol ubiformat +SUBDIRS = new-utils + TARGETS = pfiflash pddcustomize ubimirror bin2nand nand2bin ubigen \ - mkbootenv unubi pfi2bin $(NTARGETS) + mkbootenv unubi pfi2bin vpath %.c ./src -%: %.o - $(CC) $(LDFLAGS) -g -o $@ $^ - -%.o: %.c - $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< -g -Wp,-MD,.$(shell basename $<).dep - -all: $(TARGETS) - -IGNORE=${wildcard .*.c.dep} --include ${IGNORE} - -$(NTARGETS): - $(MAKE) -C new-utils $@ - mv new-utils/$@ $@ - -clean: - rm -rf *.o $(TARGETS) .*.c.dep - $(MAKE) -C new-utils clean +include ../common.mk -pddcustomize: pddcustomize.o error.o libubimirror.o bootenv.o hashmap.o \ - libubi.o crc32.o - $(CC) $(LDFLAGS) -o $@ $^ +$(BUILDDIR)/pddcustomize: $(addprefix $(BUILDDIR)/,\ + pddcustomize.o error.o libubimirror.o bootenv.o hashmap.o \ + libubi.o crc32.o) -pfiflash: pfiflash.o libpfiflash.o list.o reader.o error.o libubimirror.o \ - bootenv.o hashmap.o pfi.o libubi.o crc32.o - $(CC) $(LDFLAGS) -o $@ $^ +$(BUILDDIR)/pfiflash: $(addprefix $(BUILDDIR)/,\ + pfiflash.o libpfiflash.o list.o reader.o error.o libubimirror.o \ + bootenv.o hashmap.o pfi.o libubi.o crc32.o) -ubimirror: ubimirror.o error.o libubimirror.o bootenv.o hashmap.o \ - libubi.o crc32.o - $(CC) $(LDFLAGS) -o $@ $^ +$(BUILDDIR)/ubimirror: $(addprefix $(BUILDDIR)/,\ + ubimirror.o error.o libubimirror.o bootenv.o hashmap.o \ + libubi.o crc32.o) -nand2bin: nand2bin.o nandecc.o nandcorr.o - $(CC) $(LDFLAGS) -o $@ $^ +$(BUILDDIR)/nand2bin: $(addprefix $(BUILDDIR)/,\ + nand2bin.o nandecc.o nandcorr.o) -bin2nand: bin2nand.o error.o nandecc.o - $(CC) $(LDFLAGS) -o $@ $^ +$(BUILDDIR)/bin2nand: $(addprefix $(BUILDDIR)/,\ + bin2nand.o error.o nandecc.o) -ubigen: ubigen.o libubigen.o crc32.o - $(CC) $(LDFLAGS) -o $@ $^ +$(BUILDDIR)/ubigen: $(addprefix $(BUILDDIR)/,\ + ubigen.o libubigen.o crc32.o) -mkbootenv: mkbootenv.o bootenv.o hashmap.o error.o crc32.o - $(CC) $(LDFLAGS) -o $@ $^ +$(BUILDDIR)/mkbootenv: $(addprefix $(BUILDDIR)/,\ + mkbootenv.o bootenv.o hashmap.o error.o crc32.o) -unubi: unubi.o crc32.o unubi_analyze.o eb_chain.o - $(CC) $(LDFLAGS) -o $@ $^ +$(BUILDDIR)/unubi: $(addprefix $(BUILDDIR)/,\ + unubi.o crc32.o unubi_analyze.o eb_chain.o) -pfi2bin: pfi2bin.o peb.o error.o list.o crc32.o libubigen.o bootenv.o \ - hashmap.o reader.o pfi.o - $(CC) $(LDFLAGS) -o $@ $^ +$(BUILDDIR)/pfi2bin: $(addprefix $(BUILDDIR)/,\ + pfi2bin.o peb.o error.o list.o crc32.o libubigen.o bootenv.o \ + hashmap.o reader.o pfi.o) -install: ${TARGETS} +install:: mkdir -p ${DESTDIR}/${SBINDIR} install -m 0755 ${TARGETS} ${DESTDIR}/${SBINDIR}/ (cd perl && install ${PERLPROGS} ${DESTDIR}/${SBINDIR}/) diff --git a/ubi-utils/new-utils/Makefile b/ubi-utils/new-utils/Makefile index 9ba0d95..6ae60b3 100644 --- a/ubi-utils/new-utils/Makefile +++ b/ubi-utils/new-utils/Makefile @@ -3,76 +3,55 @@ # KERNELHDR := ../../include -DESTDIR := /usr/local -SBINDIR=/usr/sbin -MANDIR=/usr/man -INCLUDEDIR=/usr/include - -CC := $(CROSS)gcc -AR := $(CROSS)ar -RANLIB := $(CROSS)ranlib -CFLAGS ?= -O2 -CFLAGS += -Werror -Wall + +#CFLAGS += -Werror CPPFLAGS += -Iinclude -Isrc -I$(KERNELHDR) -LDFLAGS += -L. LIBS = libubi libmtd libubigen libiniparser libscan -UTILS = ubiupdatevol ubimkvol ubirmvol ubicrc32 ubinfo ubiattach \ - ubidetach ubinize ubiformat +TARGETS = ubiupdatevol ubimkvol ubirmvol ubicrc32 ubinfo ubiattach \ + ubidetach ubinize ubiformat vpath %.c src -all: $(UTILS) - -# The below cancels existing implicite rule to make programs from .c files, -# in order to force make using our rule defined below -%: %.c - -# The below is the rule to get an .o file from a .c file -%.o: %.c - $(CC) $(CFLAGS) $(CPPFLAGS) $< -c -o $@ +include ../../common.mk # And the below is the rule to get final executable from its .o and common.o -%: libubi.a %.o common.o - $(CC) $(CFLAGS) $(LDFLAGS) $(filter %.o, $^) -lubi -o $@ +$(TARGETS): $(addprefix $(BUILDDIR)/,\ + libubi.a common.o) +# $(CC) $(CFLAGS) $(filter %.o, $^) -L. -lubi -o $@ -ubicrc32: ubicrc32.o crc32.o - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ +$(BUILDDIR)/ubicrc32: $(addprefix $(BUILDDIR)/,\ + ubicrc32.o crc32.o) +# $(CC) $(CFLAGS) -o $@ $^ -ubinize: ubinize.o common.o crc32.o libiniparser.a libubigen.a - $(CC) $(CFLAGS) $(LDFLAGS) $(filter %.o, $^) -liniparser -lubigen -o $@ +$(BUILDDIR)/ubinize: $(addprefix $(BUILDDIR)/,\ + ubinize.o common.o crc32.o libiniparser.a libubigen.a) +# $(CC) $(CFLAGS) $(filter %.o, $^) -L. -liniparser -lubigen -o $@ -ubiformat: ubiformat.o common.o crc32.o libmtd.a libscan.a libubi.a libubigen.a - $(CC) $(CFLAGS) $(LDFLAGS) $(filter %.o, $^) -lmtd -lscan -lubi -lubigen -o $@ +$(BUILDDIR)/ubiformat: $(addprefix $(BUILDDIR)/,\ + ubiformat.o common.o crc32.o libmtd.a libscan.a libubi.a libubigen.a) +# $(CC) $(CFLAGS) $(filter %.o, $^) -L. -lmtd -lscan -lubi -lubigen -o $@ -libubi.a: libubi.o - $(AR) crv $@ $^ - $(RANLIB) $@ +$(BUILDDIR)/libubi.a: $(BUILDDIR)/libubi.o -libmtd.a: libmtd.o - $(AR) crv $@ $^ - $(RANLIB) $@ +$(BUILDDIR)/libmtd.a: $(BUILDDIR)/libmtd.o -libubigen.a: libubigen.o - $(AR) crv $@ $^ - $(RANLIB) $@ +$(BUILDDIR)/libubigen.a: $(BUILDDIR)/libubigen.o -libiniparser.a: libiniparser.o dictionary.o - $(AR) crv $@ $^ - $(RANLIB) $@ +$(BUILDDIR)/libiniparser.a: $(addprefix $(BUILDDIR)/,\ + libiniparser.o dictionary.o) -libscan.a: libscan.o crc32.o - $(AR) crv $@ $^ - $(RANLIB) $@ +$(BUILDDIR)/libscan.a: $(addprefix $(BUILDDIR)/,\ + libscan.o crc32.o) -clean: - rm -rf *.o $(addsuffix .a, $(LIBS)) $(UTILS) .*.c.dep +clean:: + rm -f $(addsuffix .a, $(LIBS)) -install: ${UTILS} +install:: mkdir -p ${DESTDIR}/${SBINDIR} - install -m 0755 ${UTILS} ${DESTDIR}/${SBINDIR}/ + install -m 0755 ${TARGETS} ${DESTDIR}/${SBINDIR}/ uninstall: - for file in ${UTILS}; do \ + for file in ${TARGETS}; do \ $(RM) ${DESTDIR}/${SBINDIR}/$$file; \ done