1 |
Greetings, |
2 |
I am a bit of a newbie. I installed Gentoo a couple of weeks ago. |
3 |
My kids complained that all their favorite games were missing and |
4 |
didn't seem too impressed when I tried to explain the advantages of |
5 |
portage. They are 7 and 3. So I set about installing all the |
6 |
interesting games I could find on freshmeat, tucows, linuxforkids, |
7 |
etc. At first I was doing this from tarballs. Then I told myself |
8 |
this is stupid and I started writing ebuilds, using /usr/portage/skel.build |
9 |
and existing ebuilds as a base. Then I told myself even that is stupid |
10 |
and I wrote a shell script to take the URL of the tarball, fetch it, |
11 |
unpack it, poke around a bit, and produce a first guess at an ebuild. |
12 |
For fairly simple packages it produces something decent most of the |
13 |
time. I think that with a little work it could be quite useful. |
14 |
My first priority is to make it handle packages with more than |
15 |
one source file. Other suggestions are welcome. For what it's |
16 |
worth here it is: (excuse the inelegance of the implementation; |
17 |
I am a mathematician, not a programmer.) |
18 |
|
19 |
#!/bin/bash |
20 |
CONFIG_FILE=${HOME}/.mkebuild |
21 |
if [ -e $CONFIG_FILE ] |
22 |
then |
23 |
source $CONFIG_FILE |
24 |
else |
25 |
echo This appears to be the first time you have used mkebuild. |
26 |
echo I am going to make some guesses. If any of these are wrong |
27 |
echo you should edit the file ${CONFIG_FILE}. |
28 |
echo |
29 |
MY_NAME=`awk -F":" '/^'${USER}:'/ { print $5 }' /etc/passwd` |
30 |
echo Your name is ${MY_NAME}. |
31 |
echo 'MY_NAME="'${MY_NAME}'"' >${CONFIG_FILE} |
32 |
COPYRIGHT="Gentoo Technologies, Inc." |
33 |
echo You wish to asign copyright to ${COPYRIGHT} |
34 |
echo 'COPYRIGHT="'${COPYRIGHT}'"' >>${CONFIG_FILE} |
35 |
MY_EMAIL=${USER}"@"${HOSTNAME} |
36 |
echo Your email address is ${MY_EMAIL}. |
37 |
echo 'MY_EMAIL='${MY_EMAIL} >>$CONFIG_FILE |
38 |
LICENSE="the GNU General Public License, v2 or later" |
39 |
echo Your preferred license is ${LICENSE}. |
40 |
echo 'LICENSE="'${LICENSE}'"' >>${CONFIG_FILE} |
41 |
LOCAL_SOURCE=${HOME} |
42 |
echo You download sources to ${LOCAL_SOURCE}. |
43 |
echo LOCAL_SOURCE=${LOCAL_SOURCE} >>${CONFIG_FILE} |
44 |
BUILD_DIRECTORY=${HOME} |
45 |
echo You build packages in ${BUILD_DIRECTORY}. |
46 |
echo 'BUILD_DIRECTORY='${BUILD_DIRECTORY} >>${CONFIG_FILE} |
47 |
echo |
48 |
fi |
49 |
FILE_NAME=`basename $1` |
50 |
SOURCE_LOCATION=`dirname $1` |
51 |
PACKAGE_NAME=${FILE_NAME%.*} |
52 |
FILE_EXTENSION=${FILE_NAME##*.} |
53 |
if [ "${PACKAGE_NAME##*.}" = "tar" ] |
54 |
then |
55 |
FILE_EXTENSION=tar.${FILE_EXTENSION} |
56 |
PACKAGE_NAME=${PACKAGE_NAME%.tar} |
57 |
fi |
58 |
EBUILD_FILE=${PWD}/${PACKAGE_NAME}.ebuild |
59 |
echo "#Copyright" `date +"%Y"` ${COPYRIGHT} >${EBUILD_FILE} |
60 |
echo "#Distributed under the terms of" ${LICENSE} >>${EBUILD_FILE} |
61 |
echo "#Author" ${MY_NAME} '<'${MY_EMAIL}'>' >>${EBUILD_FILE} |
62 |
echo >>${EBUILD_FILE} |
63 |
echo 'A=${P}.'${FILE_EXTENSION} >>${EBUILD_FILE} |
64 |
echo 'S=${WORKDIR}/${P}' >>${EBUILD_FILE} |
65 |
echo 'DESCRIPTION=""' >>${EBUILD_FILE} |
66 |
echo 'SRC_URI="'${SOURCE_LOCATION}'/${P}.'${FILE_EXTENSION}'"' >>${EBUILD_FILE} |
67 |
echo 'HOMEPAGE="'${SOURCE_LOCATION}'/"' >>${EBUILD_FILE} |
68 |
echo >>${EBUILD_FILE} |
69 |
echo 'DEPEND=""' >>${EBUILD_FILE} |
70 |
echo >>${EBUILD_FILE} |
71 |
echo 'RDEPEND=$DEPEND' >>${EBUILD_FILE} |
72 |
echo >>${EBUILD_FILE} |
73 |
echo 'src_unpack() {' >>${EBUILD_FILE} |
74 |
echo >>${EBUILD_FILE} |
75 |
echo -e "\t"'unpack ${P}.'${FILE_EXTENSION} >>${EBUILD_FILE} |
76 |
echo -e "\t"'cd ${S}' >>${EBUILD_FILE} |
77 |
echo >>${EBUILD_FILE} |
78 |
echo '}' >>${EBUILD_FILE} |
79 |
if [ -e ${LOCAL_SOURCE}/${FILE_NAME} ] |
80 |
then |
81 |
echo I am assuming that $1 really |
82 |
echo exists and that ${LOCAL_SOURCE}/${FILE_NAME} |
83 |
echo is a faithful copy. |
84 |
else |
85 |
echo I didn\'t find ${LOCAL_SOURCE}/${FILE_NAME} so I will fetch |
86 |
echo $1. |
87 |
cd ${LOCAL_SOURCE} |
88 |
wget $1 |
89 |
fi |
90 |
if [ -e ${BUILD_DIRECTORY}/${PACKAGE_NAME} ] |
91 |
then |
92 |
echo |
93 |
echo I am assuming that ${BUILD_DIRECTORY}/${PACKAGE_NAME} \ |
94 |
is the unpacked |
95 |
echo version of ${LOCAL_SOURCE}/${FILE_NAME}. |
96 |
else |
97 |
cd ${BUILD_DIRECTORY} |
98 |
if [ $? -ne 0 ] |
99 |
then |
100 |
echo |
101 |
echo I was unable to enter the directory ${BUILD_DIRECTORY}. |
102 |
exit 1 |
103 |
fi |
104 |
case "${FILE_EXTENSION}" in |
105 |
tar.gz|tgz) |
106 |
tar xzf ${LOCAL_SOURCE}/${FILE_NAME} |
107 |
;; |
108 |
tar.bz2|tbz2) |
109 |
tar xjf ${LOCAL_SOURCE}/${FILE_NAME} |
110 |
;; |
111 |
tar.Z|tar.z) |
112 |
unzip ${LOCAL_SOURCE}/${FILE_NAME} |
113 |
tar xf ${PACKAGE_NAME}.tar |
114 |
;; |
115 |
*) |
116 |
echo |
117 |
echo I can\'t figure out how to uncompress |
118 |
echo ${LOCAL_SOURCE}/${FILE_NAME} |
119 |
exit 1 |
120 |
esac |
121 |
if [ $? -ne 0 ] |
122 |
then |
123 |
echo |
124 |
echo I was unable to uncompress ${LOCAL_SOURCE}/${FILE_NAME}. |
125 |
exit 1 |
126 |
fi |
127 |
fi |
128 |
cd ${BUILD_DIRECTORY}/${PACKAGE_NAME} |
129 |
if [ $? -ne 0 ] |
130 |
then |
131 |
echo |
132 |
echo I could not change directory to ${BUILD_DIRECTORY}/${PACKAGE_NAME} |
133 |
exit 1 |
134 |
fi |
135 |
echo |
136 |
echo You might want to look at the following files for configuration and |
137 |
echo dependency information: |
138 |
find ${PWD} -name README -print |
139 |
find ${PWD} -name README.txt -print |
140 |
find ${PWD} -name INSTALL -print |
141 |
find ${PWD} -name INSTALL.txt -print |
142 |
find ${PWD} -name Changes -print |
143 |
find ${PWD} -name CHANGES.txt -print |
144 |
find ${PWD} -name FAQ.txt |
145 |
find ${PWD} -name ChangeLog -print |
146 |
find ${PWD} -name NEWS -print |
147 |
echo >>${EBUILD_FILE} |
148 |
echo 'src_compile() {' >>${EBUILD_FILE} |
149 |
echo >>${EBUILD_FILE} |
150 |
echo |
151 |
if [ -e Imakefile ] |
152 |
then |
153 |
echo I found an Imakefile. I am assuming that we should use xmkmf. |
154 |
echo I don\'t really understand xmkmf so you will have to configure |
155 |
echo things on your own. |
156 |
echo |
157 |
echo -e "\t"'xmkmf || die' >>${EBUILD_FILE} |
158 |
echo -e "\tmake Makefiles" >>${EBUILD_FILE} |
159 |
echo -e "\tmake includes" >>${EBUILD_FILE} |
160 |
echo -e "\tmake depend" >>${EBUILD_FILES} |
161 |
elif [ -e configure ] |
162 |
then |
163 |
echo I found a configure file. I am assuming that we are using autoconf |
164 |
. |
165 |
echo I will take care of setting the most commonly used options. I am |
166 |
echo including a list of all the available options to confiigure, commen |
167 |
ted |
168 |
echo out. You might want to look it over to see if I have missed anythi |
169 |
ng. |
170 |
echo |
171 |
./configure --help >.config.options |
172 |
echo -e "\t./configure \\" >>${EBUILD_FILE} |
173 |
awk '/--prefix/ { print "\t\t--prefix=/usr \\"}' \ |
174 |
.config.options >>${EBUILD_FILE} |
175 |
awk '/--infodir/ { print "\t\t--infodir=/usr/share/info \\"}' \ |
176 |
.config.options >>${EBUILD_FILE} |
177 |
awk '/--mandir/ { print "\t\t--mandir=/usr/share/man \\"}' \ |
178 |
.config.options >>${EBUILD_FILE} |
179 |
echo -e "\t\t"'|| die "./configure failed"' >>${EBUILD_FILE} |
180 |
echo -e "#\tAvailable options to configure:" >>${EBUILD_FILE} |
181 |
awk '/--/ { print "#" $0 }' .config.options >>${EBUILD_FILE} |
182 |
echo -e "\t"'emake || die' >>${EBUILD_FILE} |
183 |
elif [ -e Makefile ] |
184 |
then |
185 |
echo I found a Makefile. You should look at it and possibly prepare |
186 |
echo a patch. |
187 |
echo |
188 |
echo -e "\temake || die" >>${EBUILD_FILE} |
189 |
else |
190 |
echo I couldn\'t find a Imakefile, configure script, or Makefile for |
191 |
echo this package. You will have to figure out what to do on your |
192 |
echo own. |
193 |
echo |
194 |
fi |
195 |
echo '}' >>${EBUILD_FILE} |
196 |
echo >>${EBUILD_FILE} |
197 |
echo 'src_install () {' >>${EBUILD_FILE} |
198 |
echo >>${EBUILD_FILE} |
199 |
echo -e "\t"'make DESTDIR=${D} install || die' >>${EBUILD_FILE} |
200 |
echo '}' >>${EBUILD_FILE} |
201 |
echo >>${EBUILD_FILE} |
202 |
echo >>${EBUILD_FILE} |
203 |
echo >>${EBUILD_FILE} |
204 |
echo I couldn\'t supply a package description for the ebuild file |
205 |
echo because I don\'t know what ${PACKAGE_NAME} does. |
206 |
echo |
207 |
echo I am assume the hompage for this package is ${SOURCE_LOCATION}/. |
208 |
echo If that is not correct you will need to edit that portion of |
209 |
echo the ebuild file as well. |
210 |
echo |
211 |
echo I don\'t understand dependencies yet. You will have to add any |
212 |
echo dependencies you know of by hand. Then try your ebuild script |
213 |
echo out to see if there are any dependencies you don\'t know of. |
214 |
echo |
215 |
echo I am assuming that this package comes with a well-behaved Makefile |
216 |
echo which does not install anything outside of '${DESTDIR}'. You will |
217 |
echo need to check this by looking at the portion of the Makefile |
218 |
echo beginning with the line '"install:"'. |
219 |
|
220 |
|
221 |
-- |
222 |
John Stalker |
223 |
Department of Mathematics |
224 |
Princeton University |
225 |
(609)258-6469 |