Skip to content
This repository has been archived by the owner on Apr 9, 2018. It is now read-only.

Commit

Permalink
Unify the way GNU Make is invoked.
Browse files Browse the repository at this point in the history
  • Loading branch information
cahirwpz committed Sep 2, 2015
1 parent 3f40fcd commit 33611fc
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 121 deletions.
69 changes: 32 additions & 37 deletions common.py
Expand Up @@ -303,25 +303,30 @@ def env(**kwargs):
os.environ[key] = value


def check_stamp(fn):
@fill_in_args
def wrapper(*args, **kwargs):
name = fn.func_name.replace('_', '-')
if len(args) > 0:
name = name + "-" + str(fill_in(args[0]))
stamp = path.join('{stamps}', name)
if not path.exists('{stamps}'):
mkdir('{stamps}')
if not path.exists(stamp):
fn(*args, **kwargs)
touch(stamp)
else:
info('already done "%s"', name)

return wrapper
def recipe(name, nargs=0):
def real_decorator(fn):
@fill_in_args
def wrapper(*args, **kwargs):
target = [str(arg) for arg in args[:min(nargs, len(args))]]
if len(target) > 0:
target = [target[0], name] + target[1:]
target = '-'.join(target)
else:
target = name
target = target.replace('_', '-')
stamp = path.join('{stamps}', target)
if not path.exists('{stamps}'):
mkdir('{stamps}')
if not path.exists(stamp):
fn(*args, **kwargs)
touch(stamp)
else:
info('already done "%s"', target)
return wrapper
return real_decorator


@check_stamp
@recipe('fetch', 1)
def fetch(name, url):
if url.startswith('http') or url.startswith('ftp'):
if not path.exists(name):
Expand All @@ -344,7 +349,7 @@ def fetch(name, url):
panic('URL "%s" not recognized!', url)


@check_stamp
@recipe('unpack', 1)
def unpack(name, work_dir='{sources}', top_dir=None, dst_dir=None):
try:
src = glob(path.join('{archives}', name) + '*')[0]
Expand All @@ -367,7 +372,7 @@ def unpack(name, work_dir='{sources}', top_dir=None, dst_dir=None):
rmtree(tmpdir)


@check_stamp
@recipe('patch', 1)
def patch(name, work_dir='{sources}'):
with cwd(work_dir):
for name in find(path.join('{patches}', name),
Expand All @@ -380,7 +385,7 @@ def patch(name, work_dir='{sources}'):
copy(name, dst)


@check_stamp
@recipe('configure', 1)
def configure(name, *confopts, **kwargs):
info('configuring "%s"', name)

Expand All @@ -399,28 +404,18 @@ def configure(name, *confopts, **kwargs):
execute(path.join(from_dir, 'configure'), *confopts)


@check_stamp
def build(name, *targets, **makevars):
info('building "%s"', name)

with cwd(path.join('{build}', name)):
args = list(targets) + ['%s=%s' % item for item in makevars.items()]
execute('make', *args)


@check_stamp
def install(name, *targets, **makevars):
info('installing "%s"', name)

if not targets:
targets = ['install']
@recipe('make', 2)
def make(name, target=None, **makevars):
info('running make "%s"', target)

with cwd(path.join('{build}', name)):
args = list(targets) + ['%s=%s' % item for item in makevars.items()]
args = ['%s=%s' % item for item in makevars.items()]
if target is not None:
args = [target] + args
execute('make', *args)


__all__ = ['setvar', 'panic', 'cmpver', 'find_executable', 'chmod', 'execute',
'rmtree', 'mkdir', 'copy', 'copytree', 'unarc', 'fetch', 'cwd',
'symlink', 'remove', 'move', 'find', 'textfile', 'env', 'path',
'check_stamp', 'unpack', 'patch', 'configure', 'build', 'install']
'recipe', 'unpack', 'patch', 'configure', 'make']
32 changes: 16 additions & 16 deletions toolchain-dev
Expand Up @@ -21,7 +21,7 @@ URLS = \
from common import * # NOQA


def make():
def build():
for var in environ.keys():
if var not in ['_', 'LOGNAME', 'HOME', 'SHELL', 'TMPDIR', 'PWD']:
del environ[var]
Expand Down Expand Up @@ -59,33 +59,33 @@ def make():
configure('{gmp}',
'--disable-shared',
'--prefix={host}')
build('{gmp}')
install('{gmp}')
make('{gmp}')
make('{gmp}', 'install')

unpack('{mpfr}')
configure('{mpfr}',
'--disable-shared',
'--prefix={host}',
'--with-gmp={host}')
build('{mpfr}')
install('{mpfr}')
make('{mpfr}')
make('{mpfr}', 'install')

unpack('{mpc}')
configure('{mpc}',
'--disable-shared',
'--prefix={host}',
'--with-gmp={host}',
'--with-mpfr={host}')
build('{mpc}')
install('{mpc}')
make('{mpc}')
make('{mpc}', 'install')

unpack('{isl}')
configure('{isl}',
'--disable-shared',
'--prefix={host}',
'--with-gmp-prefix={host}')
build('{isl}')
install('{isl}')
make('{isl}')
make('{isl}', 'install')

unpack('{cloog}')
configure('{cloog}',
Expand All @@ -94,17 +94,17 @@ def make():
'--with-isl=system',
'--with-gmp-prefix={host}',
'--with-isl-prefix={host}')
build('{cloog}')
install('{cloog}')
make('{cloog}')
make('{cloog}', 'install')

with env(CFLAGS='-Wno-error'):
configure('binutils',
'--prefix={target}',
'--with-isl={host}',
'--target=m68k-elf',
from_dir='{archives}/binutils')
build('binutils')
install('binutils')
make('binutils')
make('binutils', 'install')

configure('gcc',
'--target=m68k-elf',
Expand All @@ -116,8 +116,8 @@ def make():
'--enable-languages=c',
'--without-headers',
from_dir='{archives}/gcc')
build('gcc', 'all-gcc')
install('gcc', 'install-gcc')
make('gcc', 'all-gcc')
make('gcc', 'install-gcc')


def clean():
Expand All @@ -140,7 +140,7 @@ if __name__ == "__main__":
panic('Build on %s architecture not supported!', platform.machine())

parser = argparse.ArgumentParser(description='Build cross toolchain.')
parser.add_argument('action', choices=['make', 'clean'], default='make',
parser.add_argument('action', choices=['build', 'clean'], default='build',
help='perform action')
parser.add_argument('--prefix', type=str, default=None,
help='installation directory')
Expand Down

0 comments on commit 33611fc

Please sign in to comment.