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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Brian Gernhardt <brian@xxxxxxxxxxxxxxxxxxxxx> writes:

> 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.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]