git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Makefile: Remove excess backslashes from sed

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 9, 2010, 05:57 UTC
Message-ID
<7vvdc12mmz.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1270783330-35215-1-git-send-email-brian@gernhardtsoftware.com>
Brian Gernhardt <brian@gernhardtsoftware.com> writes:
Show 14 quoted lines
> The sed script that was intended to add lines altering the sys.path
> had extra backslashes in them.  Instead resulting in
>
>   import sys;  import os;  sys.path.insert( ... )
>
> It output
>
>   import sys; \ import os; \ sys.path.insert( ... )
>
> Unfortunately this caused python (2.6.1 on OS X 10.6.3) to error
>
>   SyntaxError: unexpected character after line continuation character
>
> Removing two of the backslashes solves this problem.

Traditionally, multi-line sed statements written in the Makefile were portability nightmare, as the line folding rules (especially how the backslash is treated in the output) in make implementations were subtly different, and implementations of sed also got multi-line statement often wrong. These days, things might have gotten much better, but in olden days (back when BSD vs SysV war was still raging), the trick to write things like this portably was to invoke a shell script that has multi-line sed statement from the Makefile. It was painful.

I wonder if we can make this a lot simpler to avoid multi-line sed script. For example, we could write the source Python script to always begin with:

	#!/usr/bin/python
        import sys;
        import os;
        sys.path.insert(0, os.getenv("GITPYTHONLIB","."));
and then do something like this in the Makefile:
	INSTLIBDIR=... && \
	sed -e '1s|#!.*python|#!$(PYTHON_PATH_SQ)|' \
        -e 's|\(os\.getenv("GITPYTHONLIB"\)[^)]*)|\1,"'"$$INSTLIBDIR"'")|' \
        <$@.py >$@+
	mv $@+ $@

Contributors can then run things in-place while developing the scripts, perhaps setting GITPYTHONLIB to the source area.

Previous: Brian GernhardtNext: David Aguilar
Message 2 of 8 in “Makefile: Remove excess backslashes from sed”
  1. Makefile: Remove excess backslashes from sedBrian Gernhardt, Apr 9, 2010
  2. Junio C HamanoApr 9, 2010
  3. David AguilarApr 9, 2010
  4. Makefile: Avoid multi-line sed when building python scriptsDavid Aguilar, Apr 9, 2010
  5. Brian GernhardtApr 9, 2010
  6. Sverre RabbelierApr 9, 2010
  7. Makefile: Simplify handling of python scriptsBrian Gernhardt, Apr 9, 2010
  8. David AguilarApr 9, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.