threads / patch / 56410

v2make: add install-stripped target

Subject: [PATCH RESEND v2] make: add install-stripped target

## tl;dr

4 messages between Aug 31, 2021 and Sep 1, 2021. Diffs are folded; open one to read it.

replies: 3people: 2as markdown or json

Bagas Sanjaya· Aug 31, 2021, 01:32 UTC · lore
Add the target that install Git with stripped executables.

install and install-stripped share the almost-same recipe, with the difference only on extra arguments to $(INSTALL). In order for this to work properly, installing all programs ($(ALL_PROGRAMS) and $(install_bindir_programs)) must be splitted into separate portions for compiled programs and scripts. For the former, add $(INSTALL_OPTS) and for the latter, don't add anything.

$(INSTALL_OPTS) contains stripping options that are passed from install-stripped.

Signed-off-by: Bagas Sanjaya <bagasdotme@gmail.com>
---
 Changes from v1:
 - Share recipes between install-stripped and install targets (suggested
   by Junio)
 - Don't delete 'strip' target. There may exist scripts that depend on
   that target. Once this patch is integrated, deprecation notice can
   be displayed when running the target, but it is done in separate
   patch.
 Makefile | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
Show changes to Makefile +14 −4
diff --git a/Makefile b/Makefile
index d1feab008f..28d1e9bfae 100644
--- a/Makefile
+++ b/Makefile
@@ -3004,7 +3004,8 @@ mergetools_instdir = $(prefix)/$(mergetoolsdir)
 endif
 mergetools_instdir_SQ = $(subst ','\'',$(mergetools_instdir))
 
-install_bindir_programs := $(patsubst %,%$X,$(BINDIR_PROGRAMS_NEED_X)) $(BINDIR_PROGRAMS_NO_X)
+install_bindir_xprograms := $(patsubst %,%$X,$(BINDIR_PROGRAMS_NEED_X))
+install_bindir_programs := $(install_bindir_xprograms) $(BINDIR_PROGRAMS_NO_X)
 
 .PHONY: profile-install profile-fast-install
 profile-install: profile
@@ -3013,12 +3014,21 @@ profile-install: profile
 profile-fast-install: profile-fast
 	$(MAKE) install
 
-install: all
+INSTALL_OPTS =
+
+.PHONY: install-stripped
+
+install-stripped: INSTALL_OPTS = -s --strip-program=$(STRIP)
+
+install-stripped install: all
 	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)'
 	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
