Ravenports generated: 26 Nov 2019 23:39
[ravenports.git] / bucket_81 / autoselect-python
1 # Buildsheet autogenerated by ravenadm tool -- Do not edit.
2
3 NAMEBASE=               autoselect-python
4 VERSION=                1
5 REVISION=               1
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 SUB_LIST=               ALPHA=3.7
24                         BRAVO=3.6
25                         CHARLIE=2.7
26
27 post-patch:
28         @${MKDIR} ${WRKSRC}
29         ${CP} ${WRKDIR}/autoselect.c ${WRKSRC}
30
31 do-build:
32         (cd ${WRKSRC} && ${CC} ${CFLAGS} ${LDFLAGS} -o generic autoselect.c)
33
34 do-install:
35 .for prog in 2to3 idle pydoc python python-config
36         ${INSTALL_PROGRAM} ${WRKSRC}/generic  ${STAGEDIR}${PREFIX}/bin/${prog}
37 .endfor
38
39 [FILE:570:descriptions/desc.single]
40 This package provides:
41   bin/python
42   bin/python-config
43   bin/pydoc
44   bin/idle
45   bin/2to3
46
47 It automatically selects the latest version of python available.
48 For example, if python 2.7, 3.5, and 3.6 are all installed,
49 bin/python executes bin/python3.6 with the same arguments.  If
50 python 3.6 is then deinstalled, the linkage will automatically
51 adjust to python 3.5.  The python 2.7 binaries will only be
52 executed if no python 3.x packages are installed.
53
54 The priority check can be overridden by setting AUTOPYTHON=<python version>
55 in the environment, e.g. AUTOPYTHON=2.7.
56
57
58 [FILE:47:manifests/plist.single]
59 bin/
60  2to3
61  idle
62  pydoc
63  python
64  python-config
65
66
67 [FILE:742:files/LICENSE_ISC]
68 Copyright (c) 2018, The Ravenports Project.
69
70 Permission to use, copy, modify, and/or distribute this software for any
71 purpose with or without fee is hereby granted, provided that the above
72 copyright notice and this permission notice appear in all copies.
73
74 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
75 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
76 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
77 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
78 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
79 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
80 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
81
82
83 [FILE:2282:files/autoselect.c.in]
84 /*
85  * This program will determine the latest version of python
86  * installed by checking %%PREFIX%%/bin/python-<x> where <x> checks
87  * all possible versions.
88  * 
89  * If no version is present, an error message will be displayed,
90  * otherwise the versioned counterpart of the python command
91  * requested will be will be executed with the same arguments
92  * provided to this one.  If the versioned command isn't present, an
93  * error message will be provided as a fallback.
94  */
95
96 #include <stdio.h>
97 #include <stdlib.h>
98 #include <string.h>
99 #include <unistd.h>
100
101
102 int
103 main(int argc, char **argv)
104 {
105         int x;
106         char *cmd;
107         char *override;
108         char recommand[1024];
109         char *pyver    = NULL;
110         char *PYTHON_A = "%%PREFIX%%/bin/python%%ALPHA%%";
111         char *PYTHON_B = "%%PREFIX%%/bin/python%%BRAVO%%";
112         char *PYTHON_C = "%%PREFIX%%/bin/python%%CHARLIE%%";
113         char *ALPHA    = "%%ALPHA%%";
114         char *BRAVO    = "%%BRAVO%%";
115         char *CHARLIE  = "%%CHARLIE%%";
116
117         override = getenv("AUTOPYTHON");
118         if (override != NULL) {
119                 if (strcmp (override, ALPHA) == 0) {
120                         pyver = ALPHA;
121                 } else if (strcmp (override, BRAVO) == 0) {
122                         pyver = BRAVO;
123                 } else if (strcmp (override, CHARLIE) == 0) {
124                         pyver = CHARLIE;
125                 }
126         }
127         if (pyver == NULL) {
128                 if (access(PYTHON_A, F_OK) != -1) {
129                         pyver = ALPHA;
130                 } else if (access(PYTHON_B, F_OK) != -1) {
131                         pyver = BRAVO;
132                 } else if (access(PYTHON_C, F_OK) != -1) {
133                         pyver = CHARLIE;
134                 } else {
135                         /* no versions of python are installed */
136                         printf ("There are no versions of python installed at %%PREFIX%%/bin\n");
137                         exit (1);
138                 }
139         }
140
141         /*
142          * Get the last path element of the program name being executed
143          */
144         cmd = strrchr(argv[0], '/');
145         if (cmd != NULL)
146                 cmd++;
147         else
148                 cmd = argv[0];
149
150         if (strcmp (cmd, "python-config") == 0) {
151                 snprintf(recommand, 1024,
152                         "%%PREFIX%%/bin/python%s-config", pyver);
153         } else if (strcmp (cmd, "2to3") == 0) {
154                 snprintf(recommand, 1024,
155                         "%%PREFIX%%/bin/2to3-", pyver);
156         } else {
157                 snprintf(recommand, 1024,
158                         "%%PREFIX%%/bin/%s%s", cmd, pyver);
159         }
160         argv[0] = recommand;
161         execv(recommand, argv);
162
163         /*
164          * Execution failed, so write out an error message
165          */
166         printf ("Command execution failed: %s\n", recommand);
167         printf ("               arguments:");
168         for (x = 1; x < argc; x++)
169                 printf (" %s", argv[x]);
170         printf ("\n");
171         exit (1);
172 }
173