Fix pcc build
[harbours.git] / pcc / pcc-helenos.patch
blob041aa0b50661abecb9459a08a4aa3fd658789eb9
1 --- pcc-1.0.0/configure 2017-08-02 12:34:28.061165186 +0200
2 +++ pcc-1.0.0/configure 2011-04-01 15:58:31.000000000 +0200
3 @@ -2085,6 +2085,8 @@
4 ;;
5 esac
7 +targos=helenos
9 if test "X$targos" = X -o "X$targmach" = X ; then
10 { { echo "$as_me:$LINENO: error: '$target' is not (yet) supported by pcc." >&5
11 echo "$as_me: error: '$target' is not (yet) supported by pcc." >&2;}
12 --- pcc-1.0.0/cc/cc/cc.c 2011-03-15 20:25:36.000000000 +0100
13 +++ pcc-1.0.0/cc/cc/cc.c 2013-09-11 19:46:33.156788000 +0200
14 @@ -1143,6 +1149,11 @@
18 +#ifdef __helenos__
19 + av[j++] = "-T";
20 + av[j++] = "/inc/_link.ld";
21 +#endif
23 av[j++] = 0;
24 eflag |= callsys(ld, av);
25 if (nc==1 && nxo==1 && eflag==0)
26 @@ -1326,6 +1337,63 @@
27 return (exitCode != 0);
30 +#elif defined(__helenos__)
31 +#define _HELENOS_SOURCE
32 +#include <libc/task.h>
34 +int callsys(char *f, char *v[])
36 + size_t len;
37 + char *path = NULL;
38 + const char *s;
39 + int t;
40 + task_wait_t twait;
41 + task_exit_t texit;
42 + int retval;
44 + task_id_t tid;
46 + if (vflag) {
47 + fprintf(stderr, "%s ", f);
48 + for (t = 1; v[t]; t++)
49 + fprintf(stderr, "%s ", v[t]);
50 + fprintf(stderr, "\n");
51 + }
53 + if (Bflag) {
54 + len = strlen (Bflag) + 8;
55 + path = malloc (len);
56 + if (path == NULL) {
57 + error("callsys: malloc failed");
58 + exit(1);
59 + }
60 + if ((s = strrchr(f, '/'))) {
61 + strlcpy(path, Bflag, len);
62 + strlcat(path, s, len);
63 + if (task_spawnv(&tid, &twait, path, v) == 0)
64 + goto _wait;
65 + }
66 + }
68 + if (task_spawnv(&tid, &twait, f, v) == 0)
69 + goto _wait;
71 + if ((s = strrchr(f, '/')) && task_spawnv(&tid, &twait, s + 1, v) == 0)
72 + goto _wait;
74 + errorx(8, "Can't find %s\n", f);
75 + return 0;
77 +_wait:
79 + if (task_wait(&twait, &texit, &retval) != 0) {
80 + error("Couldn't wait on task");
81 + return 0;
82 + }
84 + return retval;
87 #else
89 int
90 diff -ur --unidirectional-new-file pcc-1.0.0/cc/ccom/main.c pcc/cc/ccom/main.c
91 --- pcc-1.0.0/cc/ccom/main.c 2011-01-22 23:08:23.000000000 +0100
92 +++ pcc-1.0.0/cc/ccom/main.c 2013-09-11 19:46:33.156788000 +0200
93 @@ -299,6 +299,9 @@
94 perror(NULL);
95 exit(1);
97 + } else {
98 + fprintf(stderr, "Reading from standard input is disabled on HelenOS\n");
99 + exit(1);
101 if (argc > 1 && strcmp(argv[1], "-") != 0) {
102 if (freopen(argv[1], "w", stdout) == NULL) {
103 @@ -310,7 +313,9 @@
106 mkdope();
107 +#ifndef __helenos__
108 signal(SIGSEGV, segvcatch);
109 +#endif
110 #ifdef SIGBUS
111 signal(SIGBUS, segvcatch);
112 #endif
113 --- pcc-1.0.0/cc/ccom/pftn.c 2011-02-20 11:19:07.000000000 +0100
114 +++ pcc-1.0.0/cc/ccom/pftn.c 2013-09-11 19:46:33.156788000 +0200
115 @@ -1139,6 +1139,12 @@
118 ap = attr_find(apl, ATTR_BASETYP);
120 + if (ap == NULL) {
121 + cerror("unknown type");
122 + return SZINT;
125 sz = ap->atypsz;
127 #ifdef GCC_COMPAT
128 --- pcc-1.0.0/cc/cpp/cpp.c 2011-03-27 15:17:19.000000000 +0200
129 +++ pcc-1.0.0/cc/cpp/cpp.c 2013-09-11 19:46:33.156788000 +0200
130 @@ -274,7 +274,7 @@
131 if ((ofd = open(argv[1], O_WRONLY|O_CREAT, 0600)) < 0)
132 error("Can't creat %s", argv[1]);
133 } else
134 - ofd = 1; /* stdout */
135 + ofd = fileno(stdout);
136 istty = isatty(ofd);
138 if (argc && strcmp(argv[0], "-")) {
139 @@ -402,7 +402,7 @@
140 struct symtab *nl;
141 usch *osp;
142 usch *fn, *safefn;
143 - int c, it;
144 + int c;
146 if (flslvl)
147 return;
148 @@ -436,7 +436,7 @@
150 if (c != '\n')
151 goto bad;
152 - it = SYSINC;
153 + (void) SYSINC;
154 safefn = fn;
155 } else {
156 usch *nm = stringbuf;
157 @@ -869,7 +869,6 @@
159 usch *t;
160 usch *sb = stringbuf;
161 - int dummy;
163 flbuf();
164 savch(0);
165 @@ -877,8 +876,8 @@
166 t = sheap("%s:%d: warning: ", ifiles->fname, ifiles->lineno);
167 write (2, t, strlen((char *)t));
169 - dummy = write (2, s, strlen((char *)s));
170 - dummy = write (2, "\n", 1);
171 + write (2, s, strlen((char *)s));
172 + write (2, "\n", 1);
173 stringbuf = sb;
176 @@ -886,16 +885,15 @@
177 xerror(usch *s)
179 usch *t;
180 - int dummy;
182 flbuf();
183 savch(0);
184 if (ifiles != NULL) {
185 t = sheap("%s:%d: error: ", ifiles->fname, ifiles->lineno);
186 - dummy = write (2, t, strlen((char *)t));
187 + write (2, t, strlen((char *)t));
189 - dummy = write (2, s, strlen((char *)s));
190 - dummy = write (2, "\n", 1);
191 + write (2, s, strlen((char *)s));
192 + write (2, "\n", 1);
193 exit(1);
196 @@ -1709,12 +1707,27 @@
200 +static ssize_t
201 +_write_all(int fd, const void* buffer, size_t count)
203 + size_t remaining = count;
204 + while (remaining > 0) {
205 + ssize_t retval = write(ofd, buffer, remaining);
206 + if (retval < 0) {
207 + return retval;
209 + remaining -= retval;
210 + buffer += retval;
212 + return count;
215 void
216 flbuf()
218 if (obufp == 0)
219 return;
220 - if (Mflag == 0 && write(ofd, outbuf, obufp) < 0)
221 + if (Mflag == 0 && _write_all(ofd, outbuf, obufp) < 0)
222 error("obuf write error");
223 lastoch = outbuf[obufp-1];
224 obufp = 0;
225 @@ -1862,7 +1875,7 @@
226 struct symtab *sp;
227 struct tree *w, *new, *last;
228 int len, cix, bit, fbit, svbit, ix, bitno;
229 - const usch *k, *m, *sm;
230 + const usch *k, *m;
232 /* Count full string length */
233 for (k = key, len = 0; *k; k++, len++)
234 @@ -1897,7 +1910,7 @@
236 sp = (struct symtab *)w;
238 - sm = m = sp->namep;
239 + m = sp->namep;
240 k = key;
242 /* Check for correct string and return */
243 --- pcc-1.0.0/cc/cpp/token.c 2011-03-12 18:08:26.000000000 +0100
244 +++ pcc-1.0.0/cc/cpp/token.c 2013-09-11 19:46:33.156788000 +0200
245 @@ -182,7 +182,7 @@
246 fastscan(void)
248 struct symtab *nl;
249 - int ch, i, ccnt, onemore;
250 + int ch, i, ccnt;
251 usch *cp;
253 goto run;
254 @@ -356,7 +356,7 @@
255 ch = NXTCH();
256 goto xloop;
258 - onemore = i = ccnt = 0;
259 + i = ccnt = 0;
260 do {
261 yytext[i++] = (usch)ch;
262 ch = NXTCH();
263 @@ -799,7 +799,8 @@
264 if (++inclevel > MAX_INCLEVEL)
265 error("Limit for nested includes exceeded");
266 } else {
267 - ic->infil = 0;
268 + error("Reading from stdin is disabled on HelenOS.");
269 + ic->infil = fileno(stdin);
270 ic->orgfn = ic->fname = (const usch *)"<stdin>";
272 #ifndef BUF_STACK