>From d29028b3db86501b2b4e2042abc320d46a0f4370 Mon Sep 17 00:00:00 2001
From: John Cowan
Date: Mon, 30 Dec 2019 14:23:49 -0500
Subject: [PATCH] Implement platform autodetection when possible
Cross-compilation still requires PLATFORM to be set, and you can always
set it yourself if you want to, but the README examples no longer
mention it.
Signed-off-by: Evan Hanson
---
GNUmakefile | 4 ++-
Makefile.detect | 84 +++++++++++++++++++++++++++++++++++++++++++
NEWS | 5 +++
README | 38 +++++++++++++-------
distribution/manifest | 1 +
5 files changed, 118 insertions(+), 14 deletions(-)
create mode 100644 Makefile.detect
diff --git GNUmakefile GNUmakefile
index 68422f39..81b31487 100644
--- GNUmakefile
+++ GNUmakefile
@@ -37,6 +37,8 @@ include $(CONFIG)
endif
endif
+include Makefile.detect
+
ifndef PLATFORM
$(info Please select your target platform by running one of the following commands:)
$(info )
@@ -46,4 +48,4 @@ $(info For more information, consult the README file.)
$(error No PLATFORM given.)
else
include $(SRCDIR)Makefile.$(PLATFORM)
-endif
\ No newline at end of file
+endif
diff --git Makefile.detect Makefile.detect
new file mode 100644
index 00000000..75dd5d0e
--- /dev/null
+++ Makefile.detect
@@ -0,0 +1,84 @@
+# -*- Makefile -*-
+#
+# Detect the PLATFORM with uname.
+# Based on Chibi Scheme auto-detector
+# Heavily revamped by John Cowan
+# Copyright (c) 2009-2018 Alex Shinn, John Cowan
+# BSD license at
+
+ifndef PLATFORM
+
+# First check is for pure MinGW, which doesn't have uname.
+# In cmd.exe, echo "test" outputs "test", with quotes.
+test:=$(shell echo "test")
+quote:=$(findstring ",$(test))
+
+ifeq ($(quote),")
+PLATFORM=mingw
+else
+
+# Now we can use uname tests
+uname_s:=$(shell uname)
+uname_o:=$(shell uname -o)
+
+# Check for specific platforms
+ifeq ($(uname_o),Msys)
+PLATFORM=mingw-msys
+endif
+
+ifeq ($(uname_s),Darwin)
+PLATFORM=macosx
+endif
+
+ifeq ($(uname_s),FreeBSD)
+PLATFORM=bsd
+endif
+
+ifeq ($(uname_s),NetBSD)
+PLATFORM=bsd
+endif
+
+ifeq ($(uname_s),OpenBSD)
+PLATFORM=bsd
+endif
+
+ifeq ($(uname_s),DragonFly)
+PLATFORM=bsd
+endif
+
+ifeq ($(uname_o),Cygwin)
+PLATFORM=cygwin
+endif
+
+ifeq ($(uname_o),Android)
+PLATFORM=android
+endif
+
+ifeq ($(uname_o),GNU/Linux)
+PLATFORM=linux
+endif
+
+ifeq ($(uname_s),SunOS)
+PLATFORM=solaris
+endif
+
+ifeq ($(uname_s),Haiku)
+PLATFORM=haiku
+endif
+
+ifeq ($(uname_s),BeOS)
+PLATFORM=haiku
+endif
+
+ifeq ($(uname_s),GNU)
+PLATFORM=hurd
+endif
+
+ifeq ($(uname_s),AIX)
+PLATFORM=aix
+endif
+
+# add more options here
+
+endif # have uname
+endif # undef PLATFORM
diff --git NEWS NEWS
index d86ffe23..75253c4d 100644
--- NEWS
+++ NEWS
@@ -4,6 +4,11 @@
parameters in interrupt handlers anymore. (See #1638. Fix
contributed by Sebastien Marie)
+- Build system
+ - Auto-configure at build time on most platforms. Cross-compilation
+ still requires PLATFORM to be set, and it can still be provided
+ manually, but it is no longer required in the common case.
+
5.1.1
diff --git README README
index fd295c9d..3b20cc00 100644
--- README
+++ README
@@ -78,8 +78,19 @@ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/_/
currently not supported, so you must be in the toplevel source
directory to invoke "make".
- Enter "make" without any options to see a list of supported
- platforms.
+ If you enter "make" without the PLATFORM option, CHICKEN will
+ attempt to figure out what platform you are using. If it cannot
+ do so, you will see a list of supported platforms. If you are
+ cross-building, you must specify PLATFORM; for example,
+ PLATFORM=cross-linux-mingw will build CHICKEN on Linux to
+ deploy on Windows.
+
+ If CHICKEN somehow detects the wrong platform, type
+
+ make PLATFORM=""
+
+ to get a list of available platforms, and re-run "make" using
+ the correct platform.
Note that parallel builds (using the "-j" make(1) option) are
*not* supported.
@@ -87,7 +98,7 @@ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/_/
If you invoke "make" later with different configuration parameters,
it is advisable to run:
- make PLATFORM= confclean
+ make confclean
to remove old configuration files.
@@ -96,13 +107,14 @@ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/_/
If you build CHICKEN directly from the development sources out
of the git repository, you will need a "chicken" executable to
generate the compiled C files from the Scheme library sources.
+ See section 2.1 for platform detection issues.
If you are building in a checkout where you have built other
versions of chicken, you need to make sure that all traces of
the previous build are removed. "make clean" is insufficient,
and you should do the following:
- make PLATFORM= spotless
+ make spotless
You will need to have a "chicken" binary installed, ideally
from the development snapshot tarball that is closest to the
@@ -114,7 +126,7 @@ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/_/
Then, to build you can run:
- make PLATFORM= CHICKEN=/bin/chicken
+ make CHICKEN=/bin/chicken
In some cases, the sources may have diverged enough to
become unbuildable even with the snapshot. Then you'll need
@@ -127,7 +139,7 @@ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/_/
If CHICKEN is built successfully, you can install it on your
system by entering
- make PLATFORM= PREFIX= install
+ make PREFIX= install
"PREFIX" defaults to "/usr/local". Note that the PREFIX is
compiled into several CHICKEN tools and must be the same
@@ -248,7 +260,7 @@ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/_/
To remove CHICKEN from your file-system, enter (probably as
root):
- make PLATFORM= PREFIX= uninstall
+ make PREFIX= uninstall
(If you gave DESTDIR during installation, you have to pass
the same setting to "make" when uninstalling)
@@ -474,7 +486,7 @@ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/_/
- CHICKEN will normally select a 32-bit or 64-bit build
automatically when you use the normal build step:
- make PLATFORM=macosx
+ make
Specifically, the defaults are:
@@ -487,18 +499,18 @@ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/_/
released in late 2006 or later (i.e. with a Core 2 Duo or Xeon
CPU), by specifying ARCH=x86-64:
- make PLATFORM=macosx ARCH=x86-64
+ make ARCH=x86-64
- Universal binaries: On 10.4 and 10.5 only, CHICKEN and its eggs
can be built as universal binaries which will work on either
Intel or PowerPC. Most users will not want to do this.
For 10.4 universal build:
- make PLATFORM=macosx ARCH=universal
+ make ARCH=universal
For 10.5 universal build:
export MACOSX_DEPLOYMENT_TARGET=10.4
- make C_COMPILER=gcc-4.0 PLATFORM=macosx ARCH=universal
+ make C_COMPILER=gcc-4.0 ARCH=universal
For 10.6 and later, universal builds are not supported.
@@ -642,7 +654,7 @@ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/_/
http://code.call-cc.org, unpack it, build and install it.
Then change to the directory containing the git code and run:
- make PLATFORM= CHICKEN= \
+ make CHICKEN= \
boot-chicken
This will produce a statically linked binary with the name
@@ -657,7 +669,7 @@ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/_/
builds the boot-chicken that you can use to compile the
development sources. The invocation is:
- scripts/bootstrap.sh PLATFORM= ...
+ scripts/bootstrap.sh ...
You can add additional parameters if you like to customize the
build, but this should not be necessary. Note that your current
diff --git distribution/manifest distribution/manifest
index 9d43de14..504ddb5e 100644
--- distribution/manifest
+++ distribution/manifest
@@ -253,6 +253,7 @@ tweaks.scm
Makefile
Makefile.android
Makefile.aix
+Makefile.detect
Makefile.linux
Makefile.macosx
Makefile.ios
--
2.25.1