1 # Buildsheet autogenerated by ravenadm tool -- Do not edit.
3 NAMEBASE= autoselect-python
8 SDESC[standard]= Dynamic links to the latest installed python
13 SPKGS[standard]= single
15 OPTIONS_AVAILABLE= none
16 OPTIONS_STANDARD= none
19 LICENSE_FILE= ISCL:{{FILESDIR}}/LICENSE_ISC
22 SUB_FILES= autoselect.c
29 ${CP} ${WRKDIR}/autoselect.c ${WRKSRC}
32 (cd ${WRKSRC} && ${CC} ${CFLAGS} ${LDFLAGS} -o generic autoselect.c)
35 .for prog in 2to3 idle pydoc python python-config
36 ${INSTALL_PROGRAM} ${WRKSRC}/generic ${STAGEDIR}${PREFIX}/bin/${prog}
39 [FILE:570:descriptions/desc.single]
40 This package provides:
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.
54 The priority check can be overridden by setting AUTOPYTHON=<python version>
55 in the environment, e.g. AUTOPYTHON=2.7.
58 [FILE:47:manifests/plist.single]
67 [FILE:742:files/LICENSE_ISC]
68 Copyright (c) 2018, The Ravenports Project.
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.
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.
83 [FILE:2282:files/autoselect.c.in]
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.
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.
103 main(int argc, char **argv)
108 char recommand[1024];
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%%";
117 override = getenv("AUTOPYTHON");
118 if (override != NULL) {
119 if (strcmp (override, ALPHA) == 0) {
121 } else if (strcmp (override, BRAVO) == 0) {
123 } else if (strcmp (override, CHARLIE) == 0) {
128 if (access(PYTHON_A, F_OK) != -1) {
130 } else if (access(PYTHON_B, F_OK) != -1) {
132 } else if (access(PYTHON_C, F_OK) != -1) {
135 /* no versions of python are installed */
136 printf ("There are no versions of python installed at %%PREFIX%%/bin\n");
142 * Get the last path element of the program name being executed
144 cmd = strrchr(argv[0], '/');
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);
157 snprintf(recommand, 1024,
158 "%%PREFIX%%/bin/%s%s", cmd, pyver);
161 execv(recommand, argv);
164 * Execution failed, so write out an error message
166 printf ("Command execution failed: %s\n", recommand);
167 printf (" arguments:");
168 for (x = 1; x < argc; x++)
169 printf (" %s", argv[x]);