# [PATCH] Makefile: create an install-symlinks target

8 messages from 2007-07-18 to 2007-07-18. Participants: David Kastrup, Johannes Schindelin, Alex Riesen, Peter Baumann.
Thread: https://gitlist.dev/t/9089

## David Kastrup, 2007-07-18 10:41

Subject: [PATCH] Makefile: create an install-symlinks target
Message-ID: <86bqe9lwy8.fsf@lola.quinscape.zz>
URL: https://gitlist.dev/e/86bqe9lwy8.fsf%40lola.quinscape.zz

```

Use this, for example, to do
rm -rf /opt/git
make prefix=/opt/git install
make symlinkprefix=/usr/local prefix=/opt/git install-symlinks
---
 Makefile |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/Makefile b/Makefile
index 73b487f..df2fe8d 100644
--- a/Makefile
+++ b/Makefile
@@ -142,6 +142,7 @@ ALL_LDFLAGS = $(LDFLAGS)
 STRIP ?= strip
 
 prefix = $(HOME)
+symlinkprefix = /usr/local
 bindir = $(prefix)/bin
 gitexecdir = $(bindir)
 sharedir = $(prefix)/share
@@ -996,7 +997,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) && cd '$(prefix_SQ)' && find . -mindepth 1 -type d ! \( -iname 'git*' -prune -exec echo rm -rf '$(symlinkprefix)/{}' \; \) -exec echo $(INSTALL) -m 755 -d '$(symlinkprefix)/{}' \;
+	@cd '$(prefix_SQ)' && find . -mindepth 1 -type d ! \( -iname 'git*' -prune -exec rm -rf '$(symlinkprefix)/{}' \; \) -exec $(INSTALL) -m 755 -d '$(symlinkprefix)/{}' \;
+	@: $(MAKE) && cd '$(prefix_SQ)' && find . -mindepth 1 \( -type d -iname 'git*' -prune -o ! -type d \) -exec echo ln -snf '$(prefix_SQ)/{}' '$(symlinkprefix)/{}' \;
+	@cd '$(prefix_SQ)' && find . -mindepth 1 \( -type d -iname 'git*' -prune -o ! -type d \) -exec ln -snf '$(prefix_SQ)/{}' '$(symlinkprefix)/{}' \;
 
 ### Maintainer's dist rules
 
-- 
1.5.3.rc2.41.gb47b1

```

## David Kastrup, 2007-07-18 10:41

Subject: [PATCH 1/2] Makefile: create an install-symlinks target
Message-ID: <6e14af24a3aa8af7e21e0a3f92c83c82e147202a.1184770193.git.dak@gnu.org>
URL: https://gitlist.dev/e/6e14af24a3aa8af7e21e0a3f92c83c82e147202a.1184770193.git.dak%40gnu.org
In-Reply-To: <861wf5iz6o.fsf@lola.quinscape.zz>

```

This target allows you to have git installed in one location,
and have symbolic links to all of the programs installed in
another	location.  For example, if git was installed to /opt/git
with

	make prefix=/opt/git install

you can install symbolic links in /usr/local/bin with

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

This makes it reasonably easy to remove such a package, by doing

	rm -rf /opt/git

and then removing stale links with

	find /usr/local -xtype l -print0|xargs -0 rm

(be sure to first see whether you indeed get only stale links listed).

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.

Signed-off-by: David Kastrup <dak@gnu.org>
---
 Makefile |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/Makefile b/Makefile
index 73b487f..7e53378 100644
--- a/Makefile
+++ b/Makefile
@@ -142,6 +142,7 @@ ALL_LDFLAGS = $(LDFLAGS)
 STRIP ?= strip
 
 prefix = $(HOME)
+symlinkprefix = /usr/local
 bindir = $(prefix)/bin
 gitexecdir = $(bindir)
 sharedir = $(prefix)/share
@@ -996,7 +997,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) && cd '$(prefix_SQ)' && find . -type d ! \( -iname 'git*' -prune \) -exec echo $(INSTALL) -m 755 -d '$(symlinkprefix)/{}' \;
+	@cd '$(prefix_SQ)' && find . -type d ! \( -iname 'git*' -prune \) -exec $(INSTALL) -m 755 -d '$(symlinkprefix)/{}' \;
+	@: $(MAKE) && cd '$(prefix_SQ)' && find . \( -type d -iname 'git*' -prune -o ! -type d \) -exec echo $(RM) -r '$(symlinkprefix)/{}' \; -exec echo ln -s '$(prefix_SQ)/{}' '$(symlinkprefix)/{}' \;
+	@cd '$(prefix_SQ)' && find . \( -type d -iname 'git*' -prune -o ! -type d \) -exec $(RM) -r '$(symlinkprefix)/{}' \; -exec ln -s '$(prefix_SQ)/{}' '$(symlinkprefix)/{}' \;
 
 ### Maintainer's dist rules
 
-- 
1.5.3.rc2.41.gb47b1

```

