Skip to content

Commit

Permalink
rework include and lib search paths, update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
stronnag committed Aug 29, 2022
1 parent b644c88 commit dcf0a4c
Show file tree
Hide file tree
Showing 18 changed files with 345 additions and 212 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
84 changes: 67 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

```
Expand All @@ -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.
2 changes: 1 addition & 1 deletion as68/Makefile
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down
9 changes: 0 additions & 9 deletions cc/cc.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,7 @@
//#define _GNU_SOURCE
#include <string.h>
#include <unistd.h>
//#ifdef __FreeBSD__
#include <libgen.h> /*(POSIX) */
//#endif

#ifdef __APPLE__
#include <targetconditionals.h>
#if TARGET_OS_MAC
#include <libgen.h>
#endif /* TARGET_OS_MAC */
#endif /* __APPLE__ */

#include "cc.h"
#ifdef WIN32
Expand Down
6 changes: 3 additions & 3 deletions cpp/Makefile
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
46 changes: 46 additions & 0 deletions cpp/appdir.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#include <libgen.h>
#include <stdbool.h>
#include <string.h>
#include <stdint.h>

#if defined(WIN32)
#include <windows.h>
#elif defined(__APPLE__)
#include <mach-o/dyld.h>
#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
Loading

0 comments on commit dcf0a4c

Please sign in to comment.