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

Cyril Bur cyril.bur at au1.ibm.com
Fri Jul 17 17:01:24 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.

Signed-off-by: Cyril Bur <cyril.bur at au1.ibm.com>
---
 external/{pflash => common}/get_arch.sh |  0
 external/common/rules.mk                | 29 +++++++++++++++++++++++++++++
 external/pflash/Makefile                | 15 ++++++---------
 external/pflash/Makefile.dist           |  2 ++
 external/pflash/ast.h                   |  2 +-
 external/pflash/pflash.c                |  2 +-
 external/pflash/rules.mk                | 21 +--------------------
 7 files changed, 40 insertions(+), 31 deletions(-)
 rename external/{pflash => common}/get_arch.sh (100%)
 create mode 100644 external/common/rules.mk

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..775388d
--- /dev/null
+++ b/external/common/rules.mk
@@ -0,0 +1,29 @@
+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
+
+#If arch changes make won't realise it needs to rebuild...
+.PHONY: arch_flash.o
+common/arch_flash.o: $(ARCH_OBJS)
+	$(CROSS_COMPILE)ld -shared $^ -o $@
+
diff --git a/external/pflash/Makefile b/external/pflash/Makefile
index 9be0e12..0754301 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 sfc-ctrl.c ast-sf-ctrl.c make_version.sh
+links: libflash ccan sfc-ctrl.c ast-sf-ctrl.c common make_version.sh
 
 libflash:
 	ln -sf ../../libflash .
@@ -11,18 +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
-	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
diff --git a/external/pflash/Makefile.dist b/external/pflash/Makefile.dist
index 017fd90..e94ad5e 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/rukes.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/pflash.c b/external/pflash/pflash.c
index 67d3e63..4f81d4d 100644
--- a/external/pflash/pflash.c
+++ b/external/pflash/pflash.c
@@ -19,7 +19,7 @@
 #include <libflash/blocklevel.h>
 #include <common/arch_flash.h>
 #include "progress.h"
-#include "io.h"
+#include "common/io.h"
 #include "ast.h"
 #include "sfc-ctrl.h"
 
diff --git a/external/pflash/rules.mk b/external/pflash/rules.mk
index c52ab43..28af3d2 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
-- 
2.4.6



More information about the Skiboot mailing list