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