1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
from time import strftime
from subprocess import getstatusoutput
eclass = {
"git" : "git",
"svn" : "subversion",
"hg" : "mercurial",
}
arch = getstatusoutput("portageq envvar ARCH")[1]
def genebuild(iuse,deps,usedeps,dltype,adress,targets,binaries):
"""This function starts the ebuild generation.
You have to provide the following args in order:
iuse, a list of useflags
deps, a list of dependecies
dltype, how to download the source code (wget,GIT,etc)
adress, Adress to the source code
targets, a list of build targets for the project (used to guess install method)
binaries, a list of binaries that is created during compile (used to install them if there is no 'make install')
"""
installmethod = guessinstall(targets,binaries)
outstr = outputebuild(iuse,deps,usedeps,dltype,adress,installmethod)
f = open("/tmp/workfile.ebuild","w")
f.write(outstr)
f.close()
def guessinstall(targets,binaries):
"""Guess the install method of the project
Looks at the make targets for a 'make install'
if that fails just install the binaries
"""
targetlst = []
returnlst = []
for target in targets:
targetlst.append(target[0])
if "install" in targetlst:
returnlst = [' emake DESTDIR="${D}" install || die "emake install failed"']
else:
for binary in binaries:
returnlst += [' dobin ' + binary + ' || die "bin install failed"']
return returnlst
def outputebuild(iuse,deps,usedeps,dltype,adress,installmethod):
"""Used to generate the text for the ebuild to output
Generates text with the help of the supplied variables
"""
text = [
'# Copyright 1999-' + strftime("%Y") + ' Gentoo Foundation',
'# Distributed under the terms of the GNU General Public License v2',
'# $Header: $',
''
]
inheritstr = 'inherit ' + eclass[dltype] + ' autotools'
text.append(inheritstr)
text += [
'',
'EAPI=3',
'',
'DESCRIPTION=""',
'HOMEPAGE=""'
]
if dltype == "www":
srcstr = 'SRC_URI="' + adress + '"'
else:
srcstr = 'E' + dltype.upper() + '_REPO_URI="' + adress + '"'
text.append(srcstr)
text += [
'',
'LICENSE=""',
'SLOT="0"',
'KEYWORDS="~' + arch + '"'
]
iusestr = 'IUSE="'
for flag in iuse:
iusestr += (flag.split("_")[1] + " ")
iusestr += '"\n'
text.append(iusestr)
depstr = 'DEPEND="'
for dep in deps:
depstr += (dep + "\n\t")
for use in usedeps:
#check if packagelist is empty
if usedeps[use]:
if use[0] == "!":
depstr += "!" + use.split("_")[1] + "? ( "
else:
depstr += use.split("_")[1] + "? ( "
for dep in usedeps[use]:
depstr += dep +"\n\t\t"
depstr = depstr[:-3]
depstr += " )\n\t"
depstr = depstr[:-2] + '"\nRDEPEND="${DEPEND}"'
text.append(depstr)
text += [
'',
'src_prepare() {',
'\teautoreconf',
'}',
]
if iuse:
text += [
'',
'src_configure() {',
'\teconf \\',
]
for use in iuse:
text += ['\t\t$(use_' + use.split("_")[0] + ' ' + use.split("_")[1] + ') \\']
#add \n here because the ebuild will fail if there is no extra newline between '\' and '}'
text += ['\n}']
text += [
'',
'src_compile() {',
' emake || die "emake failed"',
'}'
]
text += [
'',
'src_install() {',
]
text += installmethod
text += ['}']
outputstr = ""
for line in text:
outputstr += line + "\n"
return outputstr
|