Skip to contentSkip to conversation

Second step towards Kbuild: Descend down like Kbuild

PATCH Superseded Masahiro Yamada 1 participant 8 messages Sep 8, 2013 – Sep 27, 2013

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover Second step towards Kbuild: Descend down like Kbuild

I have been just wondering why the U-Boot top Makefile is so dirty.

It is sprinkled with SoC-specific code as follows:

    ifneq ($(CONFIG_OMAP_COMMON),)
    LIBS-y += $(CPUDIR)/omap-common/libomap-common.o
    endif
    
    ifneq (,$(filter $(SOC), mx25 mx27 mx5 mx6 mx31 mx35 mxs vf610))
    LIBS-y += arch/$(ARCH)/imx-common/libimx-common.o
    endif
    
    ifeq ($(SOC),s5pc1xx)
    LIBS-y += $(CPUDIR)/s5p-common/libs5p-common.o
    endif
    ifeq ($(SOC),exynos)
    LIBS-y += $(CPUDIR)/s5p-common/libs5p-common.o
    endif
    ifneq ($(CONFIG_TEGRA),)
    LIBS-y += arch/$(ARCH)/cpu/$(SOC)-common/lib$(SOC)-common.o
    LIBS-y += arch/$(ARCH)/cpu/tegra-common/libcputegra-common.o
    LIBS-y += $(CPUDIR)/tegra-common/libtegra-common.o
    endif

And it describes drivers not right under the top directory, which should be essentially cared by drivers/Makefile.

    LIBS-y += drivers/bios_emulator/libatibiosemu.o
    LIBS-y += drivers/block/libblock.o
    LIBS-$(CONFIG_BOOTCOUNT_LIMIT) += drivers/bootcount/libbootcount.o
    LIBS-y += drivers/crypto/libcrypto.o
    LIBS-y += drivers/dma/libdma.o
         ...

This series adds the directory descending feature like Kbuild.

0001 tweaks scripts/Makefile.build to support 'obj-y += foo/' syntax. When the build system find 'foo/' (trailed by a slash),
it visits foo directory.

0002-0006 demonstarate how we can refactor makefiles with this syntax.

0002: Move some drivers LIBS from top Makefile to drivers/Makefile 0003: Move some fs LIBS from top Makefile to fs/Makefile 0004: Move Tegra specific lines from top Makefile under arch/arm 0005: Move OMAP specific lines from top Makefile under arch/arm 0006: Move Samsung SoC specific lines from top Makefile under arch/arm

Note:
This series can be applies on v2013.10-rc2 +
'First step towards Kbuild: Use Kbuild-style makefiles' (19 patch files).

Please apply 'First step towards Kbuild: Use Kbuild-style makefiles' first.

I believe no boards are broken by this refactoring, but
it is humans who can make a mistake.
So, it is very important to do build check before patches are applied.

I tested for ARM and sandbox:

    $ CROSS_COMPILE_ARM=arm-linux-gnueabi- ./MAKEALL -a arm -a sandbox

and I got:

    --------------------- SUMMARY ----------------------------
    Boards compiled: 336
    ----------------------------------------------------------

But I can not test other architectures.
I will be grateful for any custodians' help.

Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>

Masahiro Yamada (6):
Makefile: support descending down to subdirectories
drivers: move some drivers to drivers/Makefile
fs: move some file system to fs/Makefile
ARM: tegra: delete Tegra specific code from toplevel Makefile
ARM: omap: delete OMAP specific code from toplevel Makefile
ARM: s5pc, exynos: delete Samsung ARM SoC specific code from toplevel
Makefile

 Makefile                      | 42 +++---------------------------------------
 arch/arm/cpu/Makefile         |  2 ++
 arch/arm/cpu/arm720t/Makefile |  2 ++
 arch/arm/cpu/armv7/Makefile   |  9 +++++++++
 drivers/Makefile              | 13 +++++++++++++
 fs/Makefile                   | 11 +++++++++++
 scripts/Makefile.build        | 15 +++++++++++++++
 spl/Makefile                  | 14 +-------------
 8 files changed, 56 insertions(+), 52 deletions(-)
 create mode 100644 arch/arm/cpu/Makefile
 create mode 100644 drivers/Makefile
