Jump to content
  • 0
Sign in to follow this  
jorgicio

gcc in Funtoo Portage with toolchain?

Question

Am I dreaming or too beautiful for being reality? I noticed some Funtoo gcc ebuilds now come with toolchain included (not all ebuilds, of course)

 

If so, well... thanks!

 

EDIT: Crap... they were removed and remained only the Funtoo ebuilds without toolchain <.<

Share this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Anyways, I wrote this Python code for doing that for me:

#!/usr/bin/env python
import sys,re,os,urllib2,urllib,urlparse
# linkregex = re.compile('<a\s*href=[\'|"](.*?)[\'"].*?')
linkregex = re.compile('href=[\'|"](.*?)[\'"].*?')
linksrc = re.compile('src=[\'|"](.*?)[\'"].*?')
def download(url):
    link_list = []##create a list of all found links so there are no duplicates
    restrict = url ##used to restrict found links to only have lower level
    tocrawl = set([url])
    link_list.append(restrict)
    parent_folder = restrict.rfind('/', 0, len(restrict)-1)
    ##a.com/b/c/d/ make /d/ as parent folder
    while 1:
        try:
            crawling = tocrawl.pop()
            #print crawling
        except KeyError:
            break
        url = urlparse.urlparse(crawling)##splits url into sections
        try:
            response = urllib2.urlopen(crawling)##try to open the url
        except:
            continue
        msg = response.read()##save source of url
        links = linkregex.findall(msg)##search for all href in source
        links = links + linksrc.findall(msg)##search for all src in source
        for link in (links.pop(0) for _ in xrange(len(links))):
            if link.startswith('/'):
                ##if /xxx a.com/b/c/ -> a.com/b/c/xxx
                link = 'http://' + url[1] + link
            elif ~link.find('#'):
                continue
            elif link.startswith('../'):
                if link.find('../../'):##only use links that are max 1 level above reference
                    ##if ../xxx.html a.com/b/c/d.html -> a.com/b/xxx.html
                    parent_pos = url[2].rfind('/')
                    parent_pos = url[2].rfind('/', 0, parent_pos-2) + 1
                    parent_url = url[2][:parent_pos]
                    new_link = link.find('/')+1
                    link = link[new_link:]
                    link = 'http://' + url[1] + parent_url + link
                else:
                    continue
            elif not link.startswith('http'):
                if url[2].find('.html'):
                    ##if xxx.html a.com/b/c/d.html -> a.com/b/c/xxx.html
                    a = url[2].rfind('/')+1
                    parent = url[2][:a]
                    link = 'http://' + url[1] + parent + link
                else:
                    ##if xxx.html a.com/b/c/ -> a.com/b/c/xxx.html
                    link = 'http://' + url[1] + url[2] + link
            if link not in link_list:
                link_list.append(link)##add link to list of already found links
                if (~link.find(restrict)):
                ##only grab links which are below input site
                    print link ##print downloaded link
                    tocrawl.add(link)##add link to pending view links
                    file_name = link[parent_folder+1:]##folder structure for files to be saved
                    filename = file_name.rfind('/')
                    folder = file_name[:filename]##creates folder names
                    folder = os.path.abspath(folder)##creates folder path
                    if not os.path.exists(folder):
                        os.makedirs(folder)##make folder if it does not exist
                    try:
                        urllib.urlretrieve(link, file_name)##download the link
                    except:
                        print "could not download %s"%link
                else:
                    continue



url_gcc = "http://data.gpo.zugaina.org/gentoo/sys-devel/gcc/"
local_portage = "/usr/local/portage"
gcc_local = local_portage+"/sys-devel"
gcc_avr = local_portage+"/cross-avr/gcc"
regexp = re.compile(r'^\?')
overlay = "local"

import shutil
def clean_files(direc):
    for root, dirs, files in os.walk(direc):
        for dname in dirs:
            directorio = os.path.join(root,dname)
            dcompile = regexp.search(dname)
            if dcompile is not None:
                shutil.rmtree(directorio)

        for fname in files:
            archivo = os.path.join(root,fname)
            fcompile = regexp.search(fname)
            if fcompile is not None:
                os.remove(archivo)

def install_gcc_avr(direc):
    clean_files(direc)
    if os.path.exists(gcc_local):
        shutil.rmtree(gcc_local)
    os.mkdir(gcc_local)
    gcc_local_final = gcc_local+"/gcc"
    shutil.copytree(direc,gcc_local_final)
    if os.path.lexists(gcc_avr):
        os.remove(gcc_avr)
    os.symlink(gcc_local_final,gcc_avr)

def find_line(f_gcc,linea):
    flag = False
    with open(f_gcc) as archivo:
        for l in archivo:
            l = l.rstrip()
            if l == linea:
                flag = True
        archivo.close()
    return flag

def append_to_file_gcc(f_gcc,linea):
    with open(f_gcc,'rU+') as archivo:
        archivo.seek(-2,2)
        if(archivo.read(2) == "\n\n"):
            f.seek(-1,2)
        archivo.write(linea)
        archivo.write("\n")
        archivo.close()

def mask_gcc_local():
    file_gcc_mask = "/etc/portage/package.mask"
    dir_gcc_mask = file_gcc_mask+"/mask"
    linea = "sys-devel/gcc::"+overlay
    if os.path.exists(file_gcc_mask) and os.path.isdir(file_gcc_mask):
        if os.path.exists(dir_gcc_mask):
            if not find_line(dir_gcc_mask,linea):
                append_to_file_gcc(dir_gcc_mask,linea)
        else:
            archivo = open(dir_gcc_mask,'w')
            archivo.write(linea)
            archivo.close()
    elif os.path.exists(file_gcc_mask) and os.path.isfile(file_gcc_mask):
        if not find_line(file_gcc_mask,linea):
            append_to_file_gcc(file_gcc_mask,linea)
    else:
        archivo = open(file_gcc_mask,'w')
        archivo.write(linea)
        archivo.close()

dir_res = re.split("/",url_gcc)
dir_res = dir_res[-2]
print "Downloading from %s" % url_gcc
download(url_gcc)
print "Now installing %s in %s" % (dir_res,gcc_local)
install_gcc_avr(dir_res)
print "Cleaning..."
shutil.rmtree(dir_res)
print "Now masking the local %s" % dir_res
mask_gcc_local()
print "Success!"

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...