diff mbox

external: Add Makefile targets to install libflash

Message ID 1448927612-14292-1-git-send-email-sam.mj@au1.ibm.com
State Changes Requested
Headers show

Commit Message

Sam Mendoza-Jonas Nov. 30, 2015, 11:53 p.m. UTC
This adds a Makefile under external/shared to build libflash as a
shared library and install it.
This allows programs outside of the skiboot tree to link against
libflash in order to access MTD devices (eg. Petitboot).

Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
---
(Assuming Stewart doesn't rope me into autotools)
Updated from RFC to follow changes to build in pwd, and adds a real version
string.

 external/shared/Makefile | 57 ++++++++++++++++++++++++++++++++++++++++++++++++
 external/shared/config.h | 19 ++++++++++++++++
 2 files changed, 76 insertions(+)
 create mode 100644 external/shared/Makefile
 create mode 100644 external/shared/config.h

Comments

Sam Mendoza-Jonas Dec. 22, 2015, 5:13 a.m. UTC | #1
On Tue, Dec 01, 2015 at 10:53:32AM +1100, Samuel Mendoza-Jonas wrote:
> This adds a Makefile under external/shared to build libflash as a
> shared library and install it.
> This allows programs outside of the skiboot tree to link against
> libflash in order to access MTD devices (eg. Petitboot).
> 
> Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
> ---
> (Assuming Stewart doesn't rope me into autotools)
> Updated from RFC to follow changes to build in pwd, and adds a real version
> string.

I have a v2 of this which fixes some issues when building in an op-build
environment - namely proper ARCH checking and symlink creation. Will
post when I've finalised testing and/or in the new year :)

> 
>  external/shared/Makefile | 57 ++++++++++++++++++++++++++++++++++++++++++++++++
>  external/shared/config.h | 19 ++++++++++++++++
>  2 files changed, 76 insertions(+)
>  create mode 100644 external/shared/Makefile
>  create mode 100644 external/shared/config.h
> 
> diff --git a/external/shared/Makefile b/external/shared/Makefile
> new file mode 100644
> index 0000000..f9e2786
> --- /dev/null
> +++ b/external/shared/Makefile
> @@ -0,0 +1,57 @@
> +.DEFAULT_GOAL := all
> +GET_ARCH = ../../external/common/get_arch.sh
> +include ../../external/common/rules.mk
> +
> +PREFIX ?= /usr/local/
> +LIBDIR = $(PREFIX)/lib
> +INCDIR = $(PREFIX)/include/libflash
> +
> +VERSION = $(shell ../../make_version.sh)
> +
> +CC = $(CROSS_COMPILE)gcc
> +CFLAGS += -m64 -Werror -Wall -g2 -ggdb -I. -fPIC
> +
> +.PHONY: links
> +links: libflash ccan common
> +
> +libflash:
> +	ln -sf ../../libflash .
> +
> +common:
> +	ln -sf ../common .
> +
> +ccan:
> +	ln -sf ../../ccan .
> +
> +LIBFLASH_OBJS = libflash-file.o libflash-libflash.o libflash-libffs.o libflash-ecc.o libflash-blocklevel.o
> +ARCHFLASH_OBJS = common-arch_flash.o
> +OBJS = $(LIBFLASH_OBJS) $(ARCHFLASH_OBJS)
> +
> +LIBFLASH_H = libflash/file.h libflash/libflash.h libflash/libffs.h libflash/ffs.h libflash/ecc.h libflash/blocklevel.h libflash/errors.h
> +ARCHFLASH_H = common/arch_flash.h
> +
> +$(LIBFLASH_OBJS) : libflash-%.o : libflash/%.c
> +	$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
> +
> +clean:
> +	rm -f $(OBJS) common-*.o *.so*
> +
> +distclean: clean
> +	rm -f ccan libflash common
> +
> +all: links arch_links $(OBJS)
> +	($(CC) -shared -Wl,-soname,libflash.so -o libflash.so.$(VERSION) $(OBJS))
> +
> +install-lib: all
> +	install -D -m 0755 libflash.so.$(VERSION) $(LIBDIR)/libflash.so.$(VERSION)
> +	ldconfig -n $(LIBDIR)
> +
> +install-dev:
> +	mkdir -p $(INCDIR)
> +	install -m 0644 $(LIBFLASH_H) $(ARCHFLASH_H) $(INCDIR)
> +
> +install: install-lib install-dev
> +
> +uninstall:
> +	rm -f $(LIBDIR)/libflash*
> +	rm -rf $(INCDIR)
> diff --git a/external/shared/config.h b/external/shared/config.h
> new file mode 100644
> index 0000000..a132a01
> --- /dev/null
> +++ b/external/shared/config.h
> @@ -0,0 +1,19 @@
> +/* For CCAN */
> +
> +#include <endian.h>
> +#include <byteswap.h>
> +
> +#define HAVE_TYPEOF			1
> +#define HAVE_BUILTIN_TYPES_COMPATIBLE_P	1
> +
> +
> +#if __BYTE_ORDER == __LITTLE_ENDIAN
> +#define HAVE_BIG_ENDIAN         0
> +#define HAVE_LITTLE_ENDIAN      1
> +#else
> +#define HAVE_BIG_ENDIAN         1
> +#define HAVE_LITTLE_ENDIAN      0
> +#endif
> +
> +#define HAVE_BYTESWAP_H 1
> +#define HAVE_BSWAP_64	1
> -- 
> 2.6.2
>
Stewart Smith Jan. 6, 2016, 4:11 a.m. UTC | #2
Sam Mendoza-Jonas <sam.mj@au1.ibm.com> writes:

> On Tue, Dec 01, 2015 at 10:53:32AM +1100, Samuel Mendoza-Jonas wrote:
>> This adds a Makefile under external/shared to build libflash as a
>> shared library and install it.
>> This allows programs outside of the skiboot tree to link against
>> libflash in order to access MTD devices (eg. Petitboot).
>> 
>> Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
>> ---
>> (Assuming Stewart doesn't rope me into autotools)
>> Updated from RFC to follow changes to build in pwd, and adds a real version
>> string.
>
> I have a v2 of this which fixes some issues when building in an op-build
> environment - namely proper ARCH checking and symlink creation. Will
> post when I've finalised testing and/or in the new year :)

I gather that's going to be the new year, which is now this year :)
diff mbox

Patch

diff --git a/external/shared/Makefile b/external/shared/Makefile
new file mode 100644
index 0000000..f9e2786
--- /dev/null
+++ b/external/shared/Makefile
@@ -0,0 +1,57 @@ 
+.DEFAULT_GOAL := all
+GET_ARCH = ../../external/common/get_arch.sh
+include ../../external/common/rules.mk
+
+PREFIX ?= /usr/local/
+LIBDIR = $(PREFIX)/lib
+INCDIR = $(PREFIX)/include/libflash
+
+VERSION = $(shell ../../make_version.sh)
+
+CC = $(CROSS_COMPILE)gcc
+CFLAGS += -m64 -Werror -Wall -g2 -ggdb -I. -fPIC
+
+.PHONY: links
+links: libflash ccan common
+
+libflash:
+	ln -sf ../../libflash .
+
+common:
+	ln -sf ../common .
+
+ccan:
+	ln -sf ../../ccan .
+
+LIBFLASH_OBJS = libflash-file.o libflash-libflash.o libflash-libffs.o libflash-ecc.o libflash-blocklevel.o
+ARCHFLASH_OBJS = common-arch_flash.o
+OBJS = $(LIBFLASH_OBJS) $(ARCHFLASH_OBJS)
+
+LIBFLASH_H = libflash/file.h libflash/libflash.h libflash/libffs.h libflash/ffs.h libflash/ecc.h libflash/blocklevel.h libflash/errors.h
+ARCHFLASH_H = common/arch_flash.h
+
+$(LIBFLASH_OBJS) : libflash-%.o : libflash/%.c
+	$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
+
+clean:
+	rm -f $(OBJS) common-*.o *.so*
+
+distclean: clean
+	rm -f ccan libflash common
+
+all: links arch_links $(OBJS)
+	($(CC) -shared -Wl,-soname,libflash.so -o libflash.so.$(VERSION) $(OBJS))
+
+install-lib: all
+	install -D -m 0755 libflash.so.$(VERSION) $(LIBDIR)/libflash.so.$(VERSION)
+	ldconfig -n $(LIBDIR)
+
+install-dev:
+	mkdir -p $(INCDIR)
+	install -m 0644 $(LIBFLASH_H) $(ARCHFLASH_H) $(INCDIR)
+
+install: install-lib install-dev
+
+uninstall:
+	rm -f $(LIBDIR)/libflash*
+	rm -rf $(INCDIR)
diff --git a/external/shared/config.h b/external/shared/config.h
new file mode 100644
index 0000000..a132a01
--- /dev/null
+++ b/external/shared/config.h
@@ -0,0 +1,19 @@ 
+/* For CCAN */
+
+#include <endian.h>
+#include <byteswap.h>
+
+#define HAVE_TYPEOF			1
+#define HAVE_BUILTIN_TYPES_COMPATIBLE_P	1
+
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#define HAVE_BIG_ENDIAN         0
+#define HAVE_LITTLE_ENDIAN      1
+#else
+#define HAVE_BIG_ENDIAN         1
+#define HAVE_LITTLE_ENDIAN      0
+#endif
+
+#define HAVE_BYTESWAP_H 1
+#define HAVE_BSWAP_64	1