From 6fb22ecfb1d293539c343e5cb93fdc189f682287 Mon Sep 17 00:00:00 2001 From: Nicolas Dechesne Date: Fri, 3 Jun 2016 17:15:53 +0200 Subject: [PATCH 1/5] makefile: create destination folder when installing files Signed-off-by: Nicolas Dechesne --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 675195c..401b8f3 100644 --- a/Makefile +++ b/Makefile @@ -70,7 +70,7 @@ $1: $(call src_to_obj,$($1-srcs)) $3: $1 @echo "INSTALL $$<" - @install -m 755 $$< $$@ + @install -D -m 755 $$< $$@ all-install += $3 endef From dcf148e15e9f73905cc620fe45ddd59d90ce7f52 Mon Sep 17 00:00:00 2001 From: Nicolas Dechesne Date: Fri, 3 Jun 2016 18:07:45 +0200 Subject: [PATCH 2/5] makefile: split bin and lib targets macros Build libraries with proper soname, real and linker names, using symlinks appropriately. As such, the generic macro 'add-target' can no longer be used for both binary and libaries. Signed-off-by: Nicolas Dechesne --- Makefile | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 401b8f3..e619c39 100644 --- a/Makefile +++ b/Makefile @@ -57,25 +57,45 @@ endif @$(CC) -MM -MF $(call src_to_dep,$<) -MP -MT "$@ $(call src_to_dep,$<)" $(CFLAGS) $(_CFLAGS) $< @$(CC) -o $@ -c $< $(CFLAGS) $(_CFLAGS) -define add-target +define add-target-deps all-srcs += $($1-srcs) all-objs += $(call src_to_obj,$($1-srcs)) all-deps += $(call src_to_dep,$($1-srcs)) all-clean += $1 $(call src_to_obj,$($1-srcs)): _CFLAGS := $($1-cflags) +endef + +define add-bin-target + +$(call add-target-deps,$1) $1: $(call src_to_obj,$($1-srcs)) @echo "LD $$@" - @$$(CC) -o $$@ $$(filter %.o,$$^) $(LDFLAGS) $2 + $$(CC) -o $$@ $$(filter %.o,$$^) $(LDFLAGS) -static -$3: $1 +$(PREFIX)/bin/$1: $1 @echo "INSTALL $$<" @install -D -m 755 $$< $$@ -all-install += $3 +all-install += $(PREFIX)/bin/$1 +endef + +define add-lib-target + +$(call add-target-deps,$1) + +$1: $(call src_to_obj,$($1-srcs)) + @echo "LD $$@" + $$(CC) -o $$@ $$(filter %.o,$$^) $(LDFLAGS) -shared -Wl,-soname,$1.$(proj-major) + +$(PREFIX)/lib/$1.$(proj-version): $1 + @echo "INSTALL $$<" + @install -D -m 755 $$< $$@ + @ln -sf $1.$(proj-version) $(PREFIX)/lib/$1.$(proj-major) + @ln -sf $1.$(proj-major) $(PREFIX)/lib/$1 + +all-install += $(PREFIX)/lib/$1.$(proj-version) endef -add-bin-target = $(call add-target,$1,-static,$(PREFIX)/bin/$1) -add-lib-target = $(call add-target,$1,-shared,$(PREFIX)/lib/$1) $(foreach v,$(filter-out %.so,$(targets)),$(eval $(call add-bin-target,$v))) $(foreach v,$(filter %.so,$(targets)),$(eval $(call add-lib-target,$v))) From b5cee337fa9a5a2a897624aefe7baeae66c4df07 Mon Sep 17 00:00:00 2001 From: Nicolas Dechesne Date: Fri, 3 Jun 2016 19:37:37 +0200 Subject: [PATCH 3/5] makefile: add support to install header file New macro to be used to deploy header files when 'installing'. Use it as: $(call add-inc-target,lib,foo.h) to install file lib/foo.h Signed-off-by: Nicolas Dechesne --- Makefile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Makefile b/Makefile index e619c39..7f8cad6 100644 --- a/Makefile +++ b/Makefile @@ -57,6 +57,14 @@ endif @$(CC) -MM -MF $(call src_to_dep,$<) -MP -MT "$@ $(call src_to_dep,$<)" $(CFLAGS) $(_CFLAGS) $< @$(CC) -o $@ -c $< $(CFLAGS) $(_CFLAGS) +define add-inc-target +$(PREFIX)/include/$2: $1/$2 + @echo "INSTALL $$<" + @install -D -m 755 $$< $$@ + +all-install += $(PREFIX)/include/$2 +endef + define add-target-deps all-srcs += $($1-srcs) all-objs += $(call src_to_obj,$($1-srcs)) From ea3c58a2e2700476b759ec0b4966e7f262408ac5 Mon Sep 17 00:00:00 2001 From: Nicolas Dechesne Date: Fri, 3 Jun 2016 19:39:28 +0200 Subject: [PATCH 4/5] makefile: install libqrtr.h file Signed-off-by: Nicolas Dechesne --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 7f8cad6..4080f57 100644 --- a/Makefile +++ b/Makefile @@ -107,6 +107,7 @@ endef $(foreach v,$(filter-out %.so,$(targets)),$(eval $(call add-bin-target,$v))) $(foreach v,$(filter %.so,$(targets)),$(eval $(call add-lib-target,$v))) +$(eval $(call add-inc-target,lib,libqrtr.h)) install: $(all-install) From 44bd79feb73847ad78c35b20adf22c772cea4325 Mon Sep 17 00:00:00 2001 From: Nicolas Dechesne Date: Sun, 5 Jun 2016 21:58:57 +0200 Subject: [PATCH 5/5] Makefile: implement GNU Coding Standard for Makefiles GNU coding standards notably specifies: * install files with the $(DESTDIR) to the target system image * install files with the $(prefix), not $(PREFIX) * the default value of $(prefix) should be /usr/local as per https://www.gnu.org/prep/standards/html_node/Directory-Variables.html. Signed-off-by: Nicolas Dechesne --- Makefile | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 4080f57..d71a72f 100644 --- a/Makefile +++ b/Makefile @@ -6,9 +6,7 @@ proj-version := $(proj-major).$(proj-minor) CFLAGS := -Wall -g LDFLAGS := -ifeq ($(PREFIX),) -PREFIX := /usr -endif +prefix := /usr/local ifneq ($(CROSS_COMPILE),) CC := $(CROSS_COMPILE)gcc @@ -58,11 +56,11 @@ endif @$(CC) -o $@ -c $< $(CFLAGS) $(_CFLAGS) define add-inc-target -$(PREFIX)/include/$2: $1/$2 +$(DESTDIR)$(prefix)/include/$2: $1/$2 @echo "INSTALL $$<" @install -D -m 755 $$< $$@ -all-install += $(PREFIX)/include/$2 +all-install += $(DESTDIR)$(prefix)/include/$2 endef define add-target-deps @@ -81,11 +79,11 @@ $1: $(call src_to_obj,$($1-srcs)) @echo "LD $$@" $$(CC) -o $$@ $$(filter %.o,$$^) $(LDFLAGS) -static -$(PREFIX)/bin/$1: $1 +$(DESTDIR)$(prefix)/bin/$1: $1 @echo "INSTALL $$<" @install -D -m 755 $$< $$@ -all-install += $(PREFIX)/bin/$1 +all-install += $(DESTDIR)$(prefix)/bin/$1 endef define add-lib-target @@ -96,13 +94,13 @@ $1: $(call src_to_obj,$($1-srcs)) @echo "LD $$@" $$(CC) -o $$@ $$(filter %.o,$$^) $(LDFLAGS) -shared -Wl,-soname,$1.$(proj-major) -$(PREFIX)/lib/$1.$(proj-version): $1 +$(DESTDIR)$(prefix)/lib/$1.$(proj-version): $1 @echo "INSTALL $$<" @install -D -m 755 $$< $$@ - @ln -sf $1.$(proj-version) $(PREFIX)/lib/$1.$(proj-major) - @ln -sf $1.$(proj-major) $(PREFIX)/lib/$1 + @ln -sf $1.$(proj-version) $(DESTDIR)$(prefix)/lib/$1.$(proj-major) + @ln -sf $1.$(proj-major) $(DESTDIR)$(prefix)/lib/$1 -all-install += $(PREFIX)/lib/$1.$(proj-version) +all-install += $(DESTDIR)$(prefix)/lib/$1.$(proj-version) endef $(foreach v,$(filter-out %.so,$(targets)),$(eval $(call add-bin-target,$v)))