Skip to contentSkip to conversation

Makefile: create an install-symlinks target

PATCH In review David Kastrup 4 participants 7 messages Jun 15, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Makefile: create an install-symlinks target

[commit text mostly pinched from INSTALL]

An alternative global installation method making it much easier to uninstall is to use a package-specific prefix like /opt/git, then create symlinks from /usr/local into that hierarchy. Uninstalling can then be achieved by

	# rm -rf /opt/git; find /usr/local -xtype l -delete

You can create a setup like that after having used one of the above install recipes with prefix=/opt/git by writing

	# make prefix=/opt/git symlinkprefix=/usr/local install-symlinks

This works by copying the directory hierarchy of $prefix to $symlinkprefix (not copying or descending to any directories of the name git* matched case-insensitively), then linking all the rest.

---
 INSTALL  |   12 ++++++++++++
 Makefile |   10 +++++++++-
 2 files changed, 21 insertions(+), 1 deletions(-)
INSTALL +12 -0
index 79e71b6..22df145 100644
@@ -21,6 +21,18 @@ set up install paths (via config.mak.autogen), so you can write instead
 	$ make all doc ;# as yourself
 	# make install install-doc ;# as root
 
+An alternative global installation method making it much easier to
+uninstall is to use a package-specific prefix like /opt/git, then
+create symlinks from /usr/local into that hierarchy.  Uninstalling can
+then be achieved by
+
+	# rm -rf /opt/git; find /usr/local -xtype l -delete
+
+You can create a setup like that after having used one of the above
+install recipes with prefix=/opt/git by writing
+
+	# make prefix=/opt/git symlinkprefix=/usr/local install-symlinks
+
 
 Issues of note:
 
Makefile +9 -1
index 73b487f..87b317f 100644
@@ -142,6 +142,7 @@ ALL_LDFLAGS = $(LDFLAGS)
 STRIP ?= strip
 
 prefix = $(HOME)
+symlinkprefix = /usr/local
 bindir = $(prefix)/bin
 gitexecdir = $(bindir)
 sharedir = $(prefix)/share
@@ -692,6 +693,7 @@ bindir_SQ = $(subst ','\'',$(bindir))
 gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
 template_dir_SQ = $(subst ','\'',$(template_dir))
 prefix_SQ = $(subst ','\'',$(prefix))
+symlinkprefix_SQ = $(subst ','\'',$(symlinkprefix))
 
 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
 PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
@@ -996,7 +998,13 @@ install-doc:
 quick-install-doc:
 	$(MAKE) -C Documentation quick-install
 
-
+# The somewhat strange looking lines start with an ignored $(MAKE) in
+# order to be executed also in make -n calls.
+install-symlinks:
+	@: $(MAKE) && echo cd '$(prefix_SQ)' && cd '$(prefix_SQ)' && find . -type d ! \( -iname 'git*' -prune \) -exec echo $(INSTALL) -m 755 -d '$(symlinkprefix_SQ)/{}' \;
+	@cd '$(prefix_SQ)' && find . -type d ! \( -iname 'git*' -prune \) -exec $(INSTALL) -m 755 -d '$(symlinkprefix_SQ)/{}' \;
+	@: $(MAKE) && echo cd '$(prefix_SQ)' && cd '$(prefix_SQ)' && find . \( -type d -iname 'git*' -prune -o ! -type d \) -exec echo $(RM) -r '$(symlinkprefix_SQ)/{}' \; -exec echo ln -s '$(prefix_SQ)/{}' '$(symlinkprefix_SQ)/{}' \;
+	@cd '$(prefix_SQ)' && find . \( -type d -iname 'git*' -prune -o ! -type d \) -exec $(RM) -r '$(symlinkprefix_SQ)/{}' \; -exec ln -s '$(prefix_SQ)/{}' '$(symlinkprefix_SQ)/{}' \;
 
 ### Maintainer's dist rules
 
Signature · 1 line
1.5.3.rc2.84.g6497
#1 lore raw
Quoted 12 lines · David Kastrup

[commit text mostly pinched from INSTALL]

An alternative global installation method making it much easier to uninstall is to use a package-specific prefix like /opt/git, then create symlinks from /usr/local into that hierarchy. Uninstalling can then be achieved by

	# rm -rf /opt/git; find /usr/local -xtype l -delete

You can create a setup like that after having used one of the above install recipes with prefix=/opt/git by writing

Quoted 7 lines
	# make prefix=/opt/git symlinkprefix=/usr/local install-symlinks

This works by copying the directory hierarchy of $prefix to $symlinkprefix (not copying or descending to any directories of the name git* matched case-insensitively), then linking all the rest.

AFAIR I suggested this the last time this came up, but in case you missed it:

Use (x)stow for this. It does exactly what you want. No need to hack the Makefile.

-Peter

#3 lore raw
Quoted 3 lines · Junio C Hamano

I thought we already rejected the "install symlink" in the earlier round. Am I mistaken, or are there any compelling new reasons to revisit it?

Uh, perhaps I have a patchy recollection, but what I remember is that Scho argued that one might use something like xstow or a package manager instead, and I replied that

a) this required the installation of additional software for a simple task.

b) if the software worked using symbolic links, it would not know at what level to make the links (namely create /usr/local/share/man/man1 and link every file from /opt/git/share/man/man1, but link the directory /usr/local/share/git-core directly to /opt/git/share/git-core).

I don't remember a conclusive reply to that. Not seeing the patch appear either, I decided to clean it up, remove the objection of using the GNU-specific -mindepth option, and properly document the usage.

