From 23880da0fa018c91fed4adac0fef3d8a28f6be52 Mon Sep 17 00:00:00 2001 From: Jonathan Hudson Date: Sun, 28 Aug 2022 15:59:27 +0100 Subject: [PATCH 1/6] support user defined installation path fixup intances of long as pointer with intptr_t for Msys2 --- Makefile | 2 +- README.md | 31 ++++- as68/Makefile | 4 +- as68/jas.h | 9 +- as68/parse.c | 2 +- c68/Makefile | 4 +- cc/Makefile | 4 +- cc/cc.c | 10 +- cc/cc.h | 7 +- cpp/Makefile | 6 +- cpp/cccp.c | 313 +++++++++++-------------------------------------- install.sh | 82 ------------- ld/Makefile | 6 +- ld/ldold.c | 91 ++++++++------ sdk-install.sh | 87 ++++++++++++++ slb/Makefile | 4 +- slb/slbdis.c | 17 ++- tools/Makefile | 4 +- 18 files changed, 277 insertions(+), 406 deletions(-) delete mode 100755 install.sh create mode 100755 sdk-install.sh diff --git a/Makefile b/Makefile index 4e3e193..3f9b3e5 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ DIRS = as68 c68 cc cpp ld slb CLEANDIRS = $(DIRS:%=clean-%) INSTALLDIRS = $(DIRS:%=install-%) -prefix ?= /usr/local/bin +prefix ?= /usr/local export prefix CFLAGS += -Wall -Wextra -pedantic diff --git a/README.md b/README.md index 33c82a9..b8efca6 100644 --- a/README.md +++ b/README.md @@ -9,39 +9,58 @@ As of 2021-08-24, the codebase is 64bit clean. There is no longer any requiremen ## Runtime -You need the C68 runtime binary distribution. A good place to start looking is http://www.dilwyn.me.uk/c/index.html. If runtime disk1 is installed under `support`, the `install.sh` script will install a usable environment, such that: +You need the C68 runtime binary distribution. A good place to start looking is http://www.dilwyn.me.uk/c/index.html. If runtime disk1 is installed under `support`, the `sdk-install.sh` script will install a usable environment, such that: ``` qcc -o hw hw.c ``` -will generate a QDOS executable, where `hw.c` is a trivial, standard "Hello World" application, assuming `/usr/local/bin` is on `$PATH`. +will generate a QDOS executable, where `hw.c` is a trivial, standard "Hello World" application, assuming the installation directory `$(prefix)/bin` is on `$PATH`. It is not purpose of this repo to provide a QDOS c68 environemnt, nor does it offer any help for QDOS development; it mere maintains a cross compiler. ## Installation -On most POSIX (like) systems (Linux, *BSD, MacOS, Msys, Cygwin) to build and install the excutables: +On most POSIX (like) systems (Linux, *BSD, MacOS, Msys, Cygwin) to build and install the excutables. ``` -# build and install the executables +# build and install the executables in /usr/local (default) make && sudo make install # on *BSD, you need GNU Make gmake && sudo gmake install ``` +A more modern practice on essentially "sole user" systems is to install under `~/.local`, thusly: + +``` +make install prefix=~/.local +# gmake install prefix=~/.local ## FreeBSD et al +``` + +`sudo` is then not needed. To install the QDOS includes and libraries ``` -./install.sh -s +./sdk-install.sh [~/.local] ``` +If the optional directory is omitted, `/usr/local` is assumed. You can also use the environment variable `PREFIX` (or `prefix`) instead. + ## Integration with native make (i.e. GNU Make) -* The `install.sh` script provides `ql.mak`, which it will copy to `/usr/local/qdos/etc/ql.mak` +* The `sdk-install.sh` script provides `ql.mak`, which it will copy to `$PREFIX/qdos/etc/ql.mak` * In your QDOS project `Makefile`, as the first line: ``` + # local install, alas $$HOME is not expanded here .. + include /home/USERNAME/.local/qdos/etc/ql.mak + ``` + or + + ``` + # System install include /usr/local/qdos/etc/ql.mak ``` + + Now you can easily use GNU Make to build your QDOS project. diff --git a/as68/Makefile b/as68/Makefile index f3065f7..5854ab8 100644 --- a/as68/Makefile +++ b/as68/Makefile @@ -29,5 +29,5 @@ clean: rm -f *.o as68 install: as68 - install -d $(prefix) - install as68 $(prefix) + install -d $(prefix)/bin + install as68 $(prefix)/bin diff --git a/as68/jas.h b/as68/jas.h index 92f97e0..c419d44 100644 --- a/as68/jas.h +++ b/as68/jas.h @@ -15,7 +15,8 @@ #include #include #include - +#include +#include typedef struct _sym { struct _sym *next; @@ -23,7 +24,7 @@ typedef struct _sym { char here[8]; long stix[2]; } name; - long value; + intptr_t value; unsigned short index; unsigned short flags; unsigned short access; @@ -31,7 +32,7 @@ typedef struct _sym { typedef struct { struct _sym *psym; - long value; + intptr_t value; } EXPR; /* @@ -194,5 +195,3 @@ struct _branch { #ifndef GENERIC extern long dottxt; #endif /* GENERIC */ - - diff --git a/as68/parse.c b/as68/parse.c index 69ef77c..e4b0ea1 100644 --- a/as68/parse.c +++ b/as68/parse.c @@ -228,7 +228,7 @@ VOID Yinstruction(void) ldp->minus = lp->sym2; ldp->constant = lp->u.val.value; - generate(size, GENLDIFF, (long) ldp, NULL); + generate(size, GENLDIFF, (intptr_t) ldp, NULL); } #endif /* LABELDIFF */ free( (char *) lp ); diff --git a/c68/Makefile b/c68/Makefile index 7c8f169..a66d483 100644 --- a/c68/Makefile +++ b/c68/Makefile @@ -362,5 +362,5 @@ pkzip: pkzip $(PROG)src$(S)zip $(HDR68K) $(HDRX86) $(HDR386) $(HDR86) $(HDRARM) $(HDRC30) $(HDRPPC) install: $(PROG) - install -d $(prefix) - install $(PROG) $(prefix) + install -d $(prefix)/bin + install $(PROG) $(prefix)/bin diff --git a/cc/Makefile b/cc/Makefile index 7158cac..33defdd 100644 --- a/cc/Makefile +++ b/cc/Makefile @@ -172,5 +172,5 @@ zipsrc: $(ZIP) ccsrc$(S)zip makefile cc$(S)pr $(SRC) $(HDR) cc$(S)1 cc$(S)ds? install: $(PROG) - install -d $(prefix) - install $(PROG) $(prefix) + install -d $(prefix)/bin + install $(PROG) $(prefix)/bin diff --git a/cc/cc.c b/cc/cc.c index bb64cc3..26b77ab 100644 --- a/cc/cc.c +++ b/cc/cc.c @@ -28,12 +28,12 @@ */ /* for basename() --- see the man page for GNU v. POSIX versions */ -#define _GNU_SOURCE +//#define _GNU_SOURCE #include #include -#ifdef __FreeBSD__ +//#ifdef __FreeBSD__ #include /*(POSIX) */ -#endif +//#endif #ifdef __APPLE__ #include @@ -773,7 +773,7 @@ int command_line (CC_PASSES_t * preopts, * pass back the result of running the program if the system() * call is used - the result is always 0! */ - ret = _spawnvp(_P_WAIT,current_pass.argv[0],current_pass.argv); + ret = _spawnvp(_P_WAIT,current_pass.argv[0],(const char *const *)current_pass.argv); #elif QDOS /* * On QDOS we can use the execv() family of routines as these @@ -1629,7 +1629,7 @@ char *argv[]; cp = &passes[pass]; if (pass != last_pass) { - (void) strcpy( outname, basename( inname )); /* Get its basename */ + (void) strcpy( outname, basename( inname )); /* Get its basename */ } else { diff --git a/cc/cc.h b/cc/cc.h index b0381ca..1a93cf1 100644 --- a/cc/cc.h +++ b/cc/cc.h @@ -1,3 +1,5 @@ + #define _GNU_SOURCE + /* * cc.h * ~~~~ @@ -529,11 +531,6 @@ int CheckCPU _P_((void)); # define stricmp strcasecmp # endif /* EPOC */ # endif /* WIN32 */ -#if !defined(__unix__) && !defined(__APPLE__) -char * stpcpy _P_((char *, char *)); -#endif /* __unix__ */ -char * strpbrk _P_((const char *, const char *)); -char * strrpbrk _P_((char *, char *)); #endif /* QDOS */ #ifdef JDBG diff --git a/cpp/Makefile b/cpp/Makefile index a9e7be6..cfe7798 100644 --- a/cpp/Makefile +++ b/cpp/Makefile @@ -2,7 +2,7 @@ PROG = qcpp APFLAGS= -DXTC68 -DCPLUSPLUS -CFLAGS += -O2 $(APFLAGS) +CFLAGS += -O2 $(APFLAGS) -DPREFIX="$(prefix)" LDFLAGS = OBJ = version.o cexp.o cccp.o @@ -16,5 +16,5 @@ clean: rm -f *.o qcpp install: $(PROG) - install -d $(prefix) - install $(PROG) $(prefix) + install -d $(prefix)/bin + install $(PROG) $(prefix)/bin diff --git a/cpp/cccp.c b/cpp/cccp.c index 1eb1349..cb49654 100644 --- a/cpp/cccp.c +++ b/cpp/cccp.c @@ -23,29 +23,12 @@ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. typedef unsigned char U_CHAR; -#ifdef EMACS -#define NO_SHORTNAMES -#include "../src/config.h" -#ifdef open -#undef open -#undef read -#undef write -#endif /* open */ -#endif /* EMACS */ - -#ifndef EMACS #include "config.h" -#endif /* not EMACS */ #ifndef STDC_VALUE #define STDC_VALUE 1 #endif -/* In case config.h defines these. */ -#undef bcopy -#undef bzero -#undef bcmp - #include #include #include @@ -56,22 +39,12 @@ typedef unsigned char U_CHAR; #include #include #include - - -#if !defined (VMS) && !defined (QDOS) && !defined (DOS_LIKE) #include #include #include /* for __DATE__ and __TIME__ */ -#include -#else -#define index strchr -#define rindex strrchr -#include -#ifndef QDOS -#include -#endif #include -#endif /* not VMS */ +#include +#include /* VMS-specific definitions */ #ifdef VMS @@ -106,17 +79,7 @@ typedef unsigned char U_CHAR; /* External declarations. */ -#ifndef __APPLE__ -#ifndef DOS_LIKE -void bcopy (), bzero (); -int bcmp (); -extern char *getenv (); -#else #include -#define bzero(b,len) memset(b, '\0', len) -#define bcopy(b1,b2,len) memcpy(b2,b1,len) -#endif -#endif extern char *version_string; extern int error(char *msg,...); @@ -130,6 +93,9 @@ extern int error(char *msg,...); #define SUCCESS_EXIT_CODE 0 /* 0 means success on Unix. */ #endif +#define XSTR(s) STR(s) +#define STR(s) #s + /* Name under which this program was invoked. */ char *progname; @@ -358,7 +324,7 @@ struct definition { /* different kinds of things that can appear in the value field of a hash node. Actually, this may be useless now. */ union hashval { - long ival; + intptr_t ival; char *cpval; DEFINITION *defn; }; @@ -447,7 +413,7 @@ struct arglist { long argno; }; -HASHNODE * install (U_CHAR *, long, enum node_type, long, long); +HASHNODE * install (U_CHAR *, long, enum node_type, intptr_t, long); void fatal (char *,...); void fancy_abort (void), pfatal_with_name (char *), perror_with_name (char *); HASHNODE * lookup (U_CHAR *, long, long); @@ -907,7 +873,7 @@ void deps_output (char *string, long size) deps_allocated_size *= 2; deps_buffer = (char *) xrealloc (deps_buffer, deps_allocated_size); } - bcopy (string, &deps_buffer[deps_size], size); + memmove (&deps_buffer[deps_size], string, size); deps_size += size; deps_column += size; deps_buffer[deps_size] = 0; @@ -991,23 +957,6 @@ main (argc, argv) new_argv[new_argc++] = argv[arg_cpy]; } -#ifdef VMS - { - /* Remove directories from PROGNAME. */ - char *s; - extern char *rindex (); - - progname = savestring (argv[0]); - - if (!(s = rindex (progname, ']'))) - s = rindex (progname, ':'); - if (s) - strcpy (progname, s+1); - if (s = rindex (progname, '.')) - *s = '\0'; - } -#endif - in_fname = NULL; out_fname = NULL; @@ -1057,21 +1006,38 @@ main (argc, argv) char *s; struct file_name_list *q; int n; - - if((s = getenv("QLINC"))) + int base_inc = 0; + +#ifdef PREFIX + char* pfx = XSTR(PREFIX); + if (strlen(pfx) > 0) { + char *pinc = malloc(strlen(pfx) + 32); + strcpy(pinc, pfx); + strcat(pinc, "/qdos/include"); + include_defaults[0].fname = pinc; + include_defaults[0].next = include_defaults + 1; + cplusplus_include_defaults[0].fname = pinc; + base_inc++; + } +#endif + if((s = getenv("QLINC"))) { - char *p,*r; - r = include_defaults[0].fname = strdup(s); + r = include_defaults[base_inc].fname = strdup(s); p = (r + strlen(r) - 1); if(*p == '\\' || *p == '/') { *p = 0; } - include_defaults[0].next = include_defaults + 1; - cplusplus_include_defaults[0].fname = r; + include_defaults[base_inc].next = include_defaults + 1; + cplusplus_include_defaults[base_inc].fname = r; + base_inc++; } + // fallback + include_defaults[base_inc].fname = "/usr/local/qdos/include"; + include_defaults[base_inc].next = NULL; + max_include_len = 0; for(q = include_defaults; q->next; q++) { @@ -1093,9 +1059,9 @@ main (argc, argv) } #endif - bzero ((char *) pend_files, new_argc * sizeof (char *)); - bzero ((char *) pend_defs, new_argc * sizeof (char *)); - bzero ((char *) pend_undefs, new_argc * sizeof (char *)); + memset ((char *) pend_files, 0, new_argc * sizeof (char *)); + memset ((char *) pend_defs, 0, new_argc * sizeof (char *)); + memset ((char *) pend_undefs, 0, new_argc * sizeof (char *)); /* Process switches and find input file name. */ @@ -1192,7 +1158,7 @@ main (argc, argv) else p = new_argv[++i]; - if ((p1 = (char *) index (p, '=')) != NULL) + if ((p1 = (char *) strchr (p, '=')) != NULL) *p1 = ' '; pend_defs[i] = p; } @@ -1404,13 +1370,13 @@ main (argc, argv) s = spec; /* Find the space before the DEPS_TARGET, if there is one. */ - /* Don't use `index'; that causes trouble on USG. */ + /* Don't use `strchr'; that causes trouble on USG. */ while (*s != 0 && *s != ' ') s++; if (*s != 0) { deps_target = s + 1; output_file = (char *) xmalloc (s - spec + 1); - bcopy (spec, output_file, s - spec); + memmove (output_file, spec, s - spec); output_file[s - spec] = 0; } else @@ -1583,9 +1549,9 @@ main (argc, argv) fputs (deps_buffer, deps_stream); putc ('\n', deps_stream); if (deps_stream != stdout) { - fclose (deps_stream); if (ferror (deps_stream)) fatal ("I/O error on output"); + fclose (deps_stream); } } @@ -1616,7 +1582,7 @@ void trigraph_pcp (FILE_BUF *buf) int len; fptr = bptr = sptr = buf->buf; - while ((sptr = (U_CHAR *) index ((char *)sptr, '?')) != NULL) { + while ((sptr = (U_CHAR *) strchr ((char *)sptr, '?')) != NULL) { if (*++sptr != '?') continue; switch (*++sptr) { @@ -1655,7 +1621,7 @@ void trigraph_pcp (FILE_BUF *buf) } len = sptr - fptr - 2; if (bptr != fptr && len > 0) - bcopy (fptr, bptr, len); /* BSD doc says bcopy () works right + memmove (bptr, fptr, len); /* BSD doc says bcopy () works right for overlapping strings. In ANSI C, this will be memmove (). */ bptr += len; @@ -1664,7 +1630,7 @@ void trigraph_pcp (FILE_BUF *buf) } len = buf->length - (fptr - buf->buf); if (bptr != fptr && len > 0) - bcopy (fptr, bptr, len); + memmove (bptr, fptr, len); buf->length -= fptr - bptr; buf->buf[buf->length] = '\0'; if (warn_trigraphs && fptr != bptr) @@ -2061,7 +2027,7 @@ do { ip->macro->type = T_MACRO; \ } else if (*ibp++ == '\n') { ibp--; if (put_out_comments) { - bcopy (before_bp, obp, ibp - before_bp); + memmove (obp, before_bp, ibp - before_bp); obp += ibp - before_bp; } break; @@ -2128,7 +2094,7 @@ do { ip->macro->type = T_MACRO; \ else { ibp++; if (put_out_comments) { - bcopy (before_bp, obp, ibp - before_bp); + memmove (obp, before_bp, ibp - before_bp); obp += ibp - before_bp; } } @@ -2845,13 +2811,13 @@ long handle_directive (FILE_BUF *ip, FILE_BUF *op) /* Output directive name. */ check_expand (op, kt->length+1); *op->bufp++ = '#'; - bcopy (kt->name, op->bufp, kt->length); + memmove (op->bufp, kt->name, kt->length); op->bufp += kt->length; /* Output arguments. */ len = (cp - buf); check_expand (op, len); - bcopy (buf, op->bufp, len); + memmove (op->bufp, buf, len); op->bufp += len; } @@ -2938,7 +2904,7 @@ void special_symbol ( HASHNODE *hp, FILE_BUF *op) case T_CONST: buf = (char *) alloca (4 * sizeof (long)); - sprintf (buf, "%ld", hp->value.ival); + sprintf (buf, "%" PRId64 , hp->value.ival); break; case T_SPECLINE: @@ -3000,9 +2966,8 @@ void special_symbol ( HASHNODE *hp, FILE_BUF *op) } len = strlen (buf); check_expand (op, len); - bcopy (buf, op->bufp, len); + memmove (op->bufp, buf, len); op->bufp += len; - return; } @@ -3058,7 +3023,6 @@ void do_include (U_CHAR *buf, U_CHAR *limit, FILE_BUF *op) { long n; char *ep,*nam; - extern char *rindex (); if ((nam = fp->fname) != NULL) { /* Found a named file. Figure out dir of the file, @@ -3067,12 +3031,12 @@ void do_include (U_CHAR *buf, U_CHAR *limit, FILE_BUF *op) stackp = dsp; #ifndef QDOS #ifndef VMS - ep = rindex (nam, '\\'); - if (ep == NULL) ep = rindex (nam, ':'); + ep = strrchr (nam, '\\'); + if (ep == NULL) ep = strrchr (nam, ':'); #else /* VMS */ - ep = rindex (nam, ']'); - if (ep == NULL) ep = rindex (nam, '>'); - if (ep == NULL) ep = rindex (nam, ':'); + ep = strrchr (nam, ']'); + if (ep == NULL) ep = strrchr (nam, '>'); + if (ep == NULL) ep = strrchr (nam, ':'); if (ep != NULL) ep++; #endif /* VMS */ if (ep != NULL) { @@ -3115,7 +3079,7 @@ void do_include (U_CHAR *buf, U_CHAR *limit, FILE_BUF *op) } else { trybuf = expand_to_temp_buffer (buf, limit, 0); buf = (U_CHAR *) alloca (trybuf.bufp - trybuf.buf + 1); - bcopy (trybuf.buf, buf, trybuf.bufp - trybuf.buf); + memmove (buf, trybuf.buf, trybuf.bufp - trybuf.buf); limit = buf + (trybuf.bufp - trybuf.buf); free (trybuf.buf); retried++; @@ -3273,7 +3237,7 @@ int finclude (int f, char *fname, FILE_BUF *op) goto nope; /* Impossible? */ fp = &instack[indepth + 1]; - bzero ((char *) fp, sizeof (FILE_BUF)); + memset ((char *) fp, 0, sizeof (FILE_BUF)); fp->fname = fname; fp->length = 0; fp->lineno = 1; @@ -3324,7 +3288,7 @@ int finclude (int f, char *fname, FILE_BUF *op) } fp->buf = (U_CHAR *) alloca (st_size + 2); fp->bufp = fp->buf; - bcopy (basep, fp->buf, st_size); + memmove (fp->buf, basep, st_size); fp->length = st_size; free (basep); } @@ -3391,7 +3355,7 @@ void do_define (U_CHAR *buf, U_CHAR *limit) else if (!is_idstart[*symname]) { U_CHAR *msg; /* what pain... */ msg = (U_CHAR *) alloca (sym_length + 1); - bcopy (symname, msg, sym_length); + memmove (msg, symname, sym_length); msg[sym_length] = 0; #ifndef QDOS error ("invalid macro name `%s'", msg); @@ -3466,7 +3430,7 @@ void do_define (U_CHAR *buf, U_CHAR *limit) struct arglist *temp; long i = 0; for (temp = arg_ptrs; temp; temp = temp->next) { - bcopy (temp->name, &defn->argnames[i], temp->length); + memmove(&defn->argnames[i], temp->name, temp->length); i += temp->length; if (temp->next != 0) { defn->argnames[i++] = ','; @@ -3493,7 +3457,7 @@ void do_define (U_CHAR *buf, U_CHAR *limit) || compare_defs (defn, hp->value.defn)) { U_CHAR *msg; /* what pain... */ msg = (U_CHAR *) alloca (sym_length + 20); - bcopy (symname, msg, sym_length); + memmove (msg, symname, sym_length); strcpy ((char *) (msg + sym_length), " redefined"); warning ((char *)msg); } @@ -3501,7 +3465,7 @@ void do_define (U_CHAR *buf, U_CHAR *limit) hp->type = T_MACRO; hp->value.defn = defn; } else - install (symname, sym_length, T_MACRO, (long) defn, hashcode); + install (symname, sym_length, T_MACRO, (intptr_t) defn, hashcode); } return; @@ -3943,7 +3907,7 @@ void do_line (U_CHAR *buf, U_CHAR *limit, FILE_BUF *op) hp->length = fname_length; ip->fname = hp->value.cpval = ((char *) hp) + sizeof (HASHNODE); - bcopy (fname, hp->value.cpval, fname_length); + memmove (hp->value.cpval, fname, fname_length); } } else if (*bp) { error ("invalid format #line command"); @@ -3995,7 +3959,7 @@ void do_error (U_CHAR *buf, U_CHAR *limit) { long length = limit - buf; char *copy = (char *) xmalloc (length + 1); - bcopy (buf, copy, length); + memmove (copy, buf, length); copy[length] = 0; SKIP_WHITE_SPACE (copy); error ("#error %s", copy); @@ -4672,7 +4636,7 @@ void output_line_command (FILE_BUF *ip, FILE_BUF *op, long conditional, check_expand (op, len + 1); if (op->bufp > op->buf && op->bufp[-1] != '\n') *op->bufp++ = '\n'; - bcopy (line_cmd_buf, op->bufp, len); + memmove (op->bufp, line_cmd_buf, len); op->bufp += len; op->lineno = ip->lineno; } @@ -4831,7 +4795,7 @@ void macroexpand (HASHNODE *hp, FILE_BUF *op) /* Generate in XBUF the complete expansion with arguments substituted in. TOTLEN is the total size generated so far. - OFFSET is the index in the definition + OFFSET is the strchr in the definition of where we are copying from. */ offset = totlen = 0; for (ap = defn->pattern; ap != NULL; ap = ap->next) { @@ -4936,10 +4900,10 @@ void macroexpand (HASHNODE *hp, FILE_BUF *op) else break; } } - bcopy (p1, xbuf + totlen, l1 - p1); + memmove (xbuf + totlen, p1, l1 - p1); totlen += l1 - p1; } else { - bcopy (arg->expanded, xbuf + totlen, arg->expand_length); + memmove (xbuf + totlen, arg->expanded, arg->expand_length); totlen += arg->expand_length; } @@ -5029,7 +4993,7 @@ char * macarg (struct argdata *argptr) U_CHAR *buffer = (U_CHAR *) xmalloc (bufsize + extra + 1); long final_start = 0; - bcopy (ip->bufp, buffer, bufsize); + memmove (buffer, ip->bufp, bufsize); ip->bufp = bp; ip->lineno += newlines; @@ -5050,7 +5014,7 @@ char * macarg (struct argdata *argptr) bufsize += bp - ip->bufp; extra += newlines; buffer = (U_CHAR *) xrealloc ((char *)buffer, bufsize + extra + 1); - bcopy (ip->bufp, buffer + bufsize - (bp - ip->bufp), bp - ip->bufp); + memmove (buffer + bufsize - (bp - ip->bufp), ip->bufp, bp - ip->bufp); ip->bufp = bp; ip->lineno += newlines; } @@ -5059,7 +5023,7 @@ char * macarg (struct argdata *argptr) discarding comments and duplicating newlines in whatever part of it did not come from a macro expansion. EXTRA space has been preallocated for duplicating the newlines. - FINAL_START is the index of the start of that part. */ + FINAL_START is the strchr of the start of that part. */ if (argptr != 0) { argptr->raw = buffer; argptr->raw_length = bufsize; @@ -5491,7 +5455,7 @@ long grow_outbuf (FILE_BUF *obuf, long needed) * Otherwise, compute the hash code. */ HASHNODE * install (U_CHAR *name, long len, enum node_type type, - long value, + intptr_t value, long hash) /* watch out here if sizeof (U_CHAR *) != sizeof (long) */ { @@ -5708,7 +5672,7 @@ void dump_arg_n (DEFINITION *defn, long argnum) { register U_CHAR *p = defn->argnames; while (argnum + 1 < defn->nargs) { - p = (U_CHAR *) index ((char*)p, ' ') + 1; + p = (U_CHAR *) strchr ((char*)p, ' ') + 1; argnum++; } @@ -5739,140 +5703,3 @@ long file_size_and_mode(long fd, long *mode_pointer, long int *size_pointer) return 0; } -#ifdef VMS - -/* Under VMS we need to fix up the "include" specification - filename so that everything following the 1st slash is - changed into its correct VMS file specification. */ - - hack_vms_include_specification (fname) - char *fname; -{ - register char *cp, *cp1, *cp2; - char Local[512]; - extern char *index (), *rindex (); - - /* Ignore leading "./"s */ - while (fname[0] == '.' && fname[1] == '/') - strcpy (fname, fname+2); - /* Look for the boundary between the VMS and UNIX filespecs */ - cp = rindex (fname, ']'); /* Look for end of dirspec. */ - if (cp == 0) cp == rindex (fname, '>'); /* ... Ditto */ - if (cp == 0) cp == rindex (fname, ':'); /* Look for end of devspec. */ - if (cp) { - cp++; - } else { - cp = index (fname, '/'); /* Look for the "/" */ - } - /* See if we found that 1st slash */ - if (cp == 0) return; /* Nothing to do!!! */ - if (*cp != '/') return; /* Nothing to do!!! */ - /* Point to the UNIX filename part (which needs to be fixed!) */ - cp1 = cp+1; - /* If the directory spec is not rooted, we can just copy - the UNIX filename part and we are done */ - if (((cp - fname) > 2) - && ((cp[-1] == ']') || (cp[-1] == '>')) - && (cp[-2] != '.')) { - strcpy (cp, cp1); - return; - } - /* If there are no other slashes then the filename will be - in the "root" directory. Otherwise, we need to add - directory specifications. */ - if (index (cp1, '/') == 0) { - /* Just add "[000000]" as the directory string */ - strcpy (Local, "[000000]"); - cp2 = Local + strlen (Local); - } else { - /* Open the directory specification */ - cp2 = Local; - *cp2++ = '['; - /* As long as there are still subdirectories to add, do them. */ - while (index (cp1, '/') != 0) { - /* If this token is "." we can ignore it */ - if ((cp1[0] == '.') && (cp1[1] == '/')) { - cp1 += 2; - continue; - } - /* Add a subdirectory spec. */ - if (cp2 != Local+1) *cp2++ = '.'; - /* If this is ".." then the spec becomes "-" */ - if ((cp1[0] == '.') && (cp1[1] == '.') && (cp[2] == '/')) { - /* Add "-" and skip the ".." */ - *cp2++ = '-'; - cp1 += 3; - continue; - } - /* Copy the subdirectory */ - while (*cp1 != '/') *cp2++= *cp1++; - cp1++; /* Skip the "/" */ - } - /* Close the directory specification */ - *cp2++ = ']'; - } - /* Now add the filename */ - while (*cp1) *cp2++ = *cp1++; - *cp2 = 0; - /* Now append it to the original VMS spec. */ - strcpy (cp, Local); - return; -} -#endif /* VMS */ - -#ifdef VMS - -/* These are the read/write replacement routines for - VAX-11 "C". They make read/write behave enough - like their UNIX counterparts that CCCP will work */ - -int -read (fd, buf, size) - int fd; - char *buf; - int size; -{ -#undef read /* Get back the REAL read routine */ - register int i; - register int total = 0; - - /* Read until the buffer is exhausted */ - while (size > 0) { - /* Limit each read to 32KB */ - i = (size > (32*1024)) ? (32*1024) : size; - i = read (fd, buf, i); - if (i <= 0) { - if (i == 0) return (total); - return(i); - } - /* Account for this read */ - total += i; - buf += i; - size -= i; - } - return (total); -} - -int -write (fd, buf, size) - int fd; - char *buf; - int size; -{ -#undef write /* Get back the REAL write routine */ - int i; - int j; - - /* Limit individual writes to 32Kb */ - i = size; - while (i > 0) { - j = (i > (32*1024)) ? (32*1024) : i; - if (write (fd, buf, j) < 0) return (-1); - /* Account for the data written */ - buf += j; - i -= j; - } - return (size); -} - -#endif /* VMS */ diff --git a/install.sh b/install.sh deleted file mode 100755 index 7327b37..0000000 --- a/install.sh +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/env bash - -# Install header files to /usr/local/qdos/include and sub-directories -# Install libraries to /usr/local/qdos/lib -# This script will find the relevant files under ./, in the format -# from the original distribution runtime disk 1 - -SUPONLY= -BINDIR= -for L -do - case $L in - -s) - SUPONLY=1 - ;; - *[\\/]*) - BINDIR=$L - ;; - *) - echo "install.sh [-s] [directory] [-h]" - exit - ;; - esac -done -BINDIR=${BINDIR:-/usr/local/bin} - -if [ $(id -u) -ne 0 ] ; then - if which sudo >/dev/null 2>&1 ; then - exec sudo $0 $* - else - echo "No sudo found, please run ./install.sh as root if necessary" - [ -r /usr/local ] || exit 1 - fi -fi - -CP="cp -v" - -mkdir -p /usr/local/qdos/include/sys -mkdir -p /usr/local/qdos/include/netinet/ -mkdir -p /usr/local/qdos/include/arpa/ -mkdir -p /usr/local/qdos/lib -mkdir -p /usr/local/qdos/etc -[ -f support/ql.mak ] && $CP support/ql.mak /usr/local/qdos/etc - -if [ -z "$SUPONLY" ] ; then - mkdir -p $BINDIR - for B in as68/as68 c68/c68 cc/qcc cpp/qcpp ld/qld slb/slb slb/qdos-ar slb/qdos-ranlib - do - $CP $B $BINDIR - done -fi - -while read FILE -do - FN=$(echo $FILE | tr [:upper:] [:lower:]) - case $FN in - */include_*) - IFILE=${FN##*include_} - case $IFILE in - sys_*) - SIFILE=${IFILE##*sys_} - $CP $FILE /usr/local/qdos/include/sys/$SIFILE - ;; - netinet_*) - SIFILE=${IFILE##*netinet_} - $CP $FILE /usr/local/qdos/include/netinet/$SIFILE - ;; - arpa_*) - SIFILE=${IFILE##*arpa_} - $CP $FILE /usr/local/qdos/include/arpa/$SIFILE - ;; - *) - $CP $FILE /usr/local/qdos/include/$IFILE - ;; - esac - ;; - */lib_*) - LFILE=${FN##*lib_} - $CP $FILE /usr/local/qdos/lib/$LFILE - ;; - esac -done < <(find . -iname include_\* -o -iname lib_\*) diff --git a/ld/Makefile b/ld/Makefile index 1eba594..858ca9f 100644 --- a/ld/Makefile +++ b/ld/Makefile @@ -14,10 +14,10 @@ $(PROG): $(OBJS) $(CC) $(CFLAGS) -o $(PROG) $(OBJS) ld.o: ldold.c - $(CC) $(CFLAGS) -c -o ld.o ldold.c + $(CC) $(CFLAGS) -DPREFIX="$(prefix)" -c -o ld.o ldold.c clean: rm -f *.o $(PROG) install: $(PROG) - install -d $(prefix) - install $(PROG) $(prefix) + install -d $(prefix)/bin + install $(PROG) $(prefix)/bin diff --git a/ld/ldold.c b/ld/ldold.c index ba041c3..3d15985 100644 --- a/ld/ldold.c +++ b/ld/ldold.c @@ -54,6 +54,9 @@ Dec 89 QDOS port done by Jeremy Allison # endif #endif +#define XSTR(s) STR(s) +#define STR(s) #s + char _prog_name[] = "ld"; char _version[] = "v1.22"; char _copyright[] = " QL 68000 SROFF Linker\n"; @@ -96,7 +99,7 @@ long _stackmargin = 1024L; #define MAX_NDEF 30 #define BLEN 1024 #define XMAX 10 -#define NUM_SPATHS 9 +#define NUM_SPATHS 16 #define MIN_DATASPACE 100 @@ -118,38 +121,38 @@ typedef struct oper /* Program symbol */ typedef struct symbol - { - short length; - O___DIRECT directive; - char string[81]; - long longword; - short id; - char trunc_rule; - unsigned char data_byte; - short n_xref; - OPER xref_oper[XMAX]; - } SYMBOL; +{ + short length; + O___DIRECT directive; + char string[81]; + intptr_t longword; + short id; + char trunc_rule; + unsigned char data_byte; + short n_xref; + OPER xref_oper[XMAX]; +} SYMBOL; /* Module list */ typedef struct mod_item - { - struct mod_item *mod_next; - char mod_name[2]; - } MOD_ITEM; +{ + struct mod_item *mod_next; + char mod_name[2]; +} MOD_ITEM; /* Section, TEXT, DATA or BSS */ typedef struct section - { - struct section *sec_next; - short sec_id; /* -1 = TEXT, -2 = DATA, -3 = BSS */ - char *sec_start; - long sec_length; - long sec_oldlen; - long sec_fxref; - long sec_xptr; - MOD_ITEM *sec_module; /* List of modules contributing to this section */ - char sec_name[MAX_LEN]; - } SECTION; +{ + struct section *sec_next; + short sec_id; /* -1 = TEXT, -2 = DATA, -3 = BSS */ + char *sec_start; + intptr_t sec_length; + intptr_t sec_oldlen; + intptr_t sec_fxref; + intptr_t sec_xptr; + MOD_ITEM *sec_module; /* List of modules contributing to this section */ + char sec_name[MAX_LEN]; +} SECTION; /* XDEF symbol */ typedef struct xsym @@ -322,7 +325,7 @@ void statistic(void) (void) fprintf(list_file,"---------------------------\n"); for (s=sec_liste;s!=NULL;s=s->sec_next) (void) fprintf(list_file, - "%-9s %8" PRIxPTR " %8lX\n",s->sec_name,s->sec_start-membot,s->sec_length); + "%-9s %8" PRIxPTR " %8" PRIx64 "\n",s->sec_name,s->sec_start-membot,s->sec_length); fprintf(list_file,"---------------------------\n"); } @@ -772,7 +775,7 @@ SECTION *def_section (char *name) if (!stricmp(sec->sec_name,"BSS")) sec->sec_id=-3; if (!stricmp(sec->sec_name,"UDATA")) sec->sec_id=-3; sec->sec_fxref = 0; /* jh was NULL */ - sec->sec_xptr = (long)&sec->sec_fxref; + sec->sec_xptr = (intptr_t)&sec->sec_fxref; app_sec(sec_lptr,sec); return(sec); } @@ -922,7 +925,7 @@ void xref_dir(void) } } *((XREF**)curr_sec->sec_xptr) = x; - curr_sec->sec_xptr = (long)&x->xref_next; + curr_sec->sec_xptr = (intptr_t)&x->xref_next; code_ptr += sy.trunc_rule & 7; if (code_ptr >= memend) halt(1); @@ -1011,7 +1014,7 @@ void chunk(void) { sect_command(); body(); - if (((long)code_ptr&1) && code_ptr>=neustart) + if (((intptr_t)code_ptr&1) && code_ptr>=neustart) { if (code_ptr>=memend) halt(1); *code_ptr++='\0'; @@ -1056,7 +1059,7 @@ void module(void) if (lstng_flag) { if (i++>3) { fprintf(list_file,"\n"); i=0; } - fprintf(list_file," %8.8s=%08lX", + fprintf(list_file," %8.8s=%08" PRId64 "X", sec->sec_name,sec->sec_length-sec->sec_oldlen); } sec->sec_oldlen=sec->sec_length; @@ -1119,8 +1122,8 @@ void calc_xref(XREF *x, char *c, char *modname) if (x->xref_trunc & 32) value -=c-membot; switch(x->xref_trunc & 7) { - case 4 : if (((long)c)&1) halt(1); out_long (c, value); break; - case 2 : if (((long)c)&1) halt(1); out_short (c, value); + case 4 : if (((intptr_t)c)&1) halt(1); out_long (c, value); break; + case 2 : if (((intptr_t)c)&1) halt(1); out_short (c, value); if (x->xref_trunc & 8) { if (value<-32768L || value>32767L) @@ -1711,10 +1714,20 @@ void command_line(int *xac, char ***xav, char **paths, char *lib_arr) char *ldd = getenv("QLLIB"); if(ldd == NULL) { -#if defined(__unix__) || defined(__APPLE__) - ldd = strdup("/usr/local/qdos/lib/"); +#if defined(__unix__) || defined(__APPLE__) || defined(__MINGW32__) +#ifdef PREFIX + char* pfx = XSTR(PREFIX); + if (strlen(pfx) > 0) { + ldd = malloc(strlen(pfx) + 16); + strcpy(ldd, pfx); + strcat(ldd, "/qdos/lib/"); + paths[num_paths++] = ldd; + } +#endif + // fallback + ldd = strdup("/usr/local/qdos/lib/"); #else - ldd = strdup("c:/qllib/"); + ldd = strdup("c:/qllib/"); #endif } { @@ -1799,9 +1812,9 @@ int main(int argc, char **argv) fprintf(list_file,"--------------------\n"); fprintf(list_file, - "Memory Usage = %7ld%%\n",(code_ptr-membot)*100/mem_size); + "Memory Usage = %7" PRId64 "%%\n",(code_ptr-membot)*100/mem_size); fprintf(list_file, - "Buffer Usage = %7ld%%\n",(module_max-module_buffer)*100/buf_size); + "Buffer Usage = %7" PRId64" %%\n",(module_max-module_buffer)*100/buf_size); fprintf(list_file,"--------------------\n"); } list_xsy(xsy_ll,1); diff --git a/sdk-install.sh b/sdk-install.sh new file mode 100755 index 0000000..8cc8ebf --- /dev/null +++ b/sdk-install.sh @@ -0,0 +1,87 @@ +#!/usr/bin/env bash + +# Install header files to /usr/local/qdos/include and sub-directories +# Install libraries to /usr/local/qdos/lib +# This script will find the relevant files under ./, in the format +# from the original distribution runtime disk 1 + + +[ -n "$prefix" ] && PREFIX=$prefix +PREFIX=${PREFIX:-/usr/local} +INSBIN= +BINDIR= +for L +do + case $L in + -e) + INSBIN=1 + ;; + *[\\/]*) + PREFIX=$L + ;; + *) + echo "install.sh [-e] [base directory] [-h]" + echo " -e install binaries as well as include and libraries" + exit + ;; + esac +done +BINDIR=${BINDIR:-$PREFIX/bin} + +if [ ! -w $PREFIX ] ; then + if [ $(id -u) -ne 0 ] ; then + if which sudo >/dev/null 2>&1 ; then + exec sudo $0 $* + else + echo "No sudo found, please run ./install.sh as root if necessary" + [ -r $PREFIX ] || exit 1 + fi + fi +fi +CP="cp -v" + +mkdir -p $PREFIX/qdos/include/sys +mkdir -p $PREFIX/qdos/include/netinet/ +mkdir -p $PREFIX/qdos/include/arpa/ +mkdir -p $PREFIX/qdos/lib +mkdir -p $PREFIX/qdos/etc +[ -f support/ql.mak ] && $CP support/ql.mak $PREFIX/qdos/etc + +if [ -n "$INSBIN" ] ; then + mkdir -p $BINDIR + for B in as68/as68 c68/c68 cc/qcc cpp/qcpp ld/qld slb/slb slb/qdos-ar slb/qdos-ranlib + do + $CP $B $BINDIR + done +fi + +while read FILE +do + FN=$(echo $FILE | tr [:upper:] [:lower:]) + case $FN in + */include_*) + IFILE=${FN##*include_} + case $IFILE in + sys_*) + SIFILE=${IFILE##*sys_} + $CP $FILE $PREFIX/qdos/include/sys/$SIFILE + ;; + netinet_*) + SIFILE=${IFILE##*netinet_} + $CP $FILE $PREFIX/qdos/include/netinet/$SIFILE + ;; + arpa_*) + SIFILE=${IFILE##*arpa_} + $CP $FILE $PREFIX/qdos/include/arpa/$SIFILE + ;; + *) + $CP $FILE $PREFIX/qdos/include/$IFILE + ;; + esac + ;; + */lib_*) + LFILE=${FN##*lib_} + $CP $FILE $PREFIX/qdos/lib/$LFILE + ;; + esac +done < <(find . -iname include_\* -o -iname lib_\*) diff --git a/slb/Makefile b/slb/Makefile index 6c42088..9f2d117 100644 --- a/slb/Makefile +++ b/slb/Makefile @@ -54,5 +54,5 @@ slbdis.$O : slb.h slbrefs.$O : slb.h install: $(PROG) qdos-ar qdos-ranlib - install -d $(prefix) - install $^ $(prefix) + install -d $(prefix)/bin + install $^ $(prefix)/bin diff --git a/slb/slbdis.c b/slb/slbdis.c index 3385fe6..83100b5 100644 --- a/slb/slbdis.c +++ b/slb/slbdis.c @@ -36,7 +36,18 @@ #include "slb.h" #include -#include +#include +#ifndef WIN32 +#include +#else +static uint16_t bswap_16(uint16_t val) { + return (uint16_t)(val << 8) + (val >> 8); +} +static uint32_t bswap_32(uint32_t val) { + return (uint32_t)(((uint32_t)bswap_16(val & 0xffff) << 16) | + (uint32_t)bswap_16(val >> 16)); +} +#endif PRIVATE short gword _PROTOTYPE((void)); PRIVATE long glong _PROTOTYPE((void)); @@ -248,7 +259,7 @@ short gword() DBG(("GWORD",0x1001,"enter:")); reply = (short)get_data(2); - reply = ntohs(reply); + reply = bswap_16(reply); gaddr += 2; DBG(("GWORD",0x1001,"Exit: reply=%04.4x",reply)); return (reply); @@ -266,7 +277,7 @@ long glong() DBG(("GLONG",0x1001,"Enter:")); reply = get_data(4); - reply = ntohl(reply); + reply = bswap_32(reply); gaddr += 4; DBG(("GLONG",0x1001,"Exit: reply=%08.8c",reply)); return (reply); diff --git a/tools/Makefile b/tools/Makefile index 214bf15..4103fbf 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -15,5 +15,5 @@ clean: rm -f qls qcp install: qls qcp - install -d $(prefix) - install qls qcp $(prefix) + install -d $(prefix)/bin + install qls qcp $(prefix)/bin From 12ae0e6440e37f7e72272f3ab344b79387d50737 Mon Sep 17 00:00:00 2001 From: Jonathan Hudson Date: Sun, 28 Aug 2022 17:57:27 +0100 Subject: [PATCH 2/6] remove legacy makefiles --- as68/Makefile.NT | 52 ------- as68/Makefile.qdos | 52 ------- c68/Makefile.dist | 355 --------------------------------------------- cpp/Makefile.NT | 25 ---- cpp/Makefile.orig | 18 --- ld/Makefile.NT | 33 ----- ld/Makefile.orig | 133 ----------------- 7 files changed, 668 deletions(-) delete mode 100644 as68/Makefile.NT delete mode 100644 as68/Makefile.qdos delete mode 100644 c68/Makefile.dist delete mode 100644 cpp/Makefile.NT delete mode 100644 cpp/Makefile.orig delete mode 100644 ld/Makefile.NT delete mode 100644 ld/Makefile.orig diff --git a/as68/Makefile.NT b/as68/Makefile.NT deleted file mode 100644 index a5d40df..0000000 --- a/as68/Makefile.NT +++ /dev/null @@ -1,52 +0,0 @@ -.OPTIMIZE - -COS = nt -LOS = nt -BIN = e:\bin\ - -XTCFLAGS = -dDOS_LIKE -dLABELDIFF -dUSE_LINE -dMINIX -DLITTLE_ENDIAN -DXTC68 -CFLAGS = -w4 -e25 -zp4 -zq -oneatx -5 -bt=$(COS) -LDFLAGS = SYS $(LOS) op st=20000 op maxe=25 op q - -SD = ..\ - -CC = wcc386 -LD = wlink - -OBJS = cbuf.obj cpy.obj gen.obj hdr.obj lex.obj main.obj ops.obj & - opt.obj parse.obj pass.obj scan.obj sym.obj cross.obj - -.h: $(SD) -.c: $(SD) -.c.obj : - $(cc) $[* $(CFLAGS) $(XTCFLAGS) - -all: $(BIN)as68.exe - -$(BIN)as68.exe: $(OBJS) - @%write as68.lnk NAME $(BIN)as68 - @%append as68.lnk FIL cbuf.obj,cpy.obj,gen.obj,hdr.obj,lex.obj,main.obj,ops.obj,& - opt.obj,parse.obj,pass.obj,scan.obj,sym.obj,cross.obj - @%append as68.lnk - $(LD) $(LDFLAGS) @as68.lnk - del as68.lnk - -cbuf.obj: cbuf.c jas.h -cpy.obj: cpy.c jas.h -gen.obj: gen.c jas.h -hdr.obj: hdr.c jas.h -lex.obj: lex.c jas.h scan.h parse.h -main.obj: main.c jas.h -ops.obj: ops.c jas.h opcodes.h -opt.obj: opt.c jas.h -parse.obj: parse.c jas.h parse.h -pass.obj: pass.c jas.h -scan.obj: scan.c jas.h scan.h parse.h -sym.obj: sym.c jas.h - - - - - - - diff --git a/as68/Makefile.qdos b/as68/Makefile.qdos deleted file mode 100644 index 596ce99..0000000 --- a/as68/Makefile.qdos +++ /dev/null @@ -1,52 +0,0 @@ -# Makefile for AS68 assembler -# -# The following special options can be used for CFLAGS -# -DUNIXHOST if you want to include an extra module that makes the -# assembler independent of whether your machine -# is Big-Endian or Little-Endian -# -DQDOS To produce SROFF format object files -# -DMINIX To support Minix ACK assembler syntax -# -DGENERIC To remove various "tidy up" type changes -# -DLABELDIFF To support 'label-label' as a valid operand. Both -# operands must be in the same source file and the same -# segment as this is 'quick hack' implementation - -CC = cc -CFLAGS = -c -Qmaxerr=1 -Qwarn=4 -DQDOS -DMINIX -DLABELDIFF -# CFLAGS = -c -O -Qmaxerr=1 -Qwarn=4 -DQDOS -DMINIX -DLABELDIFF -Qstackcheck - -LD = ld -LDFLAGS = -bufp80k - -RM = rm - -CFILES = cbuf_c cpy_c gen_c hdr_c lex_c main_c \ - ops_c opt_c parse_c pass_c scan_c sym_c cross_c - -# Add cross_o to object files if -DUNIXHOST added to CFLAGS above - -OFILES = cbuf_o cpy_o gen_o hdr_o lex_o main_o \ - ops_o opt_o parse_o pass_o scan_o sym_o - -as68: $(OFILES) - ${LD} ${LDFLAGS} -o$Cas68 $(OFILES) - -_c_o: - ${CC} -Qstackopt=3 ${CFLAGS} $< - -clean: - $(RM) -f *_o *_i *_s - -clobber: clean - $(RM) -f as68 - -#---------------------- Header file dependencies -------------------- - -${OFILES} : jas_h - -lex_o : scan_h parse_h -ops_o : opcodes_h -parse_o : parse_h -scan_o : scan_h parse_h - - diff --git a/c68/Makefile.dist b/c68/Makefile.dist deleted file mode 100644 index c686901..0000000 --- a/c68/Makefile.dist +++ /dev/null @@ -1,355 +0,0 @@ -# Makefile for c68 and c386 -# -# N.B. Some modules will generate empty source files -# according to the #define statements in config.h -# -# As well as entries for c68 and c386, there are also -# entries for the compilers that are typically used to -# boot the c68/c386 compilers for the first time. - -RM=rm -f -#CFLGS= -g -CFLGS= -DNDEBUG -O - -# cxref flags -CXFLAGS=-d -l -s - -# indent flags -INDENTFLAGS= -bad -br -ce -di8 -i4 -npsl \ - -TADDRESS -TAMODE -TBITSIZE -TBLOCK -TBOOL -TBTYPE -TCHAR -TCODE \ - -TCONDITION -TCSE -TDEEP -TEXPR -TEXPRTYPE -TFLAGS -TILEN \ - -TIVAL -TLABEL -TLEVEL -TLINE -TMODEL -TMSGNUM -TOPCODE -TOPTENUM \ - -TOPTION -TOPTIONS -TPEEPFLAGS -TPEEPINFO -TQUALIFIER -TRANGE \ - -TREG -TREGBITMAP -TREGLIST -TREGMASK -TREGTYPE -TREGUSAGE -TRVAL \ - -TSEQNUM -TSIZE -TSTATE -TSTATUS -TSTMT -TSTMTTYPE -TSTORAGE \ - -TSTRING -TSWITCH -TSYM -TTABLE -TTARGET -TTOKEN -TTYP -TUSES -TUVAL \ - -TVISIBILITY - -# File suffix seperator -S=. -# Object file extension -O=o - -PROG=c68 - -#------------------------------------------------------------------------------ -# Use the following if compiling c68/c386 with c68 on Minix -# CCFLAGS= -Qwarn=8 -Qerror=3 -Qstackopt=3 -D__STDC__=1 -# LDFLAGS= -m250000 -#------------------------------------------------------------------------------ -# Use the following if compiling c68/c386 with c386 on Minix -# CCFLAGS= -Qwarn=8 -Qerror=3 -Qstackopt=3 -D__STDC__=1 -# LDFLAGS= -m250000 -#------------------------------------------------------------------------------ -# Use the following if compiling c68 with ACK (68k version) -# CCFLAGS= -# LDFLAGS= -m250000 -#------------------------------------------------------------------------------ -# Use the following if compiling c68/c386 with GNU C on Minix -# CCFLAGS= -Wall -ansi -pedantic -Wshadow -Wpointer-arith \ -# -Wwrite-strings -Wcast-qual -Wwrite-strings -Wcast-align \ -# -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations \ -# -Wredundant-decls -Wnested-externs -# LDFLAGS= -s -m250000 -#------------------------------------------------------------------------------ -# Use the following if compiling c386 with bcc on Minix -# CCFLAGS= -# LDFLAGS= -#------------------------------------------------------------------------------ -# Use the following if compiling c68 with c68 on QDOS -CCFLAGS= -Qmaxerr=3 -Qwarn=8 -Qerror=3 -Qstackopt=maximum -LDFLAGS = -bufp300K -ms -S=_ -#------------------------------------------------------------------------------ -# Use the following if compiling c86 with TopSpeed on DOS -# and then do -# MAKE sibo to build both versions -# MAKE c86check to build code checking only version -# MAKE c86code to build code check and generation version -#CC=tsc /zq /fpC86.PR -#O=obj -#RM=del -#------------------------------------------------------------------------------ -# Use the following if compiling c86 with GNU C -# CCFLAGS= -Wall -ansi -pedantic -Wshadow -Wpointer-arith \ -# -Wwrite-strings -Wcast-qual -Wwrite-strings -Wcast-align \ -# -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations \ -# -Wredundant-decls -Wnested-externs -#------------------------------------------------------------------------------ -CFLAGS=$(CCFLAGS) $(CFLGS) - -#------------------------------------------------------------------------------ -# Source files common to all versions of c68/c386 -SRC1 = analyze$(S)c cglbdef$(S)c cmain$(S)c decl$(S)c expr$(S)c extern$(S)c -SRC2 = genicode$(S)c genstmt$(S)c genutil$(S)c getsym$(S)c init$(S)c -SRC3 = intexpr$(S)c list$(S)c memmgt$(S)c msgout$(S)c optimize$(S)c -SRC4 = outgen$(S)c stmt$(S)c symbol$(S)c system$(S)c types$(S)c -SRC = $(SRC1) $(SRC2) $(SRC3) $(SRC4) - -HDR = chdr$(S)h cglbdec$(S)h config$(S)h expr$(S)h message$(S)h \ - outproto$(S)h version$(S)h proto$(S)h check$(S)h - -# Source files specific to c68 680X0 versions -SRC68K =flow68k$(S)c gen68k$(S)c genffp$(S)c genieee$(S)c peep68k$(S)c\ - out68k_a$(S)c out68k_c$(S)c out68k_g$(S)c out68k_q$(S)c reg68k$(S)c -HDR68K =gen68k$(S)h - -# Source files specific to INTEL versions -SRCX86 =peepx86$(S)c regx86$(S)c \ - outx86_a$(S)c outx86_b$(S)c outx86_g$(S)c outx86_n$(S)c outx86_s$(S)c -HDRX86 =genx86$(S)h - -# Source files specific to c386 INTEL 386 versions -SRC386 =gen386$(S)c -HDR386 =gen386$(S)h - -# Source files specific to c386 INTEL 386 versions -SRC86 =gen86$(S)c -HDR86 =gen86$(S)h - -# Source files specific to carm ARM versions -SRCARM =genarm$(S)c peeparm$(S)c outarm_o$(S)c regarm$(S)c -HDRARM =genarm$(S)h - -# Source files specific to c30 TI TMS320C30 versions -SRCC30 =flowc30$(S)c genc30$(S)c peepc30$(S)c outc30_r$(S)c regc30$(S)c -HDRC30 =genc30$(S)h - -# Source files specific to PowerPC versions -SRCPPC =genppc$(S)c peepppc$(S)c outppc$(S)c regppc$(S)c -HDRPPC =genppc$(S)h - -# Source files specific to the EPOC build enviroment -SRCEPOC=c86$(S)c c86$(S)pic c86$(S)afl c86$(S)shd c86$(S)pr \ - config$(S)chk config$(S)gen config$(S)bat - -# Extra files -SRCEXTR=cmains$(S)c c86${S}dsw c86${S}dsp c68${S}dsw c68${S}dsp \ - config$(S)c86 config${S}c68 config$(S)txt - -#------------------------------------------------------------------------------ -# Object files common to all c68/c386 variants -OBJ = analyze$(S)$(O) cglbdef$(S)$(O) cmain$(S)$(O) decl$(S)$(O) expr$(S)$(O) extern$(S)$(O) \ - genicode$(S)$(O) genstmt$(S)$(O) genutil$(S)$(O) getsym$(S)$(O) init$(S)$(O) \ - intexpr$(S)$(O) list$(S)$(O) memmgt$(S)$(O) msgout$(S)$(O) optimize$(S)$(O) \ - outgen$(S)$(O) stmt$(S)$(O) symbol$(S)$(O) system$(S)$(O) types$(S)$(O) - -# Object files specific to Motorola 680X0 variants -OBJ68K =flow68k$(S)$(O) gen68k$(S)$(O) genffp$(S)$(O) genieee$(S)$(O) \ - peep68k$(S)$(O) out68k_a$(S)$(O) out68k_c$(S)$(O) out68k_g$(S)$(O) \ - out68k_q$(S)$(O) reg68k$(S)$(O) - -# Object files specific to INTEL variants -OBJX86 =peepx86$(S)$(O) regx86$(S)$(O) \ - outx86_a$(S)$(O) outx86_b$(S)$(O) outx86_g$(S)$(O) \ - outx86_n$(S)$(O) outx86_s$(S)$(O) - -# Object files specific to INTEL 386 variants -OBJ386 =gen386$(S)$(O) - -# Object files specific to INTEL 86 variants -OBJ86 =gen86$(S)$(O) - -# Object files specific to ARM variants -OBJARM =genarm$(S)$(O) peeparm$(S)$(O) outarm_o$(S)$(O) regarm$(S)$(O) - -# Object files specific to TI TMS320C30 versions -OBJC30 =flowc30$(S)$(O) genc30$(S)$(O) peepc30$(S)$(O) outc30_r$(S)$(O) \ - regc30$(S)$(O) - -# Object files specific to PowerPC versions -OBJPPC =genppc$(S)$(O) peepppc$(S)$(O) outppc$(S)$(O) regppc$(S)$(O) - -# All object files -OBJS =$(OBJ) $(OBJ68K) $(OBJX86) $(OBJ386) $(OBJ86) $(OBJARM) $(OBJC30) \ - $(OBJPPC) - -#------------------------------------------------------------------------------ -# The following is only required if your library does not -# already contain this routine. -# SRCLIB = vfprintf$(S)c -# OBJLIB = vfprintf$(S)o -# Use this setting if you already have vfprintf -SRCLIB = -OBJLIB = - -#------------------------------------------------------------------------------ -LNS =$(OBJS:.o=.ln) -CXS =$(OBJS:.o=.cx) - -.SUFFIXES: $(S)ln $(S)cx $(S)obj - -#------------------------------------------------------------------------------ -all: $(PROG) - -$(S)c$(S)obj: - $(CC) $(CFLAGS) $* - -$(S)c$(S)ln: - lint $(CFLAGS) -m -u -c $< - -$(S)c$(S)cx: - cxref $(CXFLAGS) -C $< - -$(PROG): $(OBJS) - $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIB) - -$(OBJ): $(HDR) -$(OBJ68K): $(HDR) $(HDR68K) -$(OBJX86): $(HDR) $(HDR86) $(HDRX86) -$(OBJ386): $(HDR) $(HDR386) $(HDRX86) -$(OBJ86): $(HDR) $(HDR86) $(HDRX86) -$(OBJARM): $(HDR) $(HDRASM) -$(OBJC30): $(HDR) $(HDRC30) -$(OBJPPC): $(HDR) $(HDRPPC) - -lint: $(LNS) - lint $(LNS) - -lclint: - lclint $(SRC) - -cxref: $(CXS) - cxref $(CXFLAGS) -c $(CXS) - -clobber: clean - $(RM) $(PROG) - $(RM) *$(S)exe - $(RM) *$(S)img -clean: - $(RM) *$(S)cx - $(RM) *$(S)ln - $(RM) *$(S)$(O) - $(RM) *$(S)i - $(RM) *$(S)s - $(RM) *$(S)uue - $(RM) *$(S)rs? - $(RM) *$(S)rzc - -#------------------------------------------------------------------------------ -# Special section to handle building programs -# under the SIBO SDK (TopSpeed) compiler on DOS -# This uses completely different syntax to virtually -# all the other options. - -TSOBJS =$(OBJ) $(OBJX86) $(OBJ86) - -sibo: c86check.img c86code.img -c86code: c86code.img -c86check: c86check.img - -c86check.img : checkok c86.rss $(TSOBJS) - tsc /m c86 - copy c86.img c86check.img - -c86code.img : codeok c86.rss $(TSOBJS) - tsc /m c86 - copy c86.img c86code.img -checkok: - config config.chk -codeok: - config config.gen - -c86.rss : c86.c message.h config.h - $(RM) c86.i - $(RM) c86.rss - tsc c86.c /option(pre_proc=on) /zq - mv c86.i c86.rss - rcomp16 c86.rss - rchuf hwim -v -ic86.rsc - -#------------------------------------------------------------------------------ -# reformat source files to ensure consistant style -indent: - @for file in $(SRC) $(SRC68K) $(SRCX86) $(SRC386) \ - $(SRC86) $(SRCARM) $(SRCC30) $(SRCPPC) \ - $(HDR) $(HDR68K) $(HDRX86) $(HDR386) $(HDR86) \ - $(HDRARM) $(HDRC30) $(HDRPPC) ; do \ - echo $$file:; \ - indent $(INDENTFLAGS) $$file && rm $$file~; \ - done - -#------------------------------------------------------------------------------ -# build the whole compiler as one huge .c file. This can make the -# resulting binary smaller on some systems. -c68s: $(SRC) $(HDR) $(HDR68K) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ cmains$(S)c $(LIB) - -#------------------------------------------------------------------------------ -# updating david via email -david: zip - uuencode $(PROG)src$(S)zip $(PROG)src$(S)zip \ - | mail -s "Latest $(PROG)" d.j.walker@x400.icl.co.uk - rm -f $(PROG)src$(S)zip - -#------------------------------------------------------------------------------ -# putting source on floppy to take home -home: - tar cvf /var/tmp/$(PROG)$(S)tar \ - Makefile $(SRCEPOC) \ - $(SRC) $(SRC68K) $(SRCX86) $(SRC386) $(SRC86) $(SRCARM) $(SRCC30) \ - $(SRCPPC) $(SRCEXTR) \ - $(HDR) $(HDR68K) $(HDRX86) $(HDR386) $(HDR86) $(HDRARM) $(HDRC30) \ - $(HDRPPC) - gzip /var/tmp/$(PROG)$(S)tar - rcp /var/tmp/$(PROG)$(S)tar$(S)gz melody:/var/tmp/$(PROG)$(S)tgz - rm /var/tmp/$(PROG)$(S)tar$(S)gz - rsh melody dd if=/var/tmp/$(PROG)$(S)tgz of=/dev/rdsk/f03ht bs=18k - rsh melody rm /var/tmp/$(PROG)$(S)tgz - -#------------------------------------------------------------------------------ -# putting source on floppy -floppy: - tar zcvf /dev/fd0 \ - Makefile $(SRCEPOC) \ - $(SRC) $(SRC68K) $(SRCX86) $(SRC386) $(SRC86) $(SRCARM) $(SRCC30) \ - $(SRCPPC) $(SRCEXTR) \ - $(HDR) $(HDR68K) $(HDRX86) $(HDR386) $(HDR86) $(HDRARM) $(HDRC30) \ - $(HDRPPC) - -#------------------------------------------------------------------------------ -# putting source on 720K floppies to transfer to Atari ST minix system -floppy720: - tar cvf /dev/fd0 [a-fh-o]??*$(S)c ???*$(S)h c86$(S)* - @echo -n "Insert 2nd diskette:"; read DUMMY - tar cvf /dev/fd0 [g]??*$(S)c - @echo -n "Insert 3nd diskette:"; read DUMMY - tar cvf /dev/fd0 [p-z]??*$(S)c - -#------------------------------------------------------------------------------ -# creating a uuencoded gziped tar archive -tar: - tar cvf $(PROG)$(S)tar Makefile $(SRCEPOC) \ - $(SRC) $(SRC68K) $(SRCX86) $(SRC386) $(SRC86) $(SRCARM) $(SRCC30) \ - $(SRCPPC) $(SRCEXTR) \ - $(HDR) $(HDR68K) $(HDRX86) $(HDR386) $(HDR86) $(HDRARM) $(HDRC30) \ - $(HDRPPC) - gzip $(PROG)$(S)tar - uuencode $(PROG)$(S)tar$(S)gz $(PROG)$(S)tgz >$(PROG)$(S)uue - rm -f $(PROG)$(S)tar$(S)gz - -#------------------------------------------------------------------------------ -# creating a zip archive -zip: - zip $(PROG)src$(S)zip Makefile $(SRCEPOC) \ - $(SRC) $(SRC68K) $(SRCX86) $(SRC386) $(SRC86) $(SRCARM) $(SRCC30) \ - $(SRCPPC) $(SRCEXTR) \ - $(HDR) $(HDR68K) $(HDRX86) $(HDR386) $(HDR86) $(HDRARM) $(HDRC30) \ - $(HDRPPC) - -#------------------------------------------------------------------------------ -# creating a pkzip archive -# (because of limitations on command line length -# we have to build up the archive in bits!) -pkzip: - pkzip $(PROG)src$(S)zip Makefile $(SRC1) - pkzip $(PROG)src$(S)zip $(SRC2) - pkzip $(PROG)src$(S)zip $(SRC3) - pkzip $(PROG)src$(S)zip $(SRC4) - pkzip $(PROG)src$(S)zip $(SRC68K) - pkzip $(PROG)src$(S)zip $(SRCX86) $(SRC386) $(SRC86) - pkzip $(PROG)src$(S)zip $(SRCARM) $(SRCC30) $(SRCPPC) - pkzip $(PROG)src$(S)zip $(SRCEXTR) $(SRCEPOC) - pkzip $(PROG)src$(S)zip $(HDR) - pkzip $(PROG)src$(S)zip $(HDR68K) $(HDRX86) $(HDR386) $(HDR86) $(HDRARM) $(HDRC30) $(HDRPPC) - diff --git a/cpp/Makefile.NT b/cpp/Makefile.NT deleted file mode 100644 index 50ef0f8..0000000 --- a/cpp/Makefile.NT +++ /dev/null @@ -1,25 +0,0 @@ -.OPTIMIZE - -COS = nt -LOS = nt -BIN = e:\bin\ - -APFLAGS= -dXTC68 -dDOS_LIKE -CFLAGS = -j -w4 -e25 -zp4 -zq -oneatx -5 -bt=$(COS) -LDFLAGS = SYS $(LOS) op st=8192 op maxe=25 op q - -SD = ..\ - -CC = wcc386 -LD = wlink - -OBJS= version.obj cexp.obj cccp.obj alloca.obj - -.c: $(SD) -.c.obj : - $(cc) $[* $(CFLAGS) $(APFLAGS) - -$(BIN)cpp.exe: $(OBJS) - $(ld) $(ldflags) name $(BIN)cpp.exe file version.obj,cexp.obj,cccp.obj,alloca.obj - - diff --git a/cpp/Makefile.orig b/cpp/Makefile.orig deleted file mode 100644 index 2768335..0000000 --- a/cpp/Makefile.orig +++ /dev/null @@ -1,18 +0,0 @@ -# Makefile for GNU CPP -CC= cc -RM= rm - -CFLAGS= -O -maxerr=1 -warn=3 -DGPLUSPLUS_INCLUDE_DIR="" -DGCC_INCLUDE_DIR="" -DSTDC_VALUE=1 -LDFLAGS= -bufp100k - -SRCS= alloca_c version_c cexp_c cccp_c -OBJS= alloca_o version_o cexp_o cccp_o - -cpp: $(OBJS) - ${CC} -ocpp $(LDFLAGS) $(OBJS) - -clean: - @${RM} -fv ${OBJS} - -clobber : clean - @${RM} -fv cpp diff --git a/ld/Makefile.NT b/ld/Makefile.NT deleted file mode 100644 index 0165854..0000000 --- a/ld/Makefile.NT +++ /dev/null @@ -1,33 +0,0 @@ -.OPTIMIZE - -COS = nt -LOS = nt -BIN = e:\bin\ - -APFLAG = -dXTC68 -dDOS_LIKE -CFLAGS = -j -w4 -e25 -zp4 -zq -oneatx -5 -bt=$(COS) -LDFLAGS = SYS $(LOS) op st=20000 op maxe=25 op q - -SD = ..\ - -CC = wcc386 -LD = wlink - -# -OBJS = ld.obj - -.c: $(SD) -.c.obj : - $(cc) $[* $(CFLAGS) $(APFLAG) - -all: $(BIN)ld.exe - -ld.obj : $(SD)ld.c - -$(BIN)ld.exe: $(OBJS) - $(ld) $(ldflags) name $(BIN)qld.exe file ld.obj - - - - - diff --git a/ld/Makefile.orig b/ld/Makefile.orig deleted file mode 100644 index 2233006..0000000 --- a/ld/Makefile.orig +++ /dev/null @@ -1,133 +0,0 @@ -# -# Makefile for C68 LD command -# -# Choose the appropriate set up to suit your system -# -#------------------------------------------------------------ -# ... for compiling with C68 on QDOS -CC = cc -CFLAGS = -Qerror=5 -Qwarn=5 -maxerr=5 -O -LDFLAGS= -bufp120k -bufl50k -m -LDLIBS= -CFLAGS = -Qerror=5 -Qwarn=5 -maxerr=5 -O -DLIBDEBUG -LDLIBS= -ldebug -I = ${P}INCLUDE_ -S = _ -O = o -#------------------------------------------------------------ -# .. for compiling with MINIX-68K -# CC = cc68 -# CFLAGS = -Werror=5 -Qwarn=6 -maxerr=5 -D_MINIX -I../ -O -# LDFLAGS = -# LDLIBS= -# I = /usr/include/ -# S = . -# O = o -#------------------------------------------------------------ -# .. for compiling with MINIX-PC -# CC = cc -# CFLAGS = -F -D_MINIX -I../ -# LDFLAGS = -i -# LDLIBS= -# I = /usr/include/ -# S = . -# O = s -#------------------------------------------------------------ -# .. for compiling with MINIX-386 and GNU C -# CC = gcc -# CFLAGS = -D_MINIX -I../ -I/usr/include -I../include -O -# LDFLAGS = -# LDLIBS= -# I = /usr/include/ -# S = . -# O = o -#------------------------------------------------------------ -# .. for compiling with MINIX-386 and Bruce Evans BCC -# CC = bcc -# CFLAGS = -D_MINIX -I../ -O -# LDFLAGS = -# LDLIBS= -# I = /usr/include/ -# S = . -# O = o -#------------------------------------------------------------ -# .. for compiling with MINIX-386 and c386 -# CC = gcc -# CFLAGS = -Qerror=5 -Qwarn=6 -Qmaxerr=5 -D_MINIX -I../ -O -# LDFLAGS = -# LDLIBS= -# I = /usr/include/ -# S = . -# O = o -#------------------------------------------------------------ -# .. for compiling with LINUX-386 -# CC = gcc -# CFLAGS = -D_MINIX -I../ -O -# LDFLAGS = -# LDLIBS= -# I = /usr/include/ -# S = . -# O = o -#------------------------------------------------------------ -# .. for compiling with UNIX SVR4 -# CC = cc -# CFLAGS = -c -D_MINIX -DSYSV -I../include -# LDFLAGS = -# LDLIBS= -# I = /usr/include/ -# S = . -# O = o -# LINTFLAGS = -m -x -#------------------------------------------------------------ - -LD = ld -RM = rm -CP = cp - -OBJS = ldmain${S}${O} ldparams${S}${O} ldlist${S}${O} \ - ldqdos${S}${O} ldrll${S}${O} ldsroff${S}${O} ldutils${S}${O} - -LOBJ = ldmain$Sln ldparams$Sln ldlist$Sln \ - ldqdos$Sln ldrll$Sln ldsroff$Sln ldutils$Sln - -.SUFFIXES : ${S}x ${S}s ${S}asm ${S}o ${S}rel ${S}hdr ${S}h - -all : ${OBJS} - ${CC} ${LDFLAGS} -o ld ${OBJS} ${LDLIBS} - -${S}hdr${S}h : - packhdr $*${S}hdr $*${S}h - -${S}c${S}ln: - lint ${CFLAGS} -x ${DEFINES} $< >>ld${S}lint 2>&1 - -lint :lint2 ${LOBJ} - lint ${LOBJ} ${LINTFLAGS} >>ld$Slint 2>&1 - -clean: - ${RM} -f *$S$O *$Si *$Ss *$Sln - -clobber: clean - ${RM} -f ld - -#---------------------- Header file dependencies -------------------------- - -ld${S}h : ${I}ctype${S}h ${I}errno${S}h \ - ${I}fcntl${S}h \ - ${I}stdlib${S}h ${I}stdio${S}h \ - ${I}string$Sh \ - ${I}qdos$Sh \ - ldconfig${S}h ldmsgs${S}h - touch ld$Sh - -${OBJS} : ld$Sh -${LOBJ} : ld$Sh - -ldsroff${S}c : ${I}sroff${S}h - touch ldsroff${S}c -ldqdos${S}c : ${I}rll${S}h -ldrll${S}c : ${I}rll${S}h - touch ldrll${S}c -ldutils${S}c : ldmsgs${S}h - touch ldutils${S}c - From 239fa9ac2b07076554e5c156ec01519e8802f29e Mon Sep 17 00:00:00 2001 From: Jonathan Hudson Date: Sun, 28 Aug 2022 18:37:22 +0100 Subject: [PATCH 3/6] add swap function for clang --- slb/slbdis.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/slb/slbdis.c b/slb/slbdis.c index 83100b5..45a8732 100644 --- a/slb/slbdis.c +++ b/slb/slbdis.c @@ -37,9 +37,8 @@ #include "slb.h" #include #include -#ifndef WIN32 -#include -#else + +#if defined(WIN32) || defined(__clang__) static uint16_t bswap_16(uint16_t val) { return (uint16_t)(val << 8) + (val >> 8); } @@ -47,6 +46,8 @@ static uint32_t bswap_32(uint32_t val) { return (uint32_t)(((uint32_t)bswap_16(val & 0xffff) << 16) | (uint32_t)bswap_16(val >> 16)); } +#else +#include #endif PRIVATE short gword _PROTOTYPE((void)); From c488ec0b35f45b7e36c9fb2eef53fd1d955dff7a Mon Sep 17 00:00:00 2001 From: Jonathan Hudson Date: Sun, 28 Aug 2022 19:11:45 +0100 Subject: [PATCH 4/6] find common ground between clang/freebsd, macos and mingw --- ld/ldold.c | 12 ++++++------ slb/slbdis.c | 21 +++++++++------------ 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/ld/ldold.c b/ld/ldold.c index 3d15985..65a073d 100644 --- a/ld/ldold.c +++ b/ld/ldold.c @@ -146,8 +146,8 @@ typedef struct section struct section *sec_next; short sec_id; /* -1 = TEXT, -2 = DATA, -3 = BSS */ char *sec_start; - intptr_t sec_length; - intptr_t sec_oldlen; + long sec_length; + long sec_oldlen; intptr_t sec_fxref; intptr_t sec_xptr; MOD_ITEM *sec_module; /* List of modules contributing to this section */ @@ -325,7 +325,7 @@ void statistic(void) (void) fprintf(list_file,"---------------------------\n"); for (s=sec_liste;s!=NULL;s=s->sec_next) (void) fprintf(list_file, - "%-9s %8" PRIxPTR " %8" PRIx64 "\n",s->sec_name,s->sec_start-membot,s->sec_length); + "%-9s %8" PRIxPTR " %8lx\n",s->sec_name,s->sec_start-membot,s->sec_length); fprintf(list_file,"---------------------------\n"); } @@ -1059,7 +1059,7 @@ void module(void) if (lstng_flag) { if (i++>3) { fprintf(list_file,"\n"); i=0; } - fprintf(list_file," %8.8s=%08" PRId64 "X", + fprintf(list_file," %8.8s=%08lX", sec->sec_name,sec->sec_length-sec->sec_oldlen); } sec->sec_oldlen=sec->sec_length; @@ -1812,9 +1812,9 @@ int main(int argc, char **argv) fprintf(list_file,"--------------------\n"); fprintf(list_file, - "Memory Usage = %7" PRId64 "%%\n",(code_ptr-membot)*100/mem_size); + "Memory Usage = %7ld%%\n",(long)(code_ptr-membot)*100/mem_size); fprintf(list_file, - "Buffer Usage = %7" PRId64" %%\n",(module_max-module_buffer)*100/buf_size); + "Buffer Usage = %7ld%%\n",(long)(module_max-module_buffer)*100/buf_size); fprintf(list_file,"--------------------\n"); } list_xsy(xsy_ll,1); diff --git a/slb/slbdis.c b/slb/slbdis.c index 45a8732..7b2513e 100644 --- a/slb/slbdis.c +++ b/slb/slbdis.c @@ -38,18 +38,6 @@ #include #include -#if defined(WIN32) || defined(__clang__) -static uint16_t bswap_16(uint16_t val) { - return (uint16_t)(val << 8) + (val >> 8); -} -static uint32_t bswap_32(uint32_t val) { - return (uint32_t)(((uint32_t)bswap_16(val & 0xffff) << 16) | - (uint32_t)bswap_16(val >> 16)); -} -#else -#include -#endif - PRIVATE short gword _PROTOTYPE((void)); PRIVATE long glong _PROTOTYPE((void)); PRIVATE void reladdr _PROTOTYPE((char)); @@ -103,6 +91,15 @@ PRIVATE int gisize; PRIVATE long modfstart; /* File position of start of module */ PRIVATE int endflag; +static uint16_t bswap_16(uint16_t val) { + return (uint16_t)(val << 8) + (val >> 8); +} + +static uint32_t bswap_32(uint32_t val) { + return (uint32_t)(((uint32_t)bswap_16(val & 0xffff) << 16) | + (uint32_t)bswap_16(val >> 16)); +} + /*============================================================ CHECK_LABEL */ PRIVATE From b644c885ac53ef3dcdaf75200f8d46794bf209cf Mon Sep 17 00:00:00 2001 From: Jonathan Hudson Date: Sun, 28 Aug 2022 21:19:35 +0100 Subject: [PATCH 5/6] update formats for ia32 as well --- cpp/cccp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/cccp.c b/cpp/cccp.c index cb49654..dcb5e5e 100644 --- a/cpp/cccp.c +++ b/cpp/cccp.c @@ -2904,7 +2904,7 @@ void special_symbol ( HASHNODE *hp, FILE_BUF *op) case T_CONST: buf = (char *) alloca (4 * sizeof (long)); - sprintf (buf, "%" PRId64 , hp->value.ival); + sprintf (buf, "%zd", hp->value.ival); break; case T_SPECLINE: From dcf0a4cfc624dbe93d1c63c19cd59a24880d4553 Mon Sep 17 00:00:00 2001 From: Jonathan Hudson Date: Mon, 29 Aug 2022 14:26:01 +0100 Subject: [PATCH 6/6] rework include and lib search paths, update readme --- Makefile | 8 ++-- README.md | 84 +++++++++++++++++++++++++++++-------- as68/Makefile | 2 +- cc/cc.c | 9 ---- cpp/Makefile | 6 +-- cpp/appdir.c | 46 +++++++++++++++++++++ cpp/cccp.c | 110 ++++++++++++++++++++++++++++--------------------- cpp/config.h | 8 ++-- ld/Makefile | 7 ++-- ld/appdir.c | 46 +++++++++++++++++++++ ld/ldold.c | 90 ++++++++++++++++++++++------------------ sdk-install.sh | 36 +++++----------- slb/Makefile | 6 ++- slb/slbdis.c | 18 ++++---- support/ql.mak | 4 +- tools/Makefile | 9 +++- tools/qcp.c | 35 ++++++---------- tools/qls.c | 33 +++++++-------- 18 files changed, 345 insertions(+), 212 deletions(-) create mode 100644 cpp/appdir.c create mode 100644 ld/appdir.c diff --git a/Makefile b/Makefile index 3f9b3e5..124701f 100644 --- a/Makefile +++ b/Makefile @@ -2,19 +2,19 @@ # Note you can build 32bit binaries on x86-64 by # CFLAGS=-m32 make -DIRS = as68 c68 cc cpp ld slb +DIRS = as68 c68 cc cpp ld slb tools CLEANDIRS = $(DIRS:%=clean-%) INSTALLDIRS = $(DIRS:%=install-%) prefix ?= /usr/local -export prefix - CFLAGS += -Wall -Wextra -pedantic + export CFLAGS +export prefix all: $(DIRS) $(DIRS): - $(MAKE) -C $@ + $(MAKE) -C $@ clean: $(CLEANDIRS) diff --git a/README.md b/README.md index b8efca6..ed0f85c 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,29 @@ xtc68 ===== -Cross compiler for QDOS c68 on POSIX platforms +Cross compiler for QDOS C68 on POSIX platforms (and Windows). -This is a resurrection of the 1999-ish code base to compile on modern POSIX systems (well Linux at least). No effort has gone into updating the obsolete DOS and NT variants. +This is a resurrection of the 1999-ish code base to compile on modern POSIX-like systems. -As of 2021-08-24, the codebase is 64bit clean. There is no longer any requirement to build 32bit executables. +As of 2021-08-24, the codebase is 64bit clean. There is no longer any requirement to build 32bit executables, even on Windows. + +## Installation + +You can either install a [binary distribution](https://github.com/stronnag/xtc68/releases) for Linux, MacOS, Windows or [build from source](#building). For platforms where there is no binary distribution, [build from source](#building) in required. Such platforms are: + +* Anything other than x86_64 (amd64) with Linux, MacOS and Windows. + +The binary installations are tar or Zip files, with the following structure: + +``` +xtc68/bin +xtc68/share/qdos +xtc68/share/qdos/etc +xtc68/share/qdos/include +xtc68/share/qdos/lib +``` + +You should then install a [c68 runtime](#runtime) into the `xtc68/share/qdos/include` (header files) and `xtc68/share/qdos/lib` (libraries and startup files). ## Runtime @@ -16,27 +34,39 @@ qcc -o hw hw.c ``` will generate a QDOS executable, where `hw.c` is a trivial, standard "Hello World" application, assuming the installation directory `$(prefix)/bin` is on `$PATH`. -It is not purpose of this repo to provide a QDOS c68 environemnt, nor does it offer any help for QDOS development; it mere maintains a cross compiler. +Note that it is not purpose of this repository to provide a QDOS C68 development environment, nor does it offer any help for QDOS development; it mere maintains a cross compiler. -## Installation +### Runtime path resolution + +The search path for QDOS header files and libraries is: + +* Under the `share/qdos` directory where `share` is at the same level as the binary `bin` directory (i.e. as distributed binaries) +* Under the directory defined at build time `$prefix/share/qdos`; `prefix` defaults to `/usr/local` for the binary distributions. +* In directories defined by the environment variables `QLINC` (header files) and `QLLIB` (libraries). +* In the fallback directories under `/usr/local/share/qdos` -On most POSIX (like) systems (Linux, *BSD, MacOS, Msys, Cygwin) to build and install the excutables. +So, if you unzip the supplied Windows Zip file to `C:\` (you now have `C:\xtc68` and sub-directories) and then added the C68 header files to `C:\xtc68\share\qdos\include` and the C68 libraries to `C:\xtc68\share\qdos\lib` (i.e. into the default directories the Zip file has conveniently provided), finally add `C:\xtc68\bin` to the `PATH` environment variable; it all should "just work". ``` -# build and install the executables in /usr/local (default) -make && sudo make install -# on *BSD, you need GNU Make -gmake && sudo gmake install +> # Powershell +> # Assume we have a trival "hello world" hw.c +> $env:PATH += "C:\xtc68\bin;" +> qcc -O -o helloworld hw.c +helloworld: dataspace 904 (388) +> ``` -A more modern practice on essentially "sole user" systems is to install under `~/.local`, thusly: +## Building + +On most POSIX (like) systems (Linux, *BSD, MacOS, Msys) to build and install the executables. + +Modern practice on essentially "sole user" systems is to install under `~/.local`, with `~/.local/bin` appended to the `PATH`, so: ``` make install prefix=~/.local # gmake install prefix=~/.local ## FreeBSD et al ``` -`sudo` is then not needed. To install the QDOS includes and libraries ``` @@ -45,22 +75,42 @@ To install the QDOS includes and libraries If the optional directory is omitted, `/usr/local` is assumed. You can also use the environment variable `PREFIX` (or `prefix`) instead. -## Integration with native make (i.e. GNU Make) +If you really want to install in `/usr/local`: + +``` +# build and install the executables in /usr/local (default) +make && sudo make install +# on *BSD, you need GNU Make +gmake && sudo gmake install +sudo ./sdk-install.sh +``` -* The `sdk-install.sh` script provides `ql.mak`, which it will copy to `$PREFIX/qdos/etc/ql.mak` -* In your QDOS project `Makefile`, as the first line: +Note `sudo` is required for a non-root user to install to `/usr/local`. + +## Integration with native make (i.e. GNU Make) +* The `sdk-install.sh` script provides `ql.mak`, which it will copy to `$PREFIX/share/qdos/etc/ql.mak` +* In your QDOS project `Makefile`, as the first line (`.local` prefix install) ``` # local install, alas $$HOME is not expanded here .. - include /home/USERNAME/.local/qdos/etc/ql.mak + include /home/USERNAME/.local/share/qdos/etc/ql.mak ``` - or + + * or ``` # System install include /usr/local/qdos/etc/ql.mak ``` + * or + + ``` + mkdir ~/.config/xtc68 + cp $PREFIX/share/qdos/etc/ql.mak ~/.config/xtc68/ + # then in a Makefile + include /home/USERNAME/.config/xtc68/ql.mak + ``` Now you can easily use GNU Make to build your QDOS project. diff --git a/as68/Makefile b/as68/Makefile index 5854ab8..1c92118 100644 --- a/as68/Makefile +++ b/as68/Makefile @@ -1,7 +1,7 @@ VPATH = ../ GCFLAGS = -O2 -CFLAGS += $(GCFLAGS) -DXTC68 -DLABELDIFF -DUSELINE -DMINIX -DHOST_LITTLE_ENDIAN +CFLAGS += $(GCFLAGS) -DXTC68 -DLABELDIFF -DUSELINE -DMINIX -DHOST_LITTLE_ENDIAN LDFLAGS = OBJS = cbuf.o cpy.o gen.o hdr.o lex.o main.o ops.o \ diff --git a/cc/cc.c b/cc/cc.c index 26b77ab..5d274fb 100644 --- a/cc/cc.c +++ b/cc/cc.c @@ -31,16 +31,7 @@ //#define _GNU_SOURCE #include #include -//#ifdef __FreeBSD__ #include /*(POSIX) */ -//#endif - -#ifdef __APPLE__ -#include -#if TARGET_OS_MAC -#include -#endif /* TARGET_OS_MAC */ -#endif /* __APPLE__ */ #include "cc.h" #ifdef WIN32 diff --git a/cpp/Makefile b/cpp/Makefile index cfe7798..81828ac 100644 --- a/cpp/Makefile +++ b/cpp/Makefile @@ -1,11 +1,11 @@ PROG = qcpp -APFLAGS= -DXTC68 -DCPLUSPLUS +APFLAGS= -DXTC68 -DCPLUSPLUS -CFLAGS += -O2 $(APFLAGS) -DPREFIX="$(prefix)" +CFLAGS += -O2 $(APFLAGS) -DPREFIX="$(prefix)" LDFLAGS = -OBJ = version.o cexp.o cccp.o +OBJ = version.o cexp.o cccp.o appdir.o all: $(PROG) diff --git a/cpp/appdir.c b/cpp/appdir.c new file mode 100644 index 0000000..124b1e1 --- /dev/null +++ b/cpp/appdir.c @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include +#include +#include + +#if defined(WIN32) +#include +#elif defined(__APPLE__) +#include +#endif + +char *get_binary_path(void) { + char *dest = calloc(1,PATH_MAX); + uint32_t size; +#if defined(__linux__) + realpath("/proc/self/exe", dest); +#elif defined(WIN32) + GetModuleFileName(NULL, dest, PATH_MAX); +#elif defined(__APPLE__) + size = PATH_MAX; + _NSGetExecutablePath(dest, &size); +#elif defined(__FreeBSD__) + realpath("/proc/curproc/file", dest); +#endif + size = strlen(dest); + if(size > 0) { + return dest; + } else { + free(dest); + return NULL; + } +} + +#ifdef APPDIR_TEST +int main(int argc, char **argv) { + char* p = get_binary_path(); + if(p != NULL) { + printf("Path = %s\n", dirname(p)); + free(p); + } + return 0; +} +#endif diff --git a/cpp/cccp.c b/cpp/cccp.c index dcb5e5e..e22b3cc 100644 --- a/cpp/cccp.c +++ b/cpp/cccp.c @@ -45,6 +45,9 @@ typedef unsigned char U_CHAR; #include #include #include +#include +#include + /* VMS-specific definitions */ #ifdef VMS @@ -66,6 +69,10 @@ typedef unsigned char U_CHAR; #endif #include /* This defines "errno" properly */ +#ifdef XTC68 +extern char* get_binary_path(); +#endif + #ifndef O_RDONLY #define O_RDONLY 0 #endif @@ -228,7 +235,9 @@ struct file_name_list struct file_name_list include_defaults[] = { #ifdef XTC68 - { &include_defaults[1], GCC_INCLUDE_DIR }, + { 0, "" }, + { 0, "" }, + { 0, "" }, { 0, "" }, { 0, "" } #else @@ -879,11 +888,14 @@ void deps_output (char *string, long size) deps_buffer[deps_size] = 0; } -int -main (argc, argv) - int argc; - char **argv; -{ +void remove_trailing_slash(char *fname) { + int n = strlen(fname); + if (*(fname + n -1) == '/' || *(fname + n -1) == '\\') { + *(fname + n -1) = 0; + } +} + +int main (int argc, char **argv) { long st_mode = 0; long st_size = 0; char *in_fname, *out_fname; @@ -1006,56 +1018,60 @@ main (argc, argv) char *s; struct file_name_list *q; int n; - int base_inc = 0; + + q = include_defaults; + + char* binpath = get_binary_path(); + if (binpath) { + char *dirnam = strdup(dirname(binpath)); + strcpy(binpath, dirnam); + free(dirnam); + + char *lsep = NULL; +#ifndef WIN32 + lsep = strrchr(binpath,'/'); +#else + lsep = strrchr(binpath,'\\'); +#endif + if(lsep != NULL) { + strcpy(lsep+1, "share/qdos/include"); + q->fname = binpath; + q->next = q+1; + q++; + } + } #ifdef PREFIX char* pfx = XSTR(PREFIX); if (strlen(pfx) > 0) { char *pinc = malloc(strlen(pfx) + 32); strcpy(pinc, pfx); - strcat(pinc, "/qdos/include"); - include_defaults[0].fname = pinc; - include_defaults[0].next = include_defaults + 1; - cplusplus_include_defaults[0].fname = pinc; - base_inc++; + strcat(pinc, "/share/qdos/include"); + q->fname = pinc; + q->next = q + 1; + q++; } #endif - if((s = getenv("QLINC"))) - { - char *p,*r; - r = include_defaults[base_inc].fname = strdup(s); - p = (r + strlen(r) - 1); - if(*p == '\\' || *p == '/') - { - *p = 0; - } - include_defaults[base_inc].next = include_defaults + 1; - cplusplus_include_defaults[base_inc].fname = r; - base_inc++; + if((s = getenv("QLINC"))) { + q->fname = s; + q->next = q + 1; + q++; } - // fallback - include_defaults[base_inc].fname = "/usr/local/qdos/include"; - include_defaults[base_inc].next = NULL; + q->fname = "/usr/local/share/qdos/include"; + q->next = q+1; + q++; + q->fname = NULL; + q->next = NULL; max_include_len = 0; - for(q = include_defaults; q->next; q++) - { - n = strlen(q->fname); - if(n > max_include_len) - { - max_include_len = n; - } - } - for(q = cplusplus_include_defaults; q->next; q++) - { - n = strlen(q->fname); - if(n > max_include_len) - { - max_include_len = n; - } + for(q = include_defaults; q->next; q++) { + remove_trailing_slash(q->fname); + n = strlen(q->fname); + if(n > max_include_len) { + max_include_len = n; + } } - } #endif @@ -1291,14 +1307,12 @@ main (argc, argv) if (!no_standard_includes) { if (include == 0) - include = (cplusplus ? cplusplus_include_defaults : include_defaults); + include = include_defaults; else - last_include->next - = (cplusplus ? cplusplus_include_defaults : include_defaults); + last_include->next = include_defaults; /* Make sure the list for #include <...> also has the standard dirs. */ if (ignore_srcdir && first_bracket_include == 0) - first_bracket_include - = (cplusplus ? cplusplus_include_defaults : include_defaults); + first_bracket_include = include_defaults; } /* Initialize output buffer */ diff --git a/cpp/config.h b/cpp/config.h index 50afccd..e439a7d 100644 --- a/cpp/config.h +++ b/cpp/config.h @@ -40,14 +40,12 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifdef __GNUC__ #define alloca __builtin_alloca # ifdef XTC68 -# define GCC_INCLUDE_DIR "/usr/local/qdos/include" -# define GPLUSPLUS_INCLUDE_DIR "/usr/local/qdos/include" +# define GCC_INCLUDE_DIR "/usr/local/share/qdos/include" +# define GPLUSPLUS_INCLUDE_DIR "/usr/local/share/qdos/include" # endif -#elif defined (XTC68) /* Must be DOS/NT/OS2 */ +#elif defined (XTC68) /* Must be DOS/NT/OS2 */ # define GCC_INCLUDE_DIR "c:/qlinc" # define GPLUSPLUS_INCLUDE_DIR "c:/qlinc" # define alloca xalloca extern char * xalloca(unsigned long); #endif - - diff --git a/ld/Makefile b/ld/Makefile index 858ca9f..c2f7cd5 100644 --- a/ld/Makefile +++ b/ld/Makefile @@ -1,6 +1,6 @@ VPATH = ../ -OBJS = ld.o +OBJS = ldold.o appdir.o # We force an ia32 application to avoid having to fix numerous long assumptions CFLAGS += -DXTC68 -O2 -fsigned-char @@ -10,11 +10,12 @@ PROG = qld all: $(PROG) +%.o : %.c + $(CC) $(CFLAGS) -DPREFIX="$(prefix)" -c $< -o $@ + $(PROG): $(OBJS) $(CC) $(CFLAGS) -o $(PROG) $(OBJS) -ld.o: ldold.c - $(CC) $(CFLAGS) -DPREFIX="$(prefix)" -c -o ld.o ldold.c clean: rm -f *.o $(PROG) diff --git a/ld/appdir.c b/ld/appdir.c new file mode 100644 index 0000000..124b1e1 --- /dev/null +++ b/ld/appdir.c @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include +#include +#include + +#if defined(WIN32) +#include +#elif defined(__APPLE__) +#include +#endif + +char *get_binary_path(void) { + char *dest = calloc(1,PATH_MAX); + uint32_t size; +#if defined(__linux__) + realpath("/proc/self/exe", dest); +#elif defined(WIN32) + GetModuleFileName(NULL, dest, PATH_MAX); +#elif defined(__APPLE__) + size = PATH_MAX; + _NSGetExecutablePath(dest, &size); +#elif defined(__FreeBSD__) + realpath("/proc/curproc/file", dest); +#endif + size = strlen(dest); + if(size > 0) { + return dest; + } else { + free(dest); + return NULL; + } +} + +#ifdef APPDIR_TEST +int main(int argc, char **argv) { + char* p = get_binary_path(); + if(p != NULL) { + printf("Path = %s\n", dirname(p)); + free(p); + } + return 0; +} +#endif diff --git a/ld/ldold.c b/ld/ldold.c index 65a073d..156729b 100644 --- a/ld/ldold.c +++ b/ld/ldold.c @@ -44,6 +44,8 @@ Dec 89 QDOS port done by Jeremy Allison #include #include #include +#include +#include #ifdef XTC68 # ifdef DOS_LIKE @@ -52,6 +54,7 @@ Dec 89 QDOS port done by Jeremy Allison # define _version ldversion # define movmem(a,b,c) memcpy(b,a,c); # endif +extern char * get_binary_path(); #endif #define XSTR(s) STR(s) @@ -1360,8 +1363,7 @@ int test_module(void) void link_file (char *name, int lib_mode, char **lib_paths, int file_no) { - char fname[50]; - + char fname[PATH_MAX]; strcpy(currentname, name); if(lib_mode || (file_no == 0)) @@ -1369,8 +1371,9 @@ void link_file (char *name, int lib_mode, char **lib_paths, int file_no) inp_hnd = -1; while( *lib_paths) { - strcpy( fname, *lib_paths ); - strcat( fname, name); + strcpy(fname, *lib_paths); + strcat(fname, "/"); + strcat(fname, name); if((inp_hnd=open(fname, O_RDONLY|O_BINARY, 0))!= -1) break; lib_paths++; @@ -1540,6 +1543,13 @@ void write_prog(void) /* Deal with command line */ +void remove_trailing_slash(char *fname) { + int n = strlen(fname); + if (*(fname + n -1) == '/' || *(fname + n -1) == '\\') { + *(fname + n -1) = 0; + } +} + void command_line(int *xac, char ***xav, char **paths, char *lib_arr) { #ifdef QDOS @@ -1709,51 +1719,51 @@ void command_line(int *xac, char ***xav, char **paths, char *lib_arr) halt(0); strcpy( p, getenv(_prog_use)); strcat(p, "LIB_"); -#else +#elif defined(XTC68) { - char *ldd = getenv("QLLIB"); - if(ldd == NULL) - { -#if defined(__unix__) || defined(__APPLE__) || defined(__MINGW32__) -#ifdef PREFIX - char* pfx = XSTR(PREFIX); - if (strlen(pfx) > 0) { - ldd = malloc(strlen(pfx) + 16); - strcpy(ldd, pfx); - strcat(ldd, "/qdos/lib/"); - paths[num_paths++] = ldd; - } -#endif - // fallback - ldd = strdup("/usr/local/qdos/lib/"); + char *ldd = NULL; + char* binpath = get_binary_path(); + if (binpath) { + char *dirnam = strdup(dirname(binpath)); + strcpy(binpath, dirnam); + free(dirnam); + + char *lsep = NULL; +#ifndef WIN32 + lsep = strrchr(binpath,'/'); #else - ldd = strdup("c:/qllib/"); + lsep = strrchr(binpath,'\\'); #endif + if(lsep != NULL) { + strcpy(lsep+1, "share/qdos/lib"); + paths[num_paths++] = binpath; } - { - if(!(p = paths[num_paths++] = malloc(strlen(ldd)+2))) - { - halt(0); - } - else - { - char *q; - strcpy(p, ldd); - q = p+strlen(p); - if(q[-1] != '\\' && q[-1] != '/') - { - *q++ = '/'; - *q = 0; - } - } - } + } + +#ifdef PREFIX + char* pfx = XSTR(PREFIX); + if (strlen(pfx) > 0) { + ldd = malloc(strlen(pfx) + 32); + strcpy(ldd, pfx); + strcat(ldd, "/share/qdos/lib"); + paths[num_paths++] = ldd; + } +#endif + + ldd = getenv("QLLIB"); + if (ldd != NULL) { + paths[num_paths++] = strdup(ldd); + } + paths[num_paths++] = "/usr/local/share/qdos/lib"; + for(int i = 0; i < num_paths; i++) { + remove_trailing_slash(paths[i]); + } } #endif paths[num_paths] = NULL; } -int main(int argc, char **argv) -{ +int main(int argc, char **argv) { char *paths[NUM_SPATHS+2], *lib_arr; int i; #ifdef QDOS diff --git a/sdk-install.sh b/sdk-install.sh index 8cc8ebf..9b8b514 100755 --- a/sdk-install.sh +++ b/sdk-install.sh @@ -5,17 +5,11 @@ # This script will find the relevant files under ./, in the format # from the original distribution runtime disk 1 - [ -n "$prefix" ] && PREFIX=$prefix PREFIX=${PREFIX:-/usr/local} -INSBIN= -BINDIR= for L do case $L in - -e) - INSBIN=1 - ;; *[\\/]*) PREFIX=$L ;; @@ -26,7 +20,6 @@ do ;; esac done -BINDIR=${BINDIR:-$PREFIX/bin} if [ ! -w $PREFIX ] ; then if [ $(id -u) -ne 0 ] ; then @@ -40,20 +33,13 @@ if [ ! -w $PREFIX ] ; then fi CP="cp -v" -mkdir -p $PREFIX/qdos/include/sys -mkdir -p $PREFIX/qdos/include/netinet/ -mkdir -p $PREFIX/qdos/include/arpa/ -mkdir -p $PREFIX/qdos/lib -mkdir -p $PREFIX/qdos/etc -[ -f support/ql.mak ] && $CP support/ql.mak $PREFIX/qdos/etc +mkdir -p $PREFIX/share/qdos/include/sys +mkdir -p $PREFIX/share/qdos/include/netinet/ +mkdir -p $PREFIX/share/qdos/include/arpa/ +mkdir -p $PREFIX/share/qdos/lib +mkdir -p $PREFIX/share/qdos/etc -if [ -n "$INSBIN" ] ; then - mkdir -p $BINDIR - for B in as68/as68 c68/c68 cc/qcc cpp/qcpp ld/qld slb/slb slb/qdos-ar slb/qdos-ranlib - do - $CP $B $BINDIR - done -fi +[ -f support/ql.mak ] && $CP support/ql.mak $PREFIX/share/qdos/etc while read FILE do @@ -64,24 +50,24 @@ do case $IFILE in sys_*) SIFILE=${IFILE##*sys_} - $CP $FILE $PREFIX/qdos/include/sys/$SIFILE + $CP $FILE $PREFIX/share/qdos/include/sys/$SIFILE ;; netinet_*) SIFILE=${IFILE##*netinet_} - $CP $FILE $PREFIX/qdos/include/netinet/$SIFILE + $CP $FILE $PREFIX/share/qdos/include/netinet/$SIFILE ;; arpa_*) SIFILE=${IFILE##*arpa_} - $CP $FILE $PREFIX/qdos/include/arpa/$SIFILE + $CP $FILE $PREFIX/share/qdos/include/arpa/$SIFILE ;; *) - $CP $FILE $PREFIX/qdos/include/$IFILE + $CP $FILE $PREFIX/share/qdos/include/$IFILE ;; esac ;; */lib_*) LFILE=${FN##*lib_} - $CP $FILE $PREFIX/qdos/lib/$LFILE + $CP $FILE $PREFIX/share/qdos/lib/$LFILE ;; esac done < <(find . -iname include_\* -o -iname lib_\*) diff --git a/slb/Makefile b/slb/Makefile index 9f2d117..2a94173 100644 --- a/slb/Makefile +++ b/slb/Makefile @@ -8,9 +8,11 @@ # ... for compiling on MINIX LDFLAGS += $(CFLAGS) CFLAGS += -I. -O2 - - LIBS = +MACHINE := $(shell $(CC) -dumpmachine) +ifneq (, $(findstring mingw, $(MACHINE))) + LIBS=-l wsock32 +endif # Set the object file extension # Set it to 's' for MINIX-PC, 'o' for other variants diff --git a/slb/slbdis.c b/slb/slbdis.c index 7b2513e..81aefae 100644 --- a/slb/slbdis.c +++ b/slb/slbdis.c @@ -37,6 +37,11 @@ #include "slb.h" #include #include +#if defined(__unix__) || defined(__APPLE__) +#include +#else +#include +#endif PRIVATE short gword _PROTOTYPE((void)); PRIVATE long glong _PROTOTYPE((void)); @@ -91,15 +96,6 @@ PRIVATE int gisize; PRIVATE long modfstart; /* File position of start of module */ PRIVATE int endflag; -static uint16_t bswap_16(uint16_t val) { - return (uint16_t)(val << 8) + (val >> 8); -} - -static uint32_t bswap_32(uint32_t val) { - return (uint32_t)(((uint32_t)bswap_16(val & 0xffff) << 16) | - (uint32_t)bswap_16(val >> 16)); -} - /*============================================================ CHECK_LABEL */ PRIVATE @@ -257,7 +253,7 @@ short gword() DBG(("GWORD",0x1001,"enter:")); reply = (short)get_data(2); - reply = bswap_16(reply); + reply = htons(reply); gaddr += 2; DBG(("GWORD",0x1001,"Exit: reply=%04.4x",reply)); return (reply); @@ -275,7 +271,7 @@ long glong() DBG(("GLONG",0x1001,"Enter:")); reply = get_data(4); - reply = bswap_32(reply); + reply = htonl(reply); gaddr += 4; DBG(("GLONG",0x1001,"Exit: reply=%08.8c",reply)); return (reply); diff --git a/support/ql.mak b/support/ql.mak index d9373de..31d772d 100644 --- a/support/ql.mak +++ b/support/ql.mak @@ -1,6 +1,7 @@ # Makefile definitions to use xtc68 in a GNU make 'Makefile' -# add the line (no quotes) 'include /usr/local/qdos/etc/ql.mak' as the +# add the line (no quotes) 'include $PATH_TO/ql.mak' as the # first line of the makefile. Then just 'make' normally. +# where $PATH_TO represents the path to the installed 'ql.mak' CC = qcc LD = qld @@ -9,4 +10,3 @@ CPP = qcpp %.o : %.s $(CC) $(ASFLAGS) -c $< -o $@ - diff --git a/tools/Makefile b/tools/Makefile index 4103fbf..dc5de51 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -3,13 +3,18 @@ prefix ?= /usr/local/bin +MACHINE := $(shell $(CC) -dumpmachine) +ifneq (, $(findstring mingw, $(MACHINE))) + WLIB=-l wsock32 +endif + all: qls qcp qls: qls.c - $(CC) -Wall -O2 -o $@ $< + $(CC) -Wall -O2 -o $@ $< $(WLIB) qcp: qcp.c - $(CC) -Wall -O2 -o $@ $< + $(CC) -Wall -O2 -o $@ $< $(WLIB) clean: rm -f qls qcp diff --git a/tools/qcp.c b/tools/qcp.c index 14e991c..c2e9e78 100644 --- a/tools/qcp.c +++ b/tools/qcp.c @@ -25,12 +25,15 @@ #include #include #include +#define _GNU_SOURCE #include #include #include -#ifdef NOINLINE -#define inline +#if defined(__unix__) || defined(__APPLE__) +#include +#else +#include #endif #ifdef __GNUC__ @@ -53,21 +56,10 @@ typedef struct PACKED { uint32_t d_backup; } QLDIR_t; -short is_big_endian; - -ushort swapword(ushort val) { - return (is_big_endian) ? val : (ushort)(val << 8) + (val >> 8); -} - -uint32_t swaplong(uint32_t val) { - return (is_big_endian) ? val - : (uint32_t)(((uint32_t)swapword(val & 0xFFFF) << 16) | - (uint32_t)swapword(val >> 16)); -} -#ifdef NEED_STPCPY +#ifdef WIN32 char *stpcpy(char *d, const char *s) { - while (*d++ = *s++) /* NULL loop */ + while ((*d++ = *s++)) /* NULL loop */ ; return d - 1; } @@ -91,7 +83,7 @@ uint32_t CheckXTcc(char *filename) { read(fd, &fdat, sizeof(xtcc)); close(fd); if (fdat.x.x == xtcc.x.x) { - len = swaplong(fdat.dlen); + len = htonl(fdat.dlen); } } return len; @@ -103,14 +95,11 @@ void usage(void) { } int main(int ac, char **av) { - uint32_t one = 1; uint32_t dspac = 0; int c; char *inf = NULL, *ouf = NULL; char onam[PATH_MAX], secret[PATH_MAX]; - is_big_endian = 1 - *(char *)&one; - while ((c = getopt(ac, av, "x:h?")) != EOF) { switch (c) { case 'x': @@ -185,7 +174,7 @@ int main(int ac, char **av) { if ((fd = open(secret, O_RDWR, 0666)) > -1) { while (read(fd, &qd, sizeof(qd)) == sizeof(qd)) { - if (nlen == swapword(qd.d_szname) && + if (nlen == htons(qd.d_szname) && strncasecmp(qd.d_name, q, nlen) == 0) { lseek(fd, -1 * sizeof(qd), SEEK_CUR); break; @@ -196,14 +185,14 @@ int main(int ac, char **av) { fd = open(secret, O_CREAT | O_WRONLY, 0666); } if (fd >= 0) { - qd.d_szname = swapword(nlen); + qd.d_szname = htons(nlen); memcpy(qd.d_name, q, nlen); *(qd.d_name + nlen) = '\0'; // harmless, even if len==36 qd.d_type = 1; qd.d_access = 0; qd.d_update = 0; - qd.d_length = (stat(onam, &s) == 0) ? swaplong(s.st_size) : 1; - qd.d_datalen = swaplong(dspac); + qd.d_length = (stat(onam, &s) == 0) ? htonl(s.st_size) : 1; + qd.d_datalen = htonl(dspac); write(fd, &qd, sizeof(qd)); close(fd); if (ouf) { diff --git a/tools/qls.c b/tools/qls.c index 30a2ed2..7efe8f6 100644 --- a/tools/qls.c +++ b/tools/qls.c @@ -31,6 +31,12 @@ #define PACKED #endif +#if defined(__unix__) || defined(__APPLE__) +#include +#else +#include +#endif + typedef struct PACKED { uint32_t d_length; /* file length */ unsigned char d_access; /* file access type */ @@ -45,17 +51,13 @@ typedef struct PACKED { uint32_t d_backup; } QLDIR_t; -short is_big_endian; - -ushort swapword(ushort val) { - return (is_big_endian) ? val : (ushort)(val << 8) + (val >> 8); -} - -uint32_t swaplong(uint32_t val) { - return (is_big_endian) ? val - : (uint32_t)(((uint32_t)swapword(val & 0xFFFF) << 16) | - (uint32_t)swapword(val >> 16)); +#ifdef WIN32 +char *stpcpy(char *d, const char *s) { + while ((*d++ = *s++)) /* NULL loop */ + ; + return d - 1; } +#endif void usage(void) { fputs("usage: qls path\n", stderr); @@ -63,15 +65,12 @@ void usage(void) { } int main(int ac, char **av) { - uint32_t one = 1; char secret[PATH_MAX]; char *p, *q; int fd; QLDIR_t qd; struct stat s; - is_big_endian = 1 - *(char *)&one; - if (*(av + 1) && stat(*(av + 1), &s) == 0 && (S_ISDIR(s.st_mode))) { p = stpcpy(secret, *(av + 1)); if (*(p - 1) != '/') { @@ -90,7 +89,7 @@ int main(int ac, char **av) { strncpy(fnam, secret, n); while (read(fd, &qd, sizeof(qd)) == sizeof(qd)) { - len = swapword(qd.d_szname); + len = htons(qd.d_szname); strncpy(fnam + n, qd.d_name, len); *(fnam + n + len) = 0; @@ -98,9 +97,9 @@ int main(int ac, char **av) { struct tm *tm; tm = localtime(&s.st_mtime); char tbuff[64]; - strftime(tbuff, sizeof(tbuff), "%F %T", tm); - printf("%-36.*s%9ld%8d%4d %s\n", len, qd.d_name, s.st_size, - swaplong(qd.d_datalen), qd.d_type, tbuff); + strftime(tbuff, sizeof(tbuff), "%Y-%m-%d %H:%m:%S", tm); + printf("%-36.*s%9zu%8u%4d %s\n", len, qd.d_name, (size_t)s.st_size, + (uint32_t)htonl(qd.d_datalen), qd.d_type, tbuff); } } }