standardizing installation paths and default build.

This commit is contained in:
Norayr Chilingarian 2026-09-17 01:47:47 +04:00
parent c985dcb3e4
commit c0fb40fb69
11 changed files with 253 additions and 115 deletions

View file

@ -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 <name>.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;

View file

@ -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);

View file

@ -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;

View file

@ -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();

View file

@ -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'