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