-	$(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
+	$(INSTALL) $(INSTALL_OPTS) $(PROGRAMS) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
+	$(INSTALL) $(SCRIPTS) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 	$(INSTALL) -m 644 $(SCRIPT_LIB) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
-	$(INSTALL) $(install_bindir_programs) '$(DESTDIR_SQ)$(bindir_SQ)'
+	$(INSTALL) $(INSTALL_OPTS) $(install_bindir_xprograms) '$(DESTDIR_SQ)$(bindir_SQ)'
+	$(INSTALL) $(BINDIR_PROGRAMS_NO_X) '$(DESTDIR_SQ)$(bindir_SQ)'
+
 ifdef MSVC
 	# We DO NOT install the individual foo.o.pdb files because they
 	# have already been rolled up into the exe's pdb file.

base-commit: c4203212e360b25a1c69467b5a8437d45a373cac
-- 
2.25.1
Junio C Hamano· Aug 31, 2021, 17:06 UTC · re: Bagas Sanjaya · lore

Re: [PATCH RESEND v2] make: add install-stripped target

Bagas Sanjaya <bagasdotme@gmail.com> writes:
> Add the target that install Git with stripped executables.
> ...
> +
> +install-stripped: INSTALL_OPTS = -s --strip-program=$(STRIP)
Not everybody's $(INSTALL) supports --strip-program, does it?  

FreeBSD seems to lack the option, and instead uses the $STRIPBIN environment variable to specify which program to use.

The manual page for macOS [*] does not mention --strip-program or STRIPBIN.

If the user leaves STRIP as the default (i.e. strip), this target fails, not because the user does not have 'strip', but because the 'install' used by the user does not know the --strip-program option, even though there is no need to use the option in such a case.

Given that, I am not sure if we really want "install-stripped" target. Adding INSTALL_OPTS make variable that defaults to an empty string is a good idea, but we probably can and should stop there.

Then users can do any of the following:
	$ make INSTALL_OPTS=-s install
	$ STRIPBIN=my-strip make INSTALL_OPTS=-s install

depending on their system, which sounds sufficient, and is a vast improvement over the current

	$ make ; make strip ; make install 
I would think.
[Reference]
* https://opensource.apple.com/source/file_cmds/file_cmds-321.40.3/install/install.1.auto.html
Bagas Sanjaya· Sep 1, 2021, 11:31 UTC · re: Junio C Hamano · lore

Re: [PATCH RESEND v2] make: add install-stripped target

On 01/09/21 00.06, Junio C Hamano wrote:
Show 16 quoted lines
> Given that, I am not sure if we really want "install-stripped"
> target.  Adding INSTALL_OPTS make variable that defaults to an empty
> string is a good idea, but we probably can and should stop there.
> 
> Then users can do any of the following:
> 
> 	$ make INSTALL_OPTS=-s install
> 
> 	$ STRIPBIN=my-strip make INSTALL_OPTS=-s install
> 
> depending on their system, which sounds sufficient, and is a vast
> improvement over the current
> 
> 	$ make ; make strip ; make install
> 
> I would think.

If we make $(INSTALL_OPTS) applies to both compiled executables and scripts, we have problem that $(INSTALL) -s only works for the former.

-- 
An old man doll... just what I always wanted! - Clara
Junio C Hamano· Sep 1, 2021, 17:15 UTC · re: Bagas Sanjaya · lore

Re: [PATCH RESEND v2] make: add install-stripped target

Bagas Sanjaya <bagasdotme@gmail.com> writes:
> If we make $(INSTALL_OPTS) applies to both compiled executables and
> scripts, we have problem that $(INSTALL) -s only works for the former.
Then don't make it apply to both ;-)

Isn't that what your patch did for early part of the install target? $(PROGRAMS) are installed with $(INSTALL_OPTS) while the invocation of $(INSTALL) for $(SCRIPTS) lack $(INSTALL_OPTS).

If we were to pursue this further, it probably is a good idea to rename the $(INSTALL_OPTS) to $(INSTALL_STRIP) to avoid complaints by confused users.

Something like this squashed into your patch, perhaps.
 Makefile | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
Show changes to diff +7 −8
diff --git c/Makefile w/Makefile
index 28d1e9bfae..ebef4da50c 100644
--- c/Makefile
+++ w/Makefile
@@ -465,6 +465,9 @@ all::
 # the global variable _wpgmptr containing the absolute path of the current
 # executable (this is the case on Windows).
 #
+# INSTALL_STRIP can be set to "-s" to strip binaries during installation,
+# if your $(INSTALL) command supports the option.
+#
 # Define GENERATE_COMPILATION_DATABASE to "yes" to generate JSON compilation
 # database entries during compilation if your compiler supports it, using the
 # `-MJ` flag. The JSON entries will be placed in the `compile_commands/`
@@ -3014,19 +3017,15 @@ profile-install: profile
 profile-fast-install: profile-fast
 	$(MAKE) install
 
-INSTALL_OPTS =
-
-.PHONY: install-stripped
-
-install-stripped: INSTALL_OPTS = -s --strip-program=$(STRIP)
+INSTALL_STRIP =
 
-install-stripped install: all
+install: all
 	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)'
 	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
-	$(INSTALL) $(INSTALL_OPTS) $(PROGRAMS) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
+	$(INSTALL) $(INSTALL_STRIP) $(PROGRAMS) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 	$(INSTALL) $(SCRIPTS) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 	$(INSTALL) -m 644 $(SCRIPT_LIB) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
-	$(INSTALL) $(INSTALL_OPTS) $(install_bindir_xprograms) '$(DESTDIR_SQ)$(bindir_SQ)'
+	$(INSTALL) $(INSTALL_STRIP) $(install_bindir_xprograms) '$(DESTDIR_SQ)$(bindir_SQ)'
 	$(INSTALL) $(BINDIR_PROGRAMS_NO_X) '$(DESTDIR_SQ)$(bindir_SQ)'
 
 ifdef MSVC

← back to recent threads