[Skiboot] [PATCH 2/2] external: improve xscom commands Makefile

Cédric Le Goater clg at fr.ibm.com
Thu Mar 31 23:23:49 AEDT 2016


The current Makefile is a bit rustic compared to other skiboot
tools. This patch adds a proper install target and a new versioning
target.

Signed-off-by: Cédric Le Goater <clg at fr.ibm.com>
---
 external/xscom-utils/Makefile  |   54 +++++++++++++++++++++++++++++++++--------
 external/xscom-utils/getscom.c |    4 ++-
 external/xscom-utils/getsram.c |    4 ++-
 external/xscom-utils/putscom.c |    4 ++-
 skiboot.spec                   |    4 +--
 5 files changed, 55 insertions(+), 15 deletions(-)

Index: skiboot.git/external/xscom-utils/getscom.c
===================================================================
--- skiboot.git.orig/external/xscom-utils/getscom.c
+++ skiboot.git/external/xscom-utils/getscom.c
@@ -74,6 +74,8 @@ static void print_chip_info(uint32_t chi
 	
 }
 
+extern const char version[];
+
 int main(int argc, char *argv[])
 {
 	uint64_t val, addr = -1ull;
@@ -108,7 +110,7 @@ int main(int argc, char *argv[])
 			list_chips = true;
 			break;
 		case 'v':
-			printf("xscom utils version %s\n", VERSION);
+			printf("xscom utils version %s\n", version);
 			exit(0);
 		default:
 			exit(1);
Index: skiboot.git/external/xscom-utils/getsram.c
===================================================================
--- skiboot.git.orig/external/xscom-utils/getsram.c
+++ skiboot.git/external/xscom-utils/getsram.c
@@ -32,6 +32,8 @@ static void print_usage(int code)
 	exit(code);
 }
 
+extern const char version[];
+
 int main(int argc, char *argv[])
 {
 	uint64_t val, addr = -1ull;
@@ -69,7 +71,7 @@ int main(int argc, char *argv[])
 			print_usage(0);
 			break;
 		case 'v':
-			printf("xscom utils version %s\n", VERSION);
+			printf("xscom utils version %s\n", version);
 			exit(0);
 		default:
 			exit(1);
Index: skiboot.git/external/xscom-utils/Makefile
===================================================================
--- skiboot.git.orig/external/xscom-utils/Makefile
+++ skiboot.git/external/xscom-utils/Makefile
@@ -1,23 +1,57 @@
-all: getscom putscom getsram
+CC = $(CROSS_COMPILE)gcc
 
 XSCOM_VERSION ?= $(shell ../../make_version.sh xscom-utils)
-CFLAGS?=-O2 -g -Wall -m64
-override CFLAGS += -DVERSION=\"$(XSCOM_VERSION)\"
+CFLAGS += -O2 -g -Wall -m64
+
+prefix = /usr/local/
+sbindir = $(prefix)/sbin
+datadir = $(prefix)/share
+mandir = $(datadir)/man
+
+%.o: %.c
+	$(Q_CC)$(COMPILE.c) $< -o $@
+
+# Use make V=1 for a verbose build.
+ifndef V
+        Q_CC=	@echo '    CC ' $@;
+        Q_LINK=	@echo '  LINK ' $@;
+        Q_LN=   @echo '    LN ' $@;
+        Q_MKDIR=@echo ' MKDIR ' $@;
+endif
+
+all: getscom putscom getsram
+
+getscom: getscom.c xscom.o version.o
+	$(Q_LINK)$(LINK.o) -o $@ $^
 
-getscom: getscom.c xscom.c
-	$(CC) $(CFLAGS) -o $@ $^
+getsram: getsram.o xscom.o sram.o version.o
+	$(Q_LINK)$(LINK.o) -o $@ $^
 
-getsram: getsram.c xscom.c sram.c
-	$(CC) $(CFLAGS) -o $@ $^
+putscom: putscom.o xscom.o version.o
+	$(Q_LINK)$(LINK.o) -o $@ $^
 
-putscom: putscom.c xscom.c
-	$(CC) $(CFLAGS) -o $@ $^
+install: all
+	install -D getscom $(DESTDIR)$(sbindir)/getscom
+	install -D putscom $(DESTDIR)$(sbindir)/putscom
+	install -D getsram $(DESTDIR)$(sbindir)/getsram
 
 .PHONY: clean
 clean:
-	rm -rf getscom putscom getsram
+	rm -rf *.[od] getscom putscom getsram
 
 .PHONY: distclean
 distclean: clean
 	rm -rf *.c~ *.h~ *.i *.s Makefile~
 
+version.c: ../../make_version.sh  .version
+	@(if [ "a$(XSCOM_VERSION)" = "a" ]; then \
+	echo "#error You need to set XSCOM_VERSION environment variable" > $@ ;\
+	else \
+	echo "const char version[] = \"$(XSCOM_VERSION)\";" ;\
+	fi) > $@
+
+.PHONY: VERSION-always
+.version: VERSION-always
+	@echo $(XSCOM_VERSION) > $@.tmp
+	@cmp -s $@ $@.tmp || cp $@.tmp $@
+	@rm -f $@.tmp
Index: skiboot.git/external/xscom-utils/putscom.c
===================================================================
--- skiboot.git.orig/external/xscom-utils/putscom.c
+++ skiboot.git/external/xscom-utils/putscom.c
@@ -30,6 +30,8 @@ static void print_usage(int code)
 	exit(code);
 }
 
+extern const char version[];
+
 int main(int argc, char *argv[])
 {
 	uint64_t val = -1ull, addr = -1ull;
@@ -62,7 +64,7 @@ int main(int argc, char *argv[])
 			chip_id = strtoul(optarg, NULL, 0);
 			break;
 		case 'v':
-			printf("xscom utils version %s\n", VERSION);
+			printf("xscom utils version %s\n", version);
 			exit(0);
 		case 'h':
 			print_usage(0);
Index: skiboot.git/skiboot.spec
===================================================================
--- skiboot.git.orig/skiboot.spec
+++ skiboot.git/skiboot.spec
@@ -58,8 +58,7 @@ XSCOM_VERSION=%version make V=1 -C exter
 %install
 make -C external/opal-prd install DESTDIR=%{buildroot} prefix=/usr
 make -C external/gard install DESTDIR=%{buildroot} prefix=/usr
-cp external/xscom-utils/{get,put}scom %{buildroot}%{_sbindir}
-cp external/pflash/pflash %{buildroot}%{_sbindir}
+make -C external/xscom-utils install DESTDIR=%{buildroot} prefix=/usr
 
 mkdir -p %{buildroot}%{_unitdir}
 install -m 644 -p %{SOURCE1} %{buildroot}%{_unitdir}/opal-prd.socket
@@ -102,6 +101,7 @@ fi
 %{_sbindir}/opal-gard
 %{_sbindir}/getscom
 %{_sbindir}/putscom
+%{_sbindir}/getsram
 %{_sbindir}/pflash
 %{_mandir}/man1/*
 



More information about the Skiboot mailing list