## David Kastrup, 2007-07-18 12:41

Subject: Re: [PATCH] Makefile: create an install-symlinks target
Message-ID: <86y7hdkhnu.fsf@lola.quinscape.zz>
URL: https://gitlist.dev/e/86y7hdkhnu.fsf%40lola.quinscape.zz
In-Reply-To: <86bqe9lwy8.fsf@lola.quinscape.zz>

```
David Kastrup <dak@gnu.org> writes:

> Use this, for example, to do
> rm -rf /opt/git
> make prefix=/opt/git install
> make symlinkprefix=/usr/local prefix=/opt/git install-symlinks
> ---
>  Makefile |    9 ++++++++-
>  1 files changed, 8 insertions(+), 1 deletions(-)

Oh, by the way: I got _crazy_ when I first committed this, then found
a mistake and corrected it, and then repeatedly did
git add config/emacs/Makefile
git-commit --amend

and got the

>  Makefile |    9 ++++++++-
>  1 files changed, 8 insertions(+), 1 deletions(-)

message again and again, while nothing at all changed.  Of course,
this was because I added the wrong Makefile.

I am not sure how git could be more helpful here.  Just wanted to
report it.  Maybe it could have noticed that my "amendment" was empty?
On the other hand, I might have wanted to amend the commit message.
Sigh.

-- 
David Kastrup

```

## Johannes Schindelin, 2007-07-18 12:48

Subject: Re: [PATCH] Makefile: create an install-symlinks target
Message-ID: <Pine.LNX.4.64.0707181344520.14781@racer.site>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0707181344520.14781%40racer.site
In-Reply-To: <86bqe9lwy8.fsf@lola.quinscape.zz>

```
Hi,

On Wed, 18 Jul 2007, David Kastrup wrote:

> Use this, for example, to do
> rm -rf /opt/git
> make prefix=/opt/git install
> make symlinkprefix=/usr/local prefix=/opt/git install-symlinks

You mean

	This target allows you to have git installed in one location,
	and have symbolic links to all of the programs installed in 
	another	location.  For example, if git was installed to /opt/git
	with

		make prefix=/opt/git install

	you can install symbolic links in /usr/local/bin with

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

Hmm.  Why not install it with a proper package manager in the correct 
place to begin with?  Somehow I find so many symbolic links ugly.

Ciao,
Dscho

```

## Alex Riesen, 2007-07-18 13:08

Subject: Re: [PATCH] Makefile: create an install-symlinks target
Message-ID: <81b0412b0707180608j7c22631ak87f3ddd6481bccf2@mail.gmail.com>
URL: https://gitlist.dev/e/81b0412b0707180608j7c22631ak87f3ddd6481bccf2%40mail.gmail.com
In-Reply-To: <86bqe9lwy8.fsf@lola.quinscape.zz>

```
On 7/18/07, David Kastrup <dak@gnu.org> wrote:
> +       @: $(MAKE) && cd '$(prefix_SQ)' && find . -mindepth 1 ...

Sometime about now you'll need to define $(FIND) or even $(GNUFIND)
for find. There are proprietary systems where find is not available or
does not do what you want it to. There is often a gfind installed somewhere
on these systems.

```

## David Kastrup, 2007-07-18 14:06

Subject: Re: [PATCH] Makefile: create an install-symlinks target
Message-ID: <861wf5iz6o.fsf@lola.quinscape.zz>
URL: https://gitlist.dev/e/861wf5iz6o.fsf%40lola.quinscape.zz
In-Reply-To: <81b0412b0707180608j7c22631ak87f3ddd6481bccf2@mail.gmail.com>

```
"Alex Riesen" <raa.lkml@gmail.com> writes:

> On 7/18/07, David Kastrup <dak@gnu.org> wrote:
>> +       @: $(MAKE) && cd '$(prefix_SQ)' && find . -mindepth 1 ...
>
> Sometime about now you'll need to define $(FIND) or even $(GNUFIND)
> for find. There are proprietary systems where find is not available or
> does not do what you want it to. There is often a gfind installed somewhere
> on these systems.

I think that the install-symlinks target is rather more specialized
than the tags and TAGS targets, yet those use just "find".  I think
I'll be able to throw out the -mindepth, however.  It was necessary in
a version that used find $(prefix), since /opt/git matched
-type d -name git*
but with find . this should not be relevant.

I'll amend that patch and prepare a separate one that uses $(FIND)
everywhere.

-- 
David Kastrup

```

## Peter Baumann, 2007-07-18 14:33

