1 # Buildsheet autogenerated by ravenadm tool -- Do not edit.
3 NAMEBASE= autoselect-python
7 SDESC[standard]= Dynamic links to the latest installed python
12 SPKGS[standard]= single
14 OPTIONS_AVAILABLE= none
15 OPTIONS_STANDARD= none
18 LICENSE_FILE= ISCL:{{FILESDIR}}/LICENSE_ISC
21 SUB_FILES= autoselect.c
28 ${CP} ${WRKDIR}/autoselect.c ${WRKSRC}
31 (cd ${WRKSRC} && ${CC} ${CFLAGS} ${LDFLAGS} -o generic autoselect.c)
34 .for prog in 2to3 idle pydoc python python-config
35 ${INSTALL_PROGRAM} ${WRKSRC}/generic ${STAGEDIR}${PREFIX}/bin/${prog}
38 [FILE:570:descriptions/desc.single]
39 This package provides:
46 It automatically selects the latest version of python available.
47 For example, if python 2.7, 3.5, and 3.6 are all installed,
48 bin/python executes bin/python3.6 with the same arguments. If
49 python 3.6 is then deinstalled, the linkage will automatically
50 adjust to python 3.5. The python 2.7 binaries will only be
51 executed if no python 3.x packages are installed.
53 The priority check can be overridden by setting AUTOPYTHON=<python version>
54 in the environment, e.g. AUTOPYTHON=2.7.
57 [FILE:47:manifests/plist.single]
66 [FILE:742:files/LICENSE_ISC]
67 Copyright (c) 2018, The Ravenports Project.
69 Permission to use, copy, modify, and/or distribute this software for any
70 purpose with or without fee is hereby granted, provided that the above
71 copyright notice and this permission notice appear in all copies.
73 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
74 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
75 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
76 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
77 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
78 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
79 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
82 [FILE:2280:files/autoselect.c.in]
84 * This program will determine the latest version of python
85 * installed by checking %%PREFIX%%/bin/python-<x> where <x> checks
86 * all possible versions.
88 * If no version is present, an error message will be displayed,
89 * otherwise the versioned counterpart of the python command
90 * requested will be will be executed with the same arguments
91 * provided to this one. If the versioned command isn't present, an
92 * error message will be provided as a fallback.
102 main(int argc, char **argv)
107 char recommand[1024];
109 char *PYTHON_A = "%%PREFIX%%/bin/python%%ALPHA%%";
110 char *PYTHON_B = "%%PREFIX%%/bin/python%%BRAVO%%";
111 char *PYTHON_C = "%%PREFIX%%/bin/python%%CHARLIE%%";
112 char *ALPHA = "%%ALPHA%%";
113 char *BRAVO = "%%BRAVO%%";
114 char *CHARLIE = "%%CHARLIE%%";
116 override = getenv("AUTOPYTHON");
117 if (override != NULL) {
118 if (strcmp (override, ALPHA) == 0) {
120 } else if (strcmp (override, BRAVO) == 0) {
122 } else if (strcmp (override, CHARLIE) == 0) {
127 if (access(PYTHON_A, F_OK) != -1) {
129 } else if (access(PYTHON_B, F_OK) != -1) {
131 } else if (access(PYTHON_C, F_OK) != -1) {
134 /* no versions of python are installed */
135 printf ("There are no versions of python installed at %%PREFIX%%/bin\n");
141 * Get the last path element of the program name being executed
143 cmd = strrchr(argv[0], '/');
149 if (strcmp (cmd, "python-config") == 0) {
150 snprintf(recommand, 1024,
151 "%%PREFIX%%/bin/python%s-config", pyver);
152 } else if (strcmp (cmd, "2to3") == 0) {
153 snprintf(recommand, 1024,
154 "%%PREFIX%%/bin/2to3-", pyver);
156 snprintf(recommand, 1024,
157 "%%PREFIX%%/bin/%s%s", cmd, pyver);
160 execv(recommand, argv);
163 * Execution failed, so write out an error message
165 printf ("Command execution failed: %s", recommand);
166 printf (" arguments:");
167 for (x = 1; x < argc; x++)
168 printf (" %s", argv[x]);