Since the stuff is strictly an additional convenience not impacting any of the existing targets, I would not have thought it terribly controversial.

If I have misinterpreted or misremembered part of the discussion, I apologize. No harm was intended.

In any case, some people might want to make use of the polished patch series even if it is not applied to git.git.

Is there a place other than the git list where one can provide patches that are not likely to end up in git.git?

Thanks,

Signature · 1 line
David Kastrup, Kriemhildstr. 15, 44793 Bochum
#4 lore raw
Quoted 2 lines · David Kastrup

a) this required the installation of additional software for a simple task.

I would think it's preferable to have a single piece of software to manage these links than attempt to craft a custom solution for every package you install.

Quoted 5 lines

b) if the software worked using symbolic links, it would not know at what level to make the links (namely create /usr/local/share/man/man1 and link every file from /opt/git/share/man/man1, but link the directory /usr/local/share/git-core directly to /opt/git/share/git-core).

What stow does is to create a directory for every level where multiple packages have files or non-stow files exists. It would create a link at /usr/local/share/git-core because nobody else uses that directory. If there are other /usr/local/share/man/man1/* files, it would make a link for every file in the git version.

Quoted 3 lines

Since the stuff is strictly an additional convenience not impacting any of the existing targets, I would not have thought it terribly controversial.

It's additional maintenance, mostly. I don't have an objection to it, although I also don't see a reason to include it.

Quoted 2 lines

Is there a place other than the git list where one can provide patches that are not likely to end up in git.git?

You could make a repo at repo.or.cz, I think. Have different branches to maintain features and rebase them on top of master periodically. Or just any random web-page to publish raw patches.

My $0.02,
~~ Brian

#5 lore raw

PATCH 1/1 Makefile: use $(FIND) instead of find

In reply to David Kastrup

Some people might prefer to be able to specify the find utility to use, in particular for the more complicated usage in the install-symlinks target.

---
 Makefile |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
Makefile +7 -6
index 87b317f..29dfdeb 100644
@@ -178,6 +178,7 @@ AR = ar
 RM = rm -f
 TAR = tar
 INSTALL = install
+FIND = find
 RPMBUILD = rpmbuild
 TCL_PATH = tclsh
 TCLTK_PATH = wish
@@ -905,11 +906,11 @@ doc:
 
 TAGS:
 	$(RM) TAGS
-	find . -name '*.[hcS]' -print | xargs etags -a
+	$(FIND) . -name '*.[hcS]' -print | xargs etags -a
 
 tags:
 	$(RM) tags
-	find . -name '*.[hcS]' -print | xargs ctags -a
+	$(FIND) . -name '*.[hcS]' -print | xargs ctags -a
 
 ### Detect prefix changes
 TRACK_CFLAGS = $(subst ','\'',$(ALL_CFLAGS)):\
@@ -1001,10 +1002,10 @@ quick-install-doc:
 # The somewhat strange looking lines start with an ignored $(MAKE) in
 # order to be executed also in make -n calls.
 install-symlinks:
-	@: $(MAKE) && echo cd '$(prefix_SQ)' && cd '$(prefix_SQ)' && find . -type d ! \( -iname 'git*' -prune \) -exec echo $(INSTALL) -m 755 -d '$(symlinkprefix_SQ)/{}' \;
-	@cd '$(prefix_SQ)' && find . -type d ! \( -iname 'git*' -prune \) -exec $(INSTALL) -m 755 -d '$(symlinkprefix_SQ)/{}' \;
-	@: $(MAKE) && echo cd '$(prefix_SQ)' && cd '$(prefix_SQ)' && find . \( -type d -iname 'git*' -prune -o ! -type d \) -exec echo $(RM) -r '$(symlinkprefix_SQ)/{}' \; -exec echo ln -s '$(prefix_SQ)/{}' '$(symlinkprefix_SQ)/{}' \;
-	@cd '$(prefix_SQ)' && find . \( -type d -iname 'git*' -prune -o ! -type d \) -exec $(RM) -r '$(symlinkprefix_SQ)/{}' \; -exec ln -s '$(prefix_SQ)/{}' '$(symlinkprefix_SQ)/{}' \;
+	@: $(MAKE) && echo cd '$(prefix_SQ)' && cd '$(prefix_SQ)' && $(FIND) . -type d ! \( -iname 'git*' -prune \) -exec echo $(INSTALL) -m 755 -d '$(symlinkprefix_SQ)/{}' \;
+	@cd '$(prefix_SQ)' && $(FIND) . -type d ! \( -iname 'git*' -prune \) -exec $(INSTALL) -m 755 -d '$(symlinkprefix_SQ)/{}' \;
+	@: $(MAKE) && echo cd '$(prefix_SQ)' && cd '$(prefix_SQ)' && $(FIND) . \( -type d -iname 'git*' -prune -o ! -type d \) -exec echo $(RM) -r '$(symlinkprefix_SQ)/{}' \; -exec echo ln -s '$(prefix_SQ)/{}' '$(symlinkprefix_SQ)/{}' \;
+	@cd '$(prefix_SQ)' && $(FIND) . \( -type d -iname 'git*' -prune -o ! -type d \) -exec $(RM) -r '$(symlinkprefix_SQ)/{}' \; -exec ln -s '$(prefix_SQ)/{}' '$(symlinkprefix_SQ)/{}' \;
 
 ### Maintainer's dist rules
 
Signature · 1 line
1.5.3.rc2.84.g6497
#6 lore raw

Re: [PATCH] Makefile: use $(FIND) instead of find

Will apply excluding the install-symlinks bit. The $(FIND) thing is a good idea independently. Thanks.