Signature · 1 line
1.8.1.2
#1 lore raw

PATCH 1/6 Makefile: support descending down to subdirectories

This patch tweaks scripts/Makefile.build to allow the build system to descend into subdirectories like Kbuild.

To use this feature, use "obj-y += foo/" syntax.

Example:

    obj-$(CONFIG_FOO) += foo/
---
 scripts/Makefile.build | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
scripts/Makefile.build +15 -0
index f969ec5..2ef7341 100644
@@ -19,6 +19,11 @@ obj-y := $(sort $(obj-y))
 extra-y := $(sort $(extra-y))
 lib-y := $(sort $(lib-y))
 
+subdir-y 	:= $(patsubst %/,%,$(filter %/, $(obj-y)))
+obj-y		:= $(patsubst %/, %/built-in.o, $(obj-y))
+subdir-obj-y	:= $(filter %/built-in.o, $(obj-y))
+subdir-obj-y	:= $(addprefix $(obj),$(subdir-obj-y))
+
 SRCS	+= $(COBJS:.o=.c) $(SOBJS:.o=.S) \
  $(wildcard $(obj-y:.o=.c) $(obj-y:.o=.S) $(lib-y:.o=.c) $(lib-y:.o=.S) $(extra-y:.o=.c) $(extra-y:.o=.S))
 OBJS	:= $(addprefix $(obj),$(COBJS) $(SOBJS) $(obj-y))
@@ -37,6 +42,14 @@ $(LIBGCC): $(obj).depend $(LGOBJS)
 	$(call cmd_link_o_target, $(LGOBJS))
 endif
 
+ifneq ($(subdir-obj-y),)
+# Descending
+$(subdir-obj-y): $(subdir-y)
+
+$(subdir-y): FORCE
+	$(MAKE) -C $@ -f $(TOPDIR)/scripts/Makefile.build
+endif
+
 #########################################################################
 
 # defines $(obj).depend target
@@ -46,3 +59,5 @@ include $(TOPDIR)/rules.mk
 sinclude $(obj).depend
 
 #########################################################################
+
+.PHONY: FORCE
Signature · 1 line
1.8.1.2
#2 lore raw

PATCH 2/6 drivers: move some drivers to drivers/Makefile

In reply to Masahiro Yamada

This commit moves some drivers subdirectory entry from the toplevel Makefile to drivers/Makefile using Kbuild descending feature.

---
 Makefile         | 14 +-------------
 drivers/Makefile | 13 +++++++++++++
 2 files changed, 14 insertions(+), 13 deletions(-)
 create mode 100644 drivers/Makefile
Makefile +1 -13
index 338bf31..05bbca2 100644
@@ -261,17 +261,11 @@ LIBS-y += fs/libfs.o \
 	fs/zfs/libzfs.o
 LIBS-y += net/libnet.o
 LIBS-y += disk/libdisk.o
-LIBS-y += drivers/bios_emulator/libatibiosemu.o
-LIBS-y += drivers/block/libblock.o
-LIBS-$(CONFIG_BOOTCOUNT_LIMIT) += drivers/bootcount/libbootcount.o
-LIBS-y += drivers/crypto/libcrypto.o
+LIBS-y += drivers/libdrivers.o
 LIBS-y += drivers/dma/libdma.o
-LIBS-y += drivers/fpga/libfpga.o
 LIBS-y += drivers/gpio/libgpio.o
-LIBS-y += drivers/hwmon/libhwmon.o
 LIBS-y += drivers/i2c/libi2c.o
 LIBS-y += drivers/input/libinput.o
-LIBS-y += drivers/misc/libmisc.o
 LIBS-y += drivers/mmc/libmmc.o
 LIBS-y += drivers/mtd/libmtd.o
 LIBS-y += drivers/mtd/nand/libnand.o
@@ -287,7 +281,6 @@ LIBS-y += drivers/power/libpower.o \
 	drivers/power/pmic/libpmic.o \
 	drivers/power/battery/libbattery.o
 LIBS-y += drivers/spi/libspi.o
-LIBS-y += drivers/dfu/libdfu.o
 ifeq ($(CPU),mpc83xx)
 LIBS-y += drivers/qe/libqe.o
 LIBS-y += arch/powerpc/cpu/mpc8xxx/ddr/libddr.o