Subject: Re: [PATCH] Makefile: create an install-symlinks target
Message-ID: <20070718143329.GD4815@xp.machine.xx>
URL: https://gitlist.dev/e/20070718143329.GD4815%40xp.machine.xx
In-Reply-To: <Pine.LNX.4.64.0707181344520.14781@racer.site>

```
On Wed, Jul 18, 2007 at 01:48:21PM +0100, Johannes Schindelin wrote:
> Hi,
> 
> On Wed, 18 Jul 2007, David Kastrup wrote:
> 
> > Use this, for example, to do
> > rm -rf /opt/git
> > make prefix=/opt/git install
> > make symlinkprefix=/usr/local prefix=/opt/git install-symlinks
> 
> You mean
> 
> 	This target allows you to have git installed in one location,
> 	and have symbolic links to all of the programs installed in 
> 	another	location.  For example, if git was installed to /opt/git
> 	with
> 
> 		make prefix=/opt/git install
> 
> 	you can install symbolic links in /usr/local/bin with
> 
> 		make symlinkprefix=/usr/local prefix=/opt/git \
> 			install-symlinks
> 
> Hmm.  Why not install it with a proper package manager in the correct 
> place to begin with?  Somehow I find so many symbolic links ugly.
> 

Seeing this excellent explantion from Dscho, this sound exactly like a
perfect use case for xstow [1].

It allows you to install your application into e.g. /usr/local/stow/git
and by running 'xstow git' in /usr/local/stow it would create all the
necessary links in /usr/local/{bin,share,doc} or any other place you
want.

-Peter

[1]: http://xstow.sourceforge.net/

```

## David Kastrup, 2007-07-18 14:45

Subject: [PATCH 2/2] Makefile: use $(FIND) instead of find
Message-ID: <e59329b96603b8ed323b57179608bb7df9b57322.1184770193.git.dak@gnu.org>
URL: https://gitlist.dev/e/e59329b96603b8ed323b57179608bb7df9b57322.1184770193.git.dak%40gnu.org
In-Reply-To: <6e14af24a3aa8af7e21e0a3f92c83c82e147202a.1184770193.git.dak@gnu.org>

```

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.

Signed-off-by: David Kastrup <dak@gnu.org>
---
 Makefile |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/Makefile b/Makefile
index 7e53378..cf72327 100644
--- a/Makefile
+++ b/Makefile
@@ -178,6 +178,7 @@ AR = ar
 RM = rm -f
 TAR = tar
 INSTALL = install
+FIND = find
 RPMBUILD = rpmbuild
 TCL_PATH = tclsh
 TCLTK_PATH = wish
@@ -904,11 +905,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)):\
@@ -1000,10 +1001,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) && cd '$(prefix_SQ)' && find . -type d ! \( -iname 'git*' -prune \) -exec echo $(INSTALL) -m 755 -d '$(symlinkprefix)/{}' \;
-	@cd '$(prefix_SQ)' && find . -type d ! \( -iname 'git*' -prune \) -exec $(INSTALL) -m 755 -d '$(symlinkprefix)/{}' \;
-	@: $(MAKE) && cd '$(prefix_SQ)' && find . \( -type d -iname 'git*' -prune -o ! -type d \) -exec echo $(RM) -r '$(symlinkprefix)/{}' \; -exec echo ln -s '$(prefix_SQ)/{}' '$(symlinkprefix)/{}' \;
-	@cd '$(prefix_SQ)' && find . \( -type d -iname 'git*' -prune -o ! -type d \) -exec $(RM) -r '$(symlinkprefix)/{}' \; -exec ln -s '$(prefix_SQ)/{}' '$(symlinkprefix)/{}' \;
+	@: $(MAKE) && cd '$(prefix_SQ)' && $(FIND) . -type d ! \( -iname 'git*' -prune \) -exec echo $(INSTALL) -m 755 -d '$(symlinkprefix)/{}' \;
+	@cd '$(prefix_SQ)' && $(FIND) . -type d ! \( -iname 'git*' -prune \) -exec $(INSTALL) -m 755 -d '$(symlinkprefix)/{}' \;
+	@: $(MAKE) && cd '$(prefix_SQ)' && $(FIND) . \( -type d -iname 'git*' -prune -o ! -type d \) -exec echo $(RM) -r '$(symlinkprefix)/{}' \; -exec echo ln -s '$(prefix_SQ)/{}' '$(symlinkprefix)/{}' \;
+	@cd '$(prefix_SQ)' && $(FIND) . \( -type d -iname 'git*' -prune -o ! -type d \) -exec $(RM) -r '$(symlinkprefix)/{}' \; -exec ln -s '$(prefix_SQ)/{}' '$(symlinkprefix)/{}' \;
 
 ### Maintainer's dist rules
 
-- 
1.5.3.rc2.41.gb47b1

```
