Skip to content

Commit

Permalink
Don't use sed for patching Makefile
Browse files Browse the repository at this point in the history
'-i' isn't portable, use Python instead.

Fixes #7.
  • Loading branch information
mpeterv committed Jan 3, 2016
1 parent 055dd7c commit 6dae2eb
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions hererocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,13 +481,24 @@ def set_files(self):
self.arch_file = None

def make(self):
if self.major_version == "5.1":
# Lua 5.1 doesn't support passing MYCFLAGS to Makefile.
run_command("sed -i s/MYCFLAGS/SYSCFLAGS/g src/Makefile")
substitution = "s/-Wall $(SYSCFLAGS)/-Wall $(SYSCFLAGS) $(MYCFLAGS)/g"
run_command("sed -i", quote(substitution), "src/Makefile")
cmd = "make"

if opts.cflags is not None:
if self.major_version == "5.1":
# Lua 5.1 doesn't support passing MYCFLAGS to Makefile.
makefile_h = open(os.path.join("src", "Makefile"), "rb")
makefile_src = makefile_h.read()
makefile_h.close()

before, it, after = makefile_src.partition(b"CFLAGS= -O2 -Wall $(MYCFLAGS)")
makefile_src = before + it + " " + opts.cflags + after

makefile_h = open(os.path.join("src", "Makefile"), "wb")
makefile_h.write(makefile_src)
makefile_h.close()
else:
cmd = "make MYCFLAGS=" + quote(opts.cflags)

cmd = "make" if opts.cflags is None else "make MYCFLAGS=" + quote(opts.cflags)
run_command(cmd, opts.target)

def make_install(self):
Expand Down

0 comments on commit 6dae2eb

Please sign in to comment.