@@ -305,9 +298,6 @@ LIBS-y += arch/powerpc/cpu/mpc8xxx/lib8xxx.o
 endif
 LIBS-y += drivers/rtc/librtc.o
 LIBS-y += drivers/serial/libserial.o
-LIBS-y += drivers/sound/libsound.o
-LIBS-y += drivers/tpm/libtpm.o
-LIBS-y += drivers/twserial/libtws.o
 LIBS-y += drivers/usb/eth/libusb_eth.o
 LIBS-y += drivers/usb/gadget/libusb_gadget.o
 LIBS-y += drivers/usb/host/libusb_host.o
@@ -315,8 +305,6 @@ LIBS-y += drivers/usb/musb/libusb_musb.o
 LIBS-y += drivers/usb/musb-new/libusb_musb-new.o
 LIBS-y += drivers/usb/phy/libusb_phy.o
 LIBS-y += drivers/usb/ulpi/libusb_ulpi.o
-LIBS-y += drivers/video/libvideo.o
-LIBS-y += drivers/watchdog/libwatchdog.o
 LIBS-y += common/libcommon.o
 LIBS-y += lib/libfdt/libfdt.o
 LIBS-y += api/libapi.o
drivers/Makefile new file +13 -0
new file mode 100644
index 0000000..19a1c49
@@ -0,0 +1,13 @@
+obj-y += bios_emulator/
+obj-y += block/
+obj-$(CONFIG_BOOTCOUNT_LIMIT) += bootcount/
+obj-y += crypto/
+obj-y += fpga/
+obj-y += hwmon/
+obj-y += misc/
+obj-y += dfu/
+obj-y += sound/
+obj-y += tpm/
+obj-y += twserial/
+obj-y += video/
+obj-y += watchdog/
Signature · 1 line
1.8.1.2
#3 lore raw

PATCH 3/6 fs: move some file system to fs/Makefile

In reply to Masahiro Yamada

This commit moves some subdirectories of fs
from the toplevel Makefile to fs/Makefile
using Kbuild descending feature.

---
 Makefile    | 12 +-----------
 fs/Makefile | 11 +++++++++++
 2 files changed, 12 insertions(+), 11 deletions(-)
Makefile +1 -11
index 05bbca2..53a8a88 100644
@@ -248,17 +248,7 @@ endif
 LIBS-$(CONFIG_OF_EMBED) += dts/libdts.o
 LIBS-y += arch/$(ARCH)/lib/lib$(ARCH).o
 LIBS-y += fs/libfs.o \
-	fs/cbfs/libcbfs.o \
-	fs/cramfs/libcramfs.o \
-	fs/ext4/libext4fs.o \
-	fs/fat/libfat.o \
-	fs/fdos/libfdos.o \
-	fs/jffs2/libjffs2.o \
-	fs/reiserfs/libreiserfs.o \
-	fs/sandbox/libsandboxfs.o \
-	fs/ubifs/libubifs.o \
-	fs/yaffs2/libyaffs2.o \
-	fs/zfs/libzfs.o
+	fs/fat/libfat.o
 LIBS-y += net/libnet.o
 LIBS-y += disk/libdisk.o
 LIBS-y += drivers/libdrivers.o
fs/Makefile +11 -0
index ea2eb09..bdcd746 100644
@@ -7,3 +7,14 @@
 #
 
 obj-y				+= fs.o
+
+obj-y += cbfs/
+obj-y += cramfs/
+obj-y += ext4/
+obj-y += fdos/
+obj-y += jffs2/
+obj-y += reiserfs/
+obj-y += sandbox/
+obj-y += ubifs/
+obj-y += yaffs2/
+obj-y += zfs/
Signature · 1 line
1.8.1.2
#4 lore raw

PATCH 4/6 ARM: tegra: delete Tegra specific code from toplevel Makefile

In reply to Masahiro Yamada

