[Skiboot] [PATCH v3 7/7] external/common: Write an includeable rules.mk.

Cyril Bur cyril.bur at au1.ibm.com
Wed Aug 26 16:02:38 AEST 2015


It would be nice if tools like the gard tool or pflash don't have to worry
about how to build the arch specific code they want to include through the
new external/common code.

This patch adds an external/common/rules.mk which each tool can include and
with some minor tweaking of the existing makefiles it should get the arch
code building nicely.

The one caveat is that it requires a symlink in the directory to create
common/ dir for everything to behave.

---
I would be very grateful to a Makexpert if they could point me down the path
of doing this in a less dodgy fashion.

RFC: Fix compilation issue identified by JK due to old files in my
build directory

V1: Fixed breakage of make dist
Signed-off-by: Cyril Bur <cyril.bur at au1.ibm.com>
---
 external/{pflash => common}/get_arch.sh |  0
 external/common/rules.mk                | 36 +++++++++++++++++++++++++++++++++
 external/pflash/Makefile                | 26 ++++++++++--------------
 external/pflash/Makefile.dist           |  2 ++
 external/pflash/ast.h                   |  2 +-
 external/pflash/rules.mk                | 21 +------------------
 external/pflash/sfc-ctrl.h              |  9 ---------
 7 files changed, 51 insertions(+), 45 deletions(-)
 rename external/{pflash => common}/get_arch.sh (100%)
 create mode 100644 external/common/rules.mk
 delete mode 100644 external/pflash/sfc-ctrl.h

diff --git a/external/pflash/get_arch.sh b/external/common/get_arch.sh
similarity index 100%
rename from external/pflash/get_arch.sh
rename to external/common/get_arch.sh
diff --git a/external/common/rules.mk b/external/common/rules.mk
new file mode 100644
index 0000000..bc565e8
--- /dev/null
+++ b/external/common/rules.mk
@@ -0,0 +1,36 @@
+ARCH = $(shell $(GET_ARCH) "$(CROSS_COMPILE)")
+
+ifeq ($(ARCH),ARCH_ARM)
+arch = arm
+ARCH_OBJS = common/arch_flash_common.o common/arch_flash_arm.o common/ast-sf-ctrl.o
+else
+ifeq ($(ARCH),ARCH_POWERPC)
+arch = powerpc
+ARCH_OBJS = common/arch_flash_common.o common/arch_flash_powerpc.o
+else
+ifeq ($(ARCH),ARCH_X86)
+arch = x86
+ARCH_OBJS = common/arch_flash_common.o common/arch_flash_x86.o
+else
+$(error Unsupported architecture $(ARCH))
+endif
+endif
+endif
+
+.PHONY: arch_links
+arch_links:
+	ln -sf ../../hw/ast-bmc/ast-sf-ctrl.c common/ast-sf-ctrl.c
+	ln -sf arch_flash_$(arch)_io.h common/io.h
+
+.PHONY: arch_clean
+arch_clean:
+	rm -rf $(ARCH_OBJS)
+
+#If arch changes make won't realise it needs to rebuild...
+.PHONY: .FORCE
+common/arch_flash_common.o: common/arch_flash_common.c .FORCE
+	$(CROSS_COMPILE)gcc $(CFLAGS) -c $< -o $@
+
+common/arch_flash.o: $(ARCH_OBJS)
+	$(CROSS_COMPILE)ld -r $(ARCH_OBJS) -o $@
+
diff --git a/external/pflash/Makefile b/external/pflash/Makefile
index 53501e5..f0c3773 100644
--- a/external/pflash/Makefile
+++ b/external/pflash/Makefile
@@ -1,9 +1,11 @@
 include rules.mk
+GET_ARCH = ../../external/common/get_arch.sh
+include ../../external/common/rules.mk
 
 all: $(EXE)
 
 .PHONY: links
-links: libflash ccan common sfc-ctrl.c ast-sf-ctrl.c make_version.sh
+links: libflash ccan common make_version.sh
 
 libflash:
 	ln -sf ../../libflash .
@@ -11,20 +13,13 @@ libflash:
 ccan:
 	ln -sf ../../ccan .
 
-sfc-ctrl.c:
-	ln -sf ../../hw/sfc-ctrl.c .
-
-ast-sf-ctrl.c:
-	ln -sf ../../hw/ast-bmc/ast-sf-ctrl.c
+common:
+	ln -sf ../common .
 
 make_version.sh:
 	ln -sf ../../make_version.sh
 
-common:
-	ln -sf ../../external/common .
-	ln -sf ../../external/common/arch_flash_$(arch)_io.h io.h
-
-$(OBJS) : links
+$(OBJS): | links arch_links
 
 .PHONY: VERSION-always
 .version: VERSION-always
@@ -39,12 +34,13 @@ $(OBJS) : links
 dist: links .version
 	find -L ../pflash/ -iname '*.[ch]' -print0 | xargs -0 tar -rhf $(PFLASH_VERSION).tar
 	tar --transform 's/Makefile.dist/Makefile/' -rhf $(PFLASH_VERSION).tar \
-		../pflash/get_arch.sh ../pflash/Makefile.dist ../pflash/rules.mk \
-		../pflash/.version ../pflash/make_version.sh
+		../pflash/Makefile.dist ../pflash/rules.mk \
+		../pflash/.version ../pflash/make_version.sh \
+		../pflash/common/*
 
-clean:
+clean: arch_clean
 	rm -f $(OBJS) $(EXE) *.o *.d libflash/test/test_flash libflash/test/*.o
 distclean: clean
 	rm -f *.c~ *.h~ *.sh~ Makefile~ config.mk~ libflash/*.c~ libflash/*.h~
-	rm -f libflash ccan sfc-ctrl.c ast-sf-ctrl.c .version .version.tmp
+	rm -f libflash ccan .version .version.tmp
 	rm -f common io.h make_version.sh
diff --git a/external/pflash/Makefile.dist b/external/pflash/Makefile.dist
index 017fd90..46edcb1 100644
--- a/external/pflash/Makefile.dist
+++ b/external/pflash/Makefile.dist
@@ -1,4 +1,6 @@
 include rules.mk
+GET_ARCH = common/get_arch.sh
+include common/rules.mk
 
 all: $(EXE)
 
diff --git a/external/pflash/ast.h b/external/pflash/ast.h
index fe8f7ce..1910eb4 100644
--- a/external/pflash/ast.h
+++ b/external/pflash/ast.h
@@ -32,7 +32,7 @@
  * AHB Accessors
  */
 #ifndef __SKIBOOT__
-#include "io.h"
+#include "common/io.h"
 #else
 
 /*
diff --git a/external/pflash/rules.mk b/external/pflash/rules.mk
index f3af124..849c280 100644
--- a/external/pflash/rules.mk
+++ b/external/pflash/rules.mk
@@ -1,29 +1,10 @@
-ARCH=$(shell ./get_arch.sh "$(CROSS_COMPILE)")
-
-ifeq ($(ARCH),ARCH_ARM)
-arch = arm
-ARCH_OBJS = common/arch_flash_common.o common/arch_flash_arm.o ast-sf-ctrl.o
-else
-ifeq ($(ARCH),ARCH_POWERPC)
-arch = powerpc
-ARCH_OBJS = common/arch_flash_common.o common/arch_flash_powerpc.o
-else
-ifeq ($(ARCH),ARCH_X86)
-arch = x86
-ARCH_OBJS = common/arch_flash_common.o common/arch_flash_x86.o
-else
-$(error Unsupported architecture $(ARCH))
-endif
-endif
-endif
-
 .DEFAULT_GOAL := all
 
 CFLAGS  = -O2 -Wall -I.
 LDFLAGS	= -lrt
 OBJS    = pflash.o progress.o version.o
 OBJS	+= libflash/libflash.o libflash/libffs.o libflash/ecc.o libflash/blocklevel.o libflash/file.o
-OBJS	+= $(ARCH_OBJS)
+OBJS	+= common/arch_flash.o
 EXE     = pflash
 
 CC	= $(CROSS_COMPILE)gcc
diff --git a/external/pflash/sfc-ctrl.h b/external/pflash/sfc-ctrl.h
deleted file mode 100644
index 6c30759..0000000
--- a/external/pflash/sfc-ctrl.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#ifndef SFC_CTRL_H
-#define SFC_CTRL_H
-
-struct spi_flash_ctrl;
-
-extern int sfc_open(struct spi_flash_ctrl **ctrl);
-extern void sfc_close(struct spi_flash_ctrl *ctrl);
-
-#endif /* SFC_CTRL_H */
-- 
2.5.0



More information about the Skiboot mailing list