diff --git a/ReadMe.md b/ReadMe.md index 95d7f840..1a43b4cf 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -27,14 +27,14 @@ default libraries complying with the Oakwood Guidelines for Oberon-2 compilers. ## Installation -It is easy to install the Oberon compiler and libraries +It is easy to build the Oberon compiler and libraries with the following simple steps: 1. Install pre-requisites such as git, gcc, static C libraries, diff utils. 2. Clone the repository: `git clone https://github.com/vishaps/voc`. - 3. Optionally `export CC=clang` or `export CC=tcc`. - 4. run `make full`. - 5. Optionally install to a system directory such as /opt or /usr/local/share with `make install` (might be with sudo). + 3. Optionally choose a C compiler, for example with `export CC=clang`. + 4. Run `make`. + 5. Optionally install to a system directory with `make install` (might be with sudo). 6. Set your PATH variable to include the compiler binary. These are detailed below: @@ -58,28 +58,38 @@ More details, including for MingW and MS C, in [**Installation**](/doc/Installat 1. `git clone https://github.com/vishaps/voc` 2. `cd voc` -3. `make full` +3. `make` -`make full` will create an installation directory under your local repository at voc/install. - -`mmake full` runs `ldconfig` to configure the linker to find libraries in voc/install, but you -need to update your program search PATH yourself (see step 4 below). +`make` is an unprivileged build. It creates an installation image under +`voc/install`, runs the confidence tests, and does not copy files to the host. +Choose a different C compiler with, for example, `CC=clang make`. #### 3. Optionally install to a system directory -Run `make install` as root to copy the voc/install directory to the appropriate directory -for your OS as follows: +Run `make install` as root to copy the `voc/install` image to the configured directories. +The default Unix locations are `/usr/local/bin`, `/usr/local/share/voc`, and +`/usr/local/lib`. Override `PREFIX`, `BINDIR`, `INSTALLDIR`, and `LIBDIR` as needed. -| System | Where `make install` puts the installation | -| ------- | -------------------------------------- | -| Linux | `/opt/voc` | -| BSD | `/usr/local/share/voc` | -| Windows | See [**Windows installation**](/doc/Winstallation.md) | -| Termux | `/data/data/com.termux/files/opt/voc` | +For a package build, use `DESTDIR` so the staged path is not compiled into the +compiler configuration: -`make install` updates `ldconfg` with the new library locations. + make install PREFIX=/usr DESTDIR=/path/to/package-root + +To retain the historical self-contained layout, use an explicit installation +directory instead: + + make install INSTALLDIR=/opt/voc + +| System | Where `make install` puts the installation | +| ------- | -------------------------------------- | +| Unix | `/usr/local/bin`, `/usr/local/share/voc`, `/usr/local/lib` | +| Windows | See [**Windows installation**](/doc/Winstallation.md) | +| Termux | `/data/data/com.termux/files/opt/voc` | + +For a manual installation with libraries outside the standard linker paths, +use `make install-system`; unlike `make install`, it also runs `ldconfig`. #### 4. Set your PATH environment variable @@ -87,16 +97,17 @@ for your OS as follows: Since there are so many ways that different systems and users manage their PATHs, we leave it to you to update your path to include the compiler binary. -Both `make full` and `make install` display instructions on setting the path specific to your -system. +Both `make` and `make install` display instructions on setting the path specific to your +system. A staged installation is run from its final installation paths after +the package is installed, not from its `DESTDIR` path. For reference this will be: | Installation choice | Set path | | --------- | -------------------------------------- | -| Just `make full` | `export PATH="your-repository-clone/install/bin:$PATH"` | -| `make install` on Linux | `export PATH="/opt/voc/bin:$PATH"` | -| `make install` on BSD | `export PATH="/usr/local/share/voc/bin:$PATH"` | +| Just `make` | `export PATH="your-repository-clone/install/bin:$PATH"` | +| `make install` on Unix | `export PATH="/usr/local/bin:$PATH"` | +| `make install` on BSD | `export PATH="/usr/local/bin:$PATH"` | | `make install` on Windows | See [**Windows installation**](/doc/Winstallation.md) | | `make install` on Termux | `export PATH="/data/data/com.termux/files/opt/voc/bin:$PATH"` | diff --git a/doc/Installation.md b/doc/Installation.md index d9ad75cd..3667a1cb 100644 --- a/doc/Installation.md +++ b/doc/Installation.md @@ -82,7 +82,7 @@ This will create a subdirectory 'voc' which includes the following files and dir ``` cd voc -make full +make ``` The makefile will: @@ -94,48 +94,71 @@ The makefile will: link the final Oberon compiler. This compiler is then used for the remaining steps. - Build the .sym file browser command `showdef`. - Build all the libraries in -O2 mode, and a subset in -OC mode. - - Create an installation directory structure local to your copy of the repository. - - Run a set of confidence tests. + - Create an installation directory image local to your copy of the repository at `install/`. + - Run a set of confidence tests. -The makefile will use either gcc or clang, whichever is installed. If you have both installed you can specify which to use by running either `export CC=gcc` or `export CC=clang` before the `make full` command. +The makefile will use either gcc or clang, whichever is installed. If you have both installed you can specify which to use with, for example, `CC=clang make`. + +The build does not require root access and does not install anything outside +the repository. To select a compiler for one build, use for example: + +``` +CC=clang make +``` #### Installation directories: If the makefile succeeds it will end with instructions on how to set your path variable so that the -compiler (voc) is found. +compiler (voc) in the local `install/bin` directory is found. #### Installing to system directories -You may optionally install to system directories such as /opt or /usr/local/share. +You may optionally copy the local installation image to system directories such as /opt or /usr/local. -First be sure to have completed `make full` successfully. +First be sure to have completed `make` successfully. -Then from a root prompt, or using sudo, run `make install` +Then from a root prompt, or using sudo, run `make install`. -The installation will be made to: +By default, the installation will be made to: -| System | Install dir | -| ----------------------- | -------------------------------------- | -| All types of Linux | /opt/voc | -| BSD (including Darwin) | /usr/local/share/voc | -| Termux (android) | /data/data/com.termux/files/opt/voc | +| Content | Install dir | +| --------------------------- | --------------------------- | +| Compiler and showdef | /usr/local/bin | +| Oberon resources | /usr/local/share/voc | +| Runtime libraries | /usr/local/lib | +| Termux (android) | /data/data/com.termux/files/opt/voc | -As with `make full`, `make install` will exit with instructions on how to set -your PATH. +Set `PREFIX`, `BINDIR`, `INSTALLDIR`, and `LIBDIR` to change these locations. +`make install` only copies files. Use `make install-system` for a manual +installation that also updates the dynamic linker cache. + +For package builds, set the final paths and use `DESTDIR` for staging: + +``` +make install PREFIX=/usr DESTDIR=/path/to/package-root +``` + +`DESTDIR` is only a staging prefix and is not included in the compiler's +runtime search paths. To install the historical self-contained layout instead, +use an explicit installation directory, for example: + +``` +make install INSTALLDIR=/opt/voc +``` -#### Installation directory contentains: +#### Installation directory contents: -| Directory | Content | -| --- | --- | -| bin/ | Compiler and symbol file browser command binaries. | -| lib/ | Static and dynamic link libraries for all (-O2 and -OC) type models. | -| 2/include/ | C compiler header files for -O2 modules | -| 2/sym/ | .sym files for -O2 modules | -| C/include/ | C compiler header files for -OC modules | -| C/sym/ | .sym files for -OC modules | +| Directory | Content | +| --- | --- | +| `BINDIR` | Compiler and symbol file browser command binaries. | +| `LIBDIR` | Static and dynamic link libraries for all type models. | +| `INSTALLDIR/2/include` | C headers for -O2 modules. | +| `INSTALLDIR/2/sym` | Symbol files for -O2 modules. | +| `INSTALLDIR/C/include` | C headers for -OC modules. | +| `INSTALLDIR/C/sym` | Symbol files for -OC modules. | diff --git a/doc/Porting.md b/doc/Porting.md index 8bb2e74e..bc2484ab 100644 --- a/doc/Porting.md +++ b/doc/Porting.md @@ -1,7 +1,7 @@ ### Porting to a new platform Porting to a new 32 or 64 bit platform is usually automatically handled -by `make full`: +by `make`: - The makefile compiles `src/tools/make/configure.c` with the platform's default C compiler. @@ -14,10 +14,10 @@ by `make full`: which of 5 sets of pre-prepared C source files to build to create the bootstrap compiler. -On most systems this will be sufficient for `make full` to build -and install the compiler and libraries. +On most systems this will be sufficient for `make` to build the compiler +and libraries. -`make full` will terminate with a message such as: +`make` will terminate with a message such as: `--- Branch v2docs freebsd gcc LP64 confidence tests passed ---` @@ -55,4 +55,3 @@ Unix-like systems including Linux, BSD, Android and cygwin If you are porting to a system that does not provide a Unix style API, it will be necessary to implement a new variant of Platform.Mod providing the same interface as Platformunix.Mod and Platform Windows.Mod. - diff --git a/doc/Winstallation.md b/doc/Winstallation.md index 74eb3c97..af51a1ff 100644 --- a/doc/Winstallation.md +++ b/doc/Winstallation.md @@ -52,12 +52,12 @@ This will create a subdirectory 'voc' including the following files and director | makefile | Makefile for all BSD- and Linux- like environments. Includes tests. | | make.cmd | Makefile specifically for native Microsoft C builds. No tests. | -#### 3. Build and install the Oberon compiler and library +#### 3. Build the Oberon compiler and library ``` cd voc -[sudo] make full +make ``` The makefile will: @@ -69,8 +69,14 @@ The makefile will: link the final Oberon compiler. This compiler is then used for the remaining steps. - Build the .sym file browser command `showdef`. - Build all the libraries in -O2 mode, and a subset in -OC mode. - - Install the compiler and libraries by copying them to an appropriate location for your OS. - - Run a set of confidence tests. + - Create an installation image in the local `install/` directory. + - Run a set of confidence tests. + +The build does not require administrator access. To install the resulting +image, run `make install` separately. On Cygwin, the default Unix locations +are `/usr/local/bin`, `/usr/local/share/voc`, and `/usr/local/lib`; use +`PREFIX`, `BINDIR`, `INSTALLDIR`, and `LIBDIR` to change them. For a package +build, use `DESTDIR` as the staging prefix. ### Build using mingw under cygwin @@ -84,13 +90,13 @@ The makefile will: If it succeeds the makefile will end with instructions on how to set your path variable so that the compiler (voc) is found. -The installation will be found at: +The local build image will be found at: | Built with | Install dir | | --------------- | -------------------------------------- | -| cygwin | /opt/voc | -| cygwin + mingw | %PROGRAMFILES%/voc | -| MSC | %PROGRAMFILES%/voc | +| cygwin | `voc/install/` | +| cygwin + mingw | `voc/install/` | +| MSC | `%PROGRAMFILES%/voc` after installation | The installation directory contains: @@ -167,12 +173,12 @@ To use mingw, install the correct sized package and export CC= the compiler name - For 32 bit cygwin - use setup-x86.exe to add the package mingw64-i686-gcc-core. - - run 'export CC=i686-w64-mingw32-gcc' then 'make full' + - run 'export CC=i686-w64-mingw32-gcc' then 'make' - For 64 bit cygwin - use setup-x86\_64.exe to add the package mingw64-x86\_64-gcc-core. - - run 'export CC=x86_64-w64-mingw32-gcc' then 'make full' + - run 'export CC=x86_64-w64-mingw32-gcc' then 'make' (*Note*: Don't be put off by the name 'mingw64' in the 32 bit package.) diff --git a/make.cmd b/make.cmd index a47b97f0..a403ca40 100644 --- a/make.cmd +++ b/make.cmd @@ -40,7 +40,7 @@ for /F %%d in ('cd');do set ROOTDIR=%%d :: Process target parameter if "%1" equ "" ( - call :usage + call :all ) else ( call :%1 ) @@ -54,7 +54,7 @@ goto :eof @echo. @echo Usage: @echo. -@echo. make full - Make compiler to 'install' subdirectory +@echo. make - Make compiler to 'install' subdirectory @echo. make install - Install 'install' subdir to OS. Requires administrator privileges @echo. @echo. make clean - Remove made files @@ -66,7 +66,7 @@ goto :eof -:full +:all call :clean || exit /b echo. echo.--- Compiler build started --- diff --git a/makefile b/makefile index 08b69845..f895559f 100644 --- a/makefile +++ b/makefile @@ -3,13 +3,25 @@ # Makes sure configuration parameters are up to date and then hands off # to src/tools/make/oberon.mk. +# Installation paths. The default is a conventional local Unix installation. +# Set INSTALLDIR explicitly to retain the historical self-contained layout, +# for example: INSTALLDIR=/opt/voc make. +PREFIX ?= +DESTDIR ?= +INSTALLDIR ?= +BINDIR ?= +LIBDIR ?= + +# The configurator applies defaults and resolves PREFIX versus explicit paths. +CONFIG_PATHS = PREFIX='$(PREFIX)' INSTALLDIR='$(INSTALLDIR)' BINDIR='$(BINDIR)' LIBDIR='$(LIBDIR)' + # To build and install the Oberon compiler and library on a Unix based # OS (Linux/Mac/BSD etc.) or on cygwin, run: # -# make full +# make # # To override your OSs default C compiler, first run # @@ -67,12 +79,15 @@ -# Default make target - explain usage +# Default target: complete build and confidence tests. +all: + +# Display build and installation targets usage: @echo "" @echo Usage: @echo "" - @echo " make full" + @echo " make" @echo "" @echo " Does a full, clean build, and runs confidence tests." @echo " An installation directory image is left in the local repository install directory." @@ -84,7 +99,8 @@ usage: @echo " make library - Build all library files and make library" @echo " make O2library - Build all library files with Oberon-2 type sizes" @echo " make OClibrary - Build all library files with Component Pascal type sizes" - @echo " make install - Install built compiler and library in /opt or C:\\PROGRAM FILES*" + @echo " make install - Install built compiler and library" + @echo " make install-system - Install and update the dynamic linker cache" @echo " (Needs root access)" @echo "" @echo "Targets for (re)creating and reverting bootstrap C sources:" @@ -102,18 +118,16 @@ FORCE: configuration: FORCE @$(CC) -I src/runtime -o a.o src/tools/make/configure.c - @./a.o + @$(CONFIG_PATHS) ./a.o @rm a.o - @echo BRANCH=$$(git rev-parse --abbrev-ref HEAD)>>Configuration.Make - @echo Branch: $$(git rev-parse --abbrev-ref HEAD). + @branch=$$(git -c safe.directory="$$(pwd)" rev-parse --abbrev-ref HEAD 2>/dev/null || printf unknown); echo BRANCH=$$branch>>Configuration.Make; echo Branch: $$branch. bootstrapconfiguration: FORCE @$(CC) -I src/runtime -o a.o src/tools/make/configure.c - @./a.o bootstrap + @$(CONFIG_PATHS) ./a.o bootstrap @rm a.o - @echo BRANCH=$$(git rev-parse --abbrev-ref HEAD)>>Configuration.Make - @echo Branch: $$(git rev-parse --abbrev-ref HEAD). + @branch=$$(git -c safe.directory="$$(pwd)" rev-parse --abbrev-ref HEAD 2>/dev/null || printf unknown); echo BRANCH=$$branch>>Configuration.Make; echo Branch: $$branch. @@ -138,8 +152,9 @@ clean: configuration -# full: Full build of compiler and libarary. -full: configuration +# all: Complete clean build of compiler and library. +.PHONY: all +all: configuration @make -f src/tools/make/oberon.mk -s clean # Make bootstrap compiler from source suitable for current data model @printf "\n\n--- Compiler build started ---\n\n" @@ -234,9 +249,15 @@ makeinstalldir: install: configuration @make -f src/tools/make/oberon.mk -s install +install-system: configuration + @make -f src/tools/make/oberon.mk -s install-system + uninstall: configuration @make -f src/tools/make/oberon.mk -s uninstall +uninstall-system: configuration + @make -f src/tools/make/oberon.mk -s uninstall-system + @@ -315,7 +336,7 @@ auto: configuration # autoonce: What auto does each time a build is triggered. autoonce: configuration git pull - @if make -s full; then echo \*\* Succeeded \*\*; else echo \*\* Failed \*\*;fi + @if make -s; then echo \*\* Succeeded \*\*; else echo \*\* Failed \*\*;fi diff --git a/src/compiler/OPM.Mod b/src/compiler/OPM.Mod index 84678d6c..5635fa03 100755 --- a/src/compiler/OPM.Mod +++ b/src/compiler/OPM.Mod @@ -122,6 +122,7 @@ MODULE OPM; (* RC 6.3.89 / 28.6.89, J.Templ 10.7.89 / 22.7.96 *) S: INTEGER; InstallDir*: ARRAY 1024 OF CHAR; + LibraryDir*: ARRAY 1024 OF CHAR; ResourceDir*: ARRAY 1024 OF CHAR; @@ -832,17 +833,17 @@ MODULE OPM; (* RC 6.3.89 / 28.6.89, J.Templ 10.7.89 / 22.7.96 *) PROCEDURE IsProbablyInstallDir(s: ARRAY OF CHAR): BOOLEAN; VAR testpath: ARRAY 4096 OF CHAR; identity: Platform.FileIdentity; BEGIN - COPY(InstallDir, testpath); + COPY(s, testpath); Strings.Append("/lib/lib", testpath); Strings.Append(Configuration.name, testpath); Strings.Append("-O2.a", testpath); IF Platform.IdentifyByName(testpath, identity) # 0 THEN RETURN FALSE END; - COPY(InstallDir, testpath); + COPY(s, testpath); Strings.Append("/2/include/Oberon.h", testpath); IF Platform.IdentifyByName(testpath, identity) # 0 THEN RETURN FALSE END; - COPY(InstallDir, testpath); + COPY(s, testpath); Strings.Append("/2/sym/Files.sym", testpath); IF Platform.IdentifyByName(testpath, identity) # 0 THEN RETURN FALSE END; @@ -850,14 +851,28 @@ MODULE OPM; (* RC 6.3.89 / 28.6.89, J.Templ 10.7.89 / 22.7.96 *) END IsProbablyInstallDir; PROCEDURE FindInstallDir; - VAR i: INTEGER; + VAR i: INTEGER; env: ARRAY 1024 OF CHAR; BEGIN + (* Explicit overrides are useful for testing a staged installation. *) + Platform.GetEnv("VOCROOT", env); + IF env[0] # 0X THEN + COPY(env, InstallDir); + Platform.GetEnv("VOCLIBDIR", env); + IF env[0] # 0X THEN COPY(env, LibraryDir) + ELSE COPY(Configuration.libdir, LibraryDir) + END; + RETURN + END; + (* First try location of binary (with .d appended) *) COPY(Modules.BinaryDir, InstallDir); Strings.Append("/", InstallDir); Strings.Append(Configuration.name, InstallDir); Strings.Append(".d", InstallDir); - IF IsProbablyInstallDir(InstallDir) THEN RETURN END; + IF IsProbablyInstallDir(InstallDir) THEN + COPY(InstallDir, LibraryDir); Strings.Append("/lib", LibraryDir); + RETURN + END; (* Now test whether binary is in bin directory under install dir. *) COPY(Modules.BinaryDir, InstallDir); @@ -865,11 +880,17 @@ MODULE OPM; (* RC 6.3.89 / 28.6.89, J.Templ 10.7.89 / 22.7.96 *) WHILE (i > 0) & (InstallDir[i-1] # '/') DO DEC(i) END; IF (i > 0) & (InstallDir[i-1] = '/') THEN InstallDir[i-1] := 0X; - IF IsProbablyInstallDir(InstallDir) THEN RETURN END + IF IsProbablyInstallDir(InstallDir) THEN + COPY(InstallDir, LibraryDir); Strings.Append("/lib", LibraryDir); + RETURN + END END; (* Give up! Use install directory from configuration. *) - COPY(Configuration.installdir, InstallDir) + COPY(Configuration.installdir, InstallDir); + COPY(Configuration.libdir, LibraryDir); + Platform.GetEnv("VOCLIBDIR", env); + IF env[0] # 0X THEN COPY(env, LibraryDir) END END FindInstallDir; diff --git a/src/compiler/extTools.Mod b/src/compiler/extTools.Mod index c51d8c4d..cea47cbd 100644 --- a/src/compiler/extTools.Mod +++ b/src/compiler/extTools.Mod @@ -79,8 +79,8 @@ PROCEDURE LinkMain*(VAR moduleName: ARRAY OF CHAR; statically: BOOLEAN; addition Strings.Append(".c ", cmd); IF statically THEN IF Configuration.os = "darwin" THEN - Strings.Append(OPM.InstallDir, cmd); - Strings.Append('/lib/lib', cmd); + Strings.Append(OPM.LibraryDir, cmd); + Strings.Append('/lib', cmd); Strings.Append(Configuration.name, cmd); Strings.Append('-O', cmd); Strings.Append(OPM.Model, cmd); @@ -93,8 +93,8 @@ PROCEDURE LinkMain*(VAR moduleName: ARRAY OF CHAR; statically: BOOLEAN; addition Strings.Append(moduleName, cmd); IF (~statically) OR ~(Configuration.os = "darwin") THEN Strings.Append(Configuration.linkflags, cmd); - Strings.Append(OPM.InstallDir, cmd); - Strings.Append('/lib"', cmd); + Strings.Append(OPM.LibraryDir, cmd); + Strings.Append('"', cmd); Strings.Append(Configuration.libspec, cmd); Strings.Append('-O', cmd); Strings.Append(OPM.Model, cmd); @@ -109,8 +109,8 @@ PROCEDURE LinkMain*(VAR moduleName: ARRAY OF CHAR; statically: BOOLEAN; addition Strings.Append('-O', cmd); Strings.Append(OPM.Model, cmd); Strings.Append('.dylib "', cmd); - Strings.Append(OPM.InstallDir, cmd); - Strings.Append('/lib/lib', cmd); + Strings.Append(OPM.LibraryDir, cmd); + Strings.Append('/lib', cmd); Strings.Append(Configuration.name, cmd); Strings.Append('-O', cmd); Strings.Append(OPM.Model, cmd); diff --git a/src/tools/browser/BrowserCmd.Mod b/src/tools/browser/BrowserCmd.Mod index e4ffe88f..976c1360 100644 --- a/src/tools/browser/BrowserCmd.Mod +++ b/src/tools/browser/BrowserCmd.Mod @@ -310,7 +310,7 @@ PROCEDURE SetDefaultPath; VAR path: ARRAY 256 OF CHAR; BEGIN path := ".;"; - Strings.Append(Configuration.installdir, path); + Strings.Append(OPM.InstallDir, path); Strings.Append("/2/sym", path); Files.SetSearchPath(path) END SetDefaultPath; diff --git a/src/tools/make/configure.c b/src/tools/make/configure.c index ad999660..f7016897 100644 --- a/src/tools/make/configure.c +++ b/src/tools/make/configure.c @@ -40,6 +40,8 @@ void assert(int truth, char *complaint) {if (!truth) fail(complaint);} char builddate[256]; char installdir[256]; +char bindir[256]; +char libdir[256]; char versionstring[256]; char osrelease[1024]; char cwd[1024]; @@ -173,8 +175,11 @@ void determineInstallDirectory() { installdir[0] = 0; } else { char *env = getenv("INSTALLDIR"); - if (env) { + char *prefix = getenv("PREFIX"); + if (env && env[0]) { strncpy(installdir, env, sizeof(installdir)); + } else if (prefix && prefix[0]) { + snprintf(installdir, sizeof(installdir), "%s/share/%s", prefix, oname); } else { #if defined(_MSC_VER) || defined(__MINGW32__) if (sizeof (void*) == 8) { @@ -191,7 +196,7 @@ void determineInstallDirectory() { } else if (termux) { snprintf(installdir, sizeof(installdir), "/data/data/com.termux/files/opt/%s", oname); } else { - snprintf(installdir, sizeof(installdir), "/opt/%s", oname); + snprintf(installdir, sizeof(installdir), "/usr/local/share/%s", oname); } #endif } @@ -200,6 +205,39 @@ void determineInstallDirectory() { +void determineInstallationPaths() { + char *env; + char *install; + char *prefix = getenv("PREFIX"); + int explicitInstallDir; + install = getenv("INSTALLDIR"); + explicitInstallDir = install && install[0]; + + env = getenv("BINDIR"); + if (env && env[0]) { + snprintf(bindir, sizeof(bindir), "%s", env); + } else if (prefix && prefix[0] && !explicitInstallDir) { + snprintf(bindir, sizeof(bindir), "%s/bin", prefix); + } else if (explicitInstallDir || termux) { + snprintf(bindir, sizeof(bindir), "%s/bin", installdir); + } else { + snprintf(bindir, sizeof(bindir), "/usr/local/bin"); + } + + env = getenv("LIBDIR"); + if (env && env[0]) { + snprintf(libdir, sizeof(libdir), "%s", env); + } else if (prefix && prefix[0] && !explicitInstallDir) { + snprintf(libdir, sizeof(libdir), "%s/lib", prefix); + } else if (explicitInstallDir || termux) { + snprintf(libdir, sizeof(libdir), "%s/lib", installdir); + } else { + snprintf(libdir, sizeof(libdir), "/usr/local/lib"); + } +} + + + void determineBuildDate() { time_t t = time(0); @@ -380,6 +418,8 @@ void writeMakeParameters() { fprintf(fd, "ADRSIZE=%d\n", addressSize); fprintf(fd, "ALIGNMENT=%d\n", alignment); fprintf(fd, "INSTALLDIR=%s\n", installdir); + fprintf(fd, "BINDIR=%s\n", bindir); + fprintf(fd, "LIBDIR=%s\n", libdir); fprintf(fd, "PLATFORM=%s\n", platform); fprintf(fd, "BINEXT=%s\n", binext); fprintf(fd, "DYNEXT=%s\n", dynext); @@ -407,6 +447,7 @@ void writeConfigurationMod() { fprintf(fd, " compiler* = '%s';\n", compiler); fprintf(fd, " compile* = '%s';\n", cc); fprintf(fd, " installdir* = '%s';\n", installdir); + fprintf(fd, " libdir* = '%s';\n", libdir); fprintf(fd, " staticLink* = '%s';\n", staticlink); fprintf(fd, "VAR\n"); fprintf(fd, " versionLong-: ARRAY %d OF CHAR;\n", (int)strnlen(versionstring, 100)+1); @@ -447,6 +488,7 @@ int main(int argc, char *argv[]) determineCDataModel(); determineBuildDate(); determineInstallDirectory(); + determineInstallationPaths(); testSystemDotH(); diff --git a/src/tools/make/oberon.mk b/src/tools/make/oberon.mk index 1090d5e6..2dc440e7 100644 --- a/src/tools/make/oberon.mk +++ b/src/tools/make/oberon.mk @@ -16,6 +16,12 @@ ROOTDIR = $(CURDIR)$(.CURDIR) # *every* build by the makefile in the enlistment root. include ./Configuration.Make +# Defaults for configuration files generated by older versions. +BINDIR ?= $(INSTALLDIR)/bin +LIBDIR ?= $(INSTALLDIR)/lib + +.PHONY: install uninstall install-system uninstall-system + FLAVOUR = $(OS).$(DATAMODEL).$(COMPILER) BUILDDIR = build/$(FLAVOUR) OBECOMP = $(ONAME)$(BINEXT) @@ -180,30 +186,39 @@ instructions: FORCE FORCE: -# installable: Check for access to the installation directory -installable: - @rm -rf "S(INSTALLDIR)/test-access-qqq" - @if ! mkdir -p "$(INSTALLDIR)/test-access-qqq";then printf '\n\n Cannot write to install directory.\n Please use sudo or run as root/administrator.\n\n'; exit 1;fi - @rm -rf "S(INSTALLDIR)/test-access-qqq" +# uninstall: Remove files installed by this makefile without changing the +# host dynamic linker configuration. +uninstall: + @rm -f "$(DESTDIR)$(BINDIR)/$(OBECOMP)" "$(DESTDIR)$(BINDIR)/showdef$(BINEXT)" + @rm -rf "$(DESTDIR)$(INSTALLDIR)/2" "$(DESTDIR)$(INSTALLDIR)/C" + @rm -f "$(DESTDIR)$(LIBDIR)/lib$(ONAME)-O2.a" "$(DESTDIR)$(LIBDIR)/lib$(ONAME)-O2$(DYNEXT)" + @rm -f "$(DESTDIR)$(LIBDIR)/lib$(ONAME)-OC.a" "$(DESTDIR)$(LIBDIR)/lib$(ONAME)-OC$(DYNEXT)" -uninstall: installable - @printf '\nUninstalling from \"$(INSTALLDIR)\"\n' - @[ -d "$(INSTALLDIR)/lib" ] && sh src/tools/make/addlibrary.sh uninstall "$(INSTALLDIR)/lib" $(ONAME) || echo nolibdir, skipping - rm -rf "$(INSTALLDIR)" +# install: Use only after a successful full build. DESTDIR is a staging +# prefix and is deliberately not included in the generated compiler paths. +install: + @printf '\nInstalling compiler to "$(DESTDIR)$(BINDIR)"\n' + @mkdir -p "$(DESTDIR)$(BINDIR)" + @cp "$(ROOTDIR)/install/bin/$(OBECOMP)" "$(DESTDIR)$(BINDIR)/$(OBECOMP)" + @-cp "$(ROOTDIR)/install/bin/showdef$(BINEXT)" "$(DESTDIR)$(BINDIR)" + + @mkdir -p "$(DESTDIR)$(INSTALLDIR)/2" "$(DESTDIR)$(INSTALLDIR)/C" + @cp -rf "$(ROOTDIR)/install/2/." "$(DESTDIR)$(INSTALLDIR)/2/" + @cp -rf "$(ROOTDIR)/install/C/." "$(DESTDIR)$(INSTALLDIR)/C/" + + @mkdir -p "$(DESTDIR)$(LIBDIR)" + @cp "$(ROOTDIR)/install/lib/"* "$(DESTDIR)$(LIBDIR)/" + @printf '\nOberon compiler installed.\n' -# install: Use only after a successful full build. Installs the compiler -# and libraries in /opt/$(ONAME). -# May require root access. -install: uninstall - @printf '\nInstalling into \"$(INSTALLDIR)\"\n' - @rm -rf "$(INSTALLDIR)" - @cp -rf "$(ROOTDIR)/install/" "$(INSTALLDIR)" - @sh src/tools/make/addlibrary.sh install "$(INSTALLDIR)/lib" $(ONAME) - @printf '\nOberon compiler installed to $(INSTALLDIR)\n' - @printf '\nNow add $(INSTALLDIR)/bin to your path, for example with the command:\n' - @printf 'export PATH=\"$(INSTALLDIR)/bin:$$PATH\"\n' +# install-system: Install and update the dynamic linker cache for a manual +# installation. Package managers should use install with DESTDIR instead. +install-system: install + @sh src/tools/make/addlibrary.sh install "$(LIBDIR)" $(ONAME) + +uninstall-system: uninstall + @sh src/tools/make/addlibrary.sh uninstall "$(LIBDIR)" $(ONAME) @printf '\n'