This patch moves Tegra specific directory entries from the toplevel Makefile and spl/Makefile
to arch/arm/cpu/*/Makefile using Kbuild descending feature.

---
 Makefile                      | 6 +-----
 arch/arm/cpu/Makefile         | 2 ++
 arch/arm/cpu/arm720t/Makefile | 2 ++
 arch/arm/cpu/armv7/Makefile   | 2 ++
 spl/Makefile                  | 6 +-----
 5 files changed, 8 insertions(+), 10 deletions(-)
 create mode 100644 arch/arm/cpu/Makefile
Makefile +1 -5
index 53a8a88..a32fd7f 100644
@@ -315,11 +315,7 @@ endif
 ifeq ($(SOC),exynos)
 LIBS-y += $(CPUDIR)/s5p-common/libs5p-common.o
 endif
-ifneq ($(CONFIG_TEGRA),)
-LIBS-y += arch/$(ARCH)/cpu/$(SOC)-common/lib$(SOC)-common.o
-LIBS-y += arch/$(ARCH)/cpu/tegra-common/libcputegra-common.o
-LIBS-y += $(CPUDIR)/tegra-common/libtegra-common.o
-endif
+LIBS-$(CONFIG_ARM) += arch/arm/cpu/libcpu.o
 
 LIBS := $(addprefix $(obj),$(sort $(LIBS-y)))
 .PHONY : $(LIBS)
arch/arm/cpu/Makefile new file +2 -0
new file mode 100644
index 0000000..fd0da53
@@ -0,0 +1,2 @@
+obj-$(CONFIG_TEGRA) += $(SOC)-common/
+obj-$(CONFIG_TEGRA) += tegra-common/
arch/arm/cpu/arm720t/Makefile +2 -0
index 243a123..6badb3b 100644
@@ -7,3 +7,5 @@
 
 extra-y	= start.o
 obj-y	= interrupts.o cpu.o
+
+obj-$(CONFIG_TEGRA) += tegra-common/
arch/arm/cpu/armv7/Makefile +2 -0
index 75fac4b..7b260ac 100644
@@ -15,3 +15,5 @@ obj-y	+= syslib.o
 ifneq ($(CONFIG_AM43XX)$(CONFIG_AM33XX)$(CONFIG_OMAP44XX)$(CONFIG_OMAP54XX)$(CONFIG_TEGRA)$(CONFIG_MX6)$(CONFIG_TI81XX),)
 obj-y	+= lowlevel_init.o
 endif
+
+obj-$(CONFIG_TEGRA) += tegra-common/
spl/Makefile +1 -5
index 5d31a52..9901619 100644
@@ -107,11 +107,7 @@ ifneq (,$(CONFIG_MX23)$(filter $(SOC), mx25 mx27 mx5 mx6 mx31 mx35))
 LIBS-y += arch/$(ARCH)/imx-common/libimx-common.o
 endif
 
-ifneq ($(CONFIG_TEGRA),)
-LIBS-y += arch/$(ARCH)/cpu/$(SOC)-common/lib$(SOC)-common.o
-LIBS-y += arch/$(ARCH)/cpu/tegra-common/libcputegra-common.o
-LIBS-y += $(CPUDIR)/tegra-common/libtegra-common.o
-endif
+LIBS-$(CONFIG_ARM) += arch/arm/cpu/libcpu.o
 
 ifneq ($(CONFIG_MX23)$(CONFIG_MX35),)
 LIBS-y += arch/$(ARCH)/imx-common/libimx-common.o
Signature · 1 line
1.8.1.2
#5 lore raw

PATCH 5/6 ARM: omap: delete OMAP specific code from toplevel Makefile

In reply to Masahiro Yamada

This patch moves OMAP specific directory entries
from the toplevel Makefile and spl/Makefile
to arch/arm/cpu/armv7/Makefile using Kbuild descending feature.

---
 Makefile                    | 4 ----
 arch/arm/cpu/armv7/Makefile | 3 +++
 spl/Makefile                | 4 ----
 3 files changed, 3 insertions(+), 8 deletions(-)
Makefile +0 -4
index a32fd7f..da6e657 100644
@@ -301,10 +301,6 @@ LIBS-y += api/libapi.o
 LIBS-y += post/libpost.o
 LIBS-y += test/libtest.o
 
-ifneq ($(CONFIG_OMAP_COMMON),)
-LIBS-y += $(CPUDIR)/omap-common/libomap-common.o
-endif
-
 ifneq (,$(filter $(SOC), mx25 mx27 mx5 mx6 mx31 mx35 mxs vf610))
 LIBS-y += arch/$(ARCH)/imx-common/libimx-common.o
 endif
arch/arm/cpu/armv7/Makefile +3 -0
index 7b260ac..7443b39 100644
@@ -13,7 +13,10 @@ obj-y	+= cpu.o
 obj-y	+= syslib.o
 
 ifneq ($(CONFIG_AM43XX)$(CONFIG_AM33XX)$(CONFIG_OMAP44XX)$(CONFIG_OMAP54XX)$(CONFIG_TEGRA)$(CONFIG_MX6)$(CONFIG_TI81XX),)
+ifneq ($(CONFIG_SKIP_LOWLEVEL_INIT),y)
 obj-y	+= lowlevel_init.o
 endif
+endif
 
+obj-$(CONFIG_OMAP_COMMON) += omap-common/
 obj-$(CONFIG_TEGRA) += tegra-common/
spl/Makefile +0 -4
index 9901619..ae40b60 100644
@@ -99,10 +99,6 @@ LIBS-$(CONFIG_SPL_USBETH_SUPPORT) += drivers/net/phy/libphy.o
 LIBS-$(CONFIG_SPL_MUSB_NEW_SUPPORT) += drivers/usb/musb-new/libusb_musb-new.o
 LIBS-$(CONFIG_SPL_USBETH_SUPPORT) += drivers/usb/gadget/libusb_gadget.o
 
-ifneq ($(CONFIG_OMAP_COMMON),)
-LIBS-y += $(CPUDIR)/omap-common/libomap-common.o
-endif
-
 ifneq (,$(CONFIG_MX23)$(filter $(SOC), mx25 mx27 mx5 mx6 mx31 mx35))
 LIBS-y += arch/$(ARCH)/imx-common/libimx-common.o
 endif
Signature · 1 line
1.8.1.2
#6 lore raw

PATCH 6/6 ARM: s5pc, exynos: delete Samsung ARM SoC specific code from toplevel Makefile

In reply to Masahiro Yamada

This patch moves S5PC, EXYNOS specific directory entries from the toplevel Makefile to arch/arm/cpu/armv7/Makefile using Kbuild descending feature.

---
 Makefile                    | 6 ------
 arch/arm/cpu/armv7/Makefile | 4 ++++
 spl/Makefile                | 4 ----
 3 files changed, 4 insertions(+), 10 deletions(-)
Makefile +0 -6
index da6e657..e43352f 100644
@@ -305,12 +305,6 @@ ifneq (,$(filter $(SOC), mx25 mx27 mx5 mx6 mx31 mx35 mxs vf610))
 LIBS-y += arch/$(ARCH)/imx-common/libimx-common.o
 endif
 
-ifeq ($(SOC),s5pc1xx)
-LIBS-y += $(CPUDIR)/s5p-common/libs5p-common.o
-endif
-ifeq ($(SOC),exynos)
-LIBS-y += $(CPUDIR)/s5p-common/libs5p-common.o
-endif
 LIBS-$(CONFIG_ARM) += arch/arm/cpu/libcpu.o
 
 LIBS := $(addprefix $(obj),$(sort $(LIBS-y)))
arch/arm/cpu/armv7/Makefile +4 -0
index 7443b39..8d5bde9 100644
@@ -20,3 +20,7 @@ endif
 
 obj-$(CONFIG_OMAP_COMMON) += omap-common/
 obj-$(CONFIG_TEGRA) += tegra-common/
+
+ifneq (,$(filter s5pc1xx exynos,$(SOC)))
+obj-y += s5p-common/
+endif
spl/Makefile +0 -4
index ae40b60..0e3b66b 100644
@@ -109,10 +109,6 @@ ifneq ($(CONFIG_MX23)$(CONFIG_MX35),)
 LIBS-y += arch/$(ARCH)/imx-common/libimx-common.o
 endif
 
-ifeq ($(SOC),exynos)
-LIBS-y += $(CPUDIR)/s5p-common/libs5p-common.o
-endif
-
 # Add GCC lib
 ifeq ("$(USE_PRIVATE_LIBGCC)", "yes")
 PLATFORM_LIBGCC = $(SPLTREE)/arch/$(ARCH)/lib/libgcc.o
Signature · 1 line
1.8.1.2