Ravenports generated: 21 Nov 2021 04:14
[ravenports.git] / bucket_81 / autoselect-python
1 # Buildsheet autogenerated by ravenadm tool -- Do not edit.
2
3 NAMEBASE=               autoselect-python
4 VERSION=                3
5 KEYWORDS=               lang
6 VARIANTS=               standard
7 SDESC[standard]=        Dynamic links to the latest installed python
8 HOMEPAGE=               none
9 CONTACT=                nobody
10
11 DOWNLOAD_GROUPS=        none
12 SPKGS[standard]=        single
13
14 OPTIONS_AVAILABLE=      none
15 OPTIONS_STANDARD=       none
16
17 LICENSE=                ISCL:single
18 LICENSE_FILE=           ISCL:{{FILESDIR}}/LICENSE_ISC
19 LICENSE_SCHEME=         solo
20
21 SUB_FILES=              autoselect.c
22                         only3.c
23 SUB_LIST=               ALPHA=3.9
24                         BRAVO=3.10
25                         CHARLIE=2.7
26
27 post-patch:
28         ${MKDIR} ${WRKSRC}
29         ${CP} ${WRKDIR}/*.c ${WRKSRC}
30
31 do-build:
32         (cd ${WRKSRC} && ${CC} ${CFLAGS} ${LDFLAGS} -o generic autoselect.c)
33         (cd ${WRKSRC} && ${CC} ${CFLAGS} ${LDFLAGS} -o only3   only3.c)
34
35 do-install:
36 .for prog in 2to3 idle pydoc python python-config
37         ${INSTALL_PROGRAM} ${WRKSRC}/generic  ${STAGEDIR}${PREFIX}/bin/${prog}
38 .endfor
39 .for prog in python3 python-config3
40         ${INSTALL_PROGRAM} ${WRKSRC}/only3 ${STAGEDIR}${PREFIX}/bin/${prog}
41 .endfor
42
43 [FILE:570:descriptions/desc.single]
44 This package provides:
45   bin/python
46   bin/python-config
47   bin/pydoc
48   bin/idle
49   bin/2to3
50
51 It automatically selects the latest version of python available.
52 For example, if python 2.7, 3.5, and 3.6 are all installed,
53 bin/python executes bin/python3.6 with the same arguments.  If
54 python 3.6 is then deinstalled, the linkage will automatically
55 adjust to python 3.5.  The python 2.7 binaries will only be
56 executed if no python 3.x packages are installed.
57
58 The priority check can be overridden by setting AUTOPYTHON=<python version>
59 in the environment, e.g. AUTOPYTHON=2.7.
60
61
62 [FILE:72:manifests/plist.single]
63 bin/
64  2to3
65  idle
66  pydoc
67  python
68  python-config
69  python-config3
70  python3
71
72
73 [FILE:742:files/LICENSE_ISC]
74 Copyright (c) 2018, The Ravenports Project.
75
76 Permission to use, copy, modify, and/or distribute this software for any
77 purpose with or without fee is hereby granted, provided that the above
78 copyright notice and this permission notice appear in all copies.
79
80 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
81 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
82 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
83 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
84 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
85 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
86 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
87
88
89 [FILE:2282:files/autoselect.c.in]
90 /*
91  * This program will determine the latest version of python
92  * installed by checking %%PREFIX%%/bin/python-<x> where <x> checks
93  * all possible versions.
94  * 
95  * If no version is present, an error message will be displayed,
96  * otherwise the versioned counterpart of the python command
97  * requested will be will be executed with the same arguments
98  * provided to this one.  If the versioned command isn't present, an
99  * error message will be provided as a fallback.
100  */
101
102 #include <stdio.h>
103 #include <stdlib.h>
104 #include <string.h>
105 #include <unistd.h>
106
107
108 int
109 main(int argc, char **argv)
110 {
111         int x;
112         char *cmd;
113         char *override;
114         char recommand[1024];
115         char *pyver    = NULL;
116         char *PYTHON_A = "%%PREFIX%%/bin/python%%ALPHA%%";
117         char *PYTHON_B = "%%PREFIX%%/bin/python%%BRAVO%%";
118         char *PYTHON_C = "%%PREFIX%%/bin/python%%CHARLIE%%";
119         char *ALPHA    = "%%ALPHA%%";
120         char *BRAVO    = "%%BRAVO%%";
121         char *CHARLIE  = "%%CHARLIE%%";
122
123         override = getenv("AUTOPYTHON");
124         if (override != NULL) {
125                 if (strcmp (override, ALPHA) == 0) {
126                         pyver = ALPHA;
127                 } else if (strcmp (override, BRAVO) == 0) {
128                         pyver = BRAVO;
129                 } else if (strcmp (override, CHARLIE) == 0) {
130                         pyver = CHARLIE;
131                 }
132         }
133         if (pyver == NULL) {
134                 if (access(PYTHON_A, F_OK) != -1) {
135                         pyver = ALPHA;
136                 } else if (access(PYTHON_B, F_OK) != -1) {
137                         pyver = BRAVO;
138                 } else if (access(PYTHON_C, F_OK) != -1) {
139                         pyver = CHARLIE;
140                 } else {
141                         /* no versions of python are installed */
142                         printf ("There are no versions of python installed at %%PREFIX%%/bin\n");
143                         exit (1);
144                 }
145         }
146
147         /*
148          * Get the last path element of the program name being executed
149          */
150         cmd = strrchr(argv[0], '/');
151         if (cmd != NULL)
152                 cmd++;
153         else
154                 cmd = argv[0];
155
156         if (strcmp (cmd, "python-config") == 0) {
157                 snprintf(recommand, 1024,
158                         "%%PREFIX%%/bin/python%s-config", pyver);
159         } else if (strcmp (cmd, "2to3") == 0) {
160                 snprintf(recommand, 1024,
161                         "%%PREFIX%%/bin/2to3-", pyver);
162         } else {
163                 snprintf(recommand, 1024,
164                         "%%PREFIX%%/bin/%s%s", cmd, pyver);
165         }
166         argv[0] = recommand;
167         execv(recommand, argv);
168
169         /*
170          * Execution failed, so write out an error message
171          */
172         printf ("Command execution failed: %s\n", recommand);
173         printf ("               arguments:");
174         for (x = 1; x < argc; x++)
175                 printf (" %s", argv[x]);
176         printf ("\n");
177         exit (1);
178 }
179
180
181 [FILE:2086:files/only3.c.in]
182 /*
183  * This program will determine the latest version of python
184  * installed by checking %%PREFIX%%/bin/python-<x> where <x> checks
185  * all possible versions of python 3.
186  * 
187  * If no version is present, an error message will be displayed,
188  * otherwise the versioned counterpart of the python command
189  * requested will be will be executed with the same arguments
190  * provided to this one.  If the versioned command isn't present, an
191  * error message will be provided as a fallback.
192  */
193
194 #include <stdio.h>
195 #include <stdlib.h>
196 #include <string.h>
197 #include <unistd.h>
198
199
200 int
201 main(int argc, char **argv)
202 {
203         int x;
204         char *cmd;
205         char *override;
206         char recommand[1024];
207         char *pyver    = NULL;
208         char *PYTHON_A = "%%PREFIX%%/bin/python%%ALPHA%%";
209         char *PYTHON_B = "%%PREFIX%%/bin/python%%BRAVO%%";
210         char *ALPHA    = "%%ALPHA%%";
211         char *BRAVO    = "%%BRAVO%%";
212
213         override = getenv("AUTOPYTHON");
214         if (override != NULL) {
215                 if (strcmp (override, ALPHA) == 0) {
216                         pyver = ALPHA;
217                 } else if (strcmp (override, BRAVO) == 0) {
218                         pyver = BRAVO;
219                 }
220         }
221         if (pyver == NULL) {
222                 if (access(PYTHON_A, F_OK) != -1) {
223                         pyver = ALPHA;
224                 } else if (access(PYTHON_B, F_OK) != -1) {
225                         pyver = BRAVO;
226                 } else {
227                         /* no versions of python 3 are installed */
228                         printf ("There are no versions of python 3 installed at %%PREFIX%%/bin\n");
229                         exit (1);
230                 }
231         }
232
233         /*
234          * Get the last path element of the program name being executed
235          */
236         cmd = strrchr(argv[0], '/');
237         if (cmd != NULL)
238                 cmd++;
239         else
240                 cmd = argv[0];
241
242         if (strcmp (cmd, "python-config3") == 0) {
243                 snprintf(recommand, 1024,
244                         "%%PREFIX%%/bin/python%s-config", pyver);
245         } else if (strcmp (cmd, "python3") == 0) {
246                 snprintf(recommand, 1024,
247                         "%%PREFIX%%/bin/python%s", pyver);
248         } else {
249                 printf ("only3 doesn't handle this file: %s\n", cmd);
250                 exit (1);
251         }
252         argv[0] = recommand;
253         execv(recommand, argv);
254
255         /*
256          * Execution failed, so write out an error message
257          */
258         printf ("Command execution failed: %s\n", recommand);
259         printf ("               arguments:");
260         for (x = 1; x < argc; x++)
261                 printf (" %s", argv[x]);
262         printf ("\n");
263         exit (1);
264 }
265