Improve target setup in makefiles

split out HOST TARGET and SUBTARGET generation into separate file.
split out target(frontend) specific tool settings into separate files.
This commit is contained in:
Vincent Sanders 2021-01-17 20:06:24 +00:00
parent 25c21e5fef
commit 5db541a6d7
10 changed files with 299 additions and 257 deletions

263
Makefile
View File

@ -12,8 +12,7 @@
#
# Look at Makefile.config for configuration options.
#
# Tested on unix platforms (building for GTK and cross-compiling for RO) and
# on RO (building for RO).
# Best results obtained building on unix platforms cross compiling for others
#
# To clean, invoke as above, with the 'clean' target
#
@ -26,100 +25,8 @@
all: all-program
# Determine host type
# NOTE: HOST determination on RISC OS could fail because of missing bug fixes
# in UnixLib which only got addressed in UnixLib 5 / GCCSDK 4.
# When you don't have 'uname' available, you will see:
# File 'uname' not found
# When you do and using a 'uname' compiled with a buggy UnixLib, you
# will see the following printed on screen:
# RISC OS
# In both cases HOST make variable is empty and we recover from that by
# assuming we're building on RISC OS.
# In case you don't see anything printed (including the warning), you
# have an up-to-date RISC OS build system. ;-)
HOST := $(shell uname -s)
# default values for base variables
# Sanitise host
# TODO: Ideally, we want the equivalent of s/[^A-Za-z0-9]/_/g here
HOST := $(subst .,_,$(subst -,_,$(subst /,_,$(HOST))))
ifeq ($(HOST),)
HOST := riscos
$(warning Build platform determination failed but that's a known problem for RISC OS so we're assuming a native RISC OS build.)
else
ifeq ($(HOST),RISC OS)
# Fixup uname -s returning "RISC OS"
HOST := riscos
endif
endif
ifeq ($(HOST),riscos)
# Build happening on RO platform, default target is RO backend
ifeq ($(TARGET),)
TARGET := riscos
endif
endif
ifeq ($(HOST),BeOS)
HOST := beos
endif
ifeq ($(HOST),Haiku)
# Haiku implements the BeOS API
HOST := beos
endif
ifeq ($(HOST),beos)
# Build happening on BeOS platform, default target is BeOS backend
ifeq ($(TARGET),)
TARGET := beos
endif
ifeq ($(TARGET),haiku)
override TARGET := beos
endif
endif
ifeq ($(HOST),AmigaOS)
HOST := amiga
ifeq ($(TARGET),)
TARGET := amiga
endif
endif
ifeq ($(HOST),FreeMiNT)
HOST := mint
endif
ifeq ($(HOST),mint)
ifeq ($(TARGET),)
TARGET := atari
endif
endif
ifeq ($(findstring MINGW,$(HOST)),MINGW)
# MSYS' uname reports the likes of "MINGW32_NT-6.0"
HOST := windows
endif
ifeq ($(HOST),windows)
ifeq ($(TARGET),)
TARGET := windows
endif
endif
# Default target is GTK backend
ifeq ($(TARGET),)
TARGET := gtk3
endif
# valid values for the TARGET
VLDTARGET := riscos gtk2 gtk3 beos amiga amigaos3 framebuffer windows atari monkey
# Check for valid TARGET
ifeq ($(filter $(VLDTARGET),$(TARGET)),)
$(error Unknown TARGET "$(TARGET)", Must be one of $(VLDTARGET))
endif
# ensure empty values for base variables
# Sub target for build
SUBTARGET=
# Resources executable target depends upon
RESOURCES=
# Messages executable target depends on
@ -153,169 +60,11 @@ BUILD_CFLAGS = -g -W -Wall -Wundef -Wpointer-arith -Wcast-align \
-Wwrite-strings -Wmissing-declarations -Wuninitialized \
-Wno-unused-parameter
ifeq ($(TARGET),riscos)
ifeq ($(HOST),riscos)
# Build for RO on RO
GCCSDK_INSTALL_ENV := <NSLibs$$Dir>
CCRES := ccres
TPLEXT :=
MAKERUN := makerun
SQUEEZE := squeeze
RUNEXT :=
CC := gcc
CXX := g++
EXEEXT :=
PKG_CONFIG :=
else
# Cross-build for RO (either using GCCSDK 3.4.6 - AOF,
# either using GCCSDK 4 - ELF)
ifeq ($(origin GCCSDK_INSTALL_ENV),undefined)
ifneq ($(realpath /opt/netsurf/arm-unknown-riscos/env),)
GCCSDK_INSTALL_ENV := /opt/netsurf/arm-unknown-riscos/env
else
GCCSDK_INSTALL_ENV := /home/riscos/env
endif
endif
# compute HOST, TARGET and SUBTARGET
include frontends/Makefile.hts
ifeq ($(origin GCCSDK_INSTALL_CROSSBIN),undefined)
ifneq ($(realpath /opt/netsurf/arm-unknown-riscos/cross/bin),)
GCCSDK_INSTALL_CROSSBIN := /opt/netsurf/arm-unknown-riscos/cross/bin
else
GCCSDK_INSTALL_CROSSBIN := /home/riscos/cross/bin
endif
endif
CCRES := $(GCCSDK_INSTALL_CROSSBIN)/ccres
TPLEXT := ,fec
MAKERUN := $(GCCSDK_INSTALL_CROSSBIN)/makerun
SQUEEZE := $(GCCSDK_INSTALL_CROSSBIN)/squeeze
RUNEXT := ,feb
CC := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*gcc)
ifneq (,$(findstring arm-unknown-riscos-gcc,$(CC)))
SUBTARGET := -elf
EXEEXT := ,e1f
ELF2AIF := $(GCCSDK_INSTALL_CROSSBIN)/elf2aif
else
SUBTARGET := -aof
EXEEXT := ,ff8
endif
CXX := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*g++)
PKG_CONFIG := $(GCCSDK_INSTALL_ENV)/ro-pkg-config
endif
else
ifeq ($(TARGET),beos)
# Building for BeOS/Haiku
#ifeq ($(HOST),beos)
# Build for BeOS on BeOS
GCCSDK_INSTALL_ENV := /boot/develop
CC := gcc
CXX := g++
EXEEXT :=
PKG_CONFIG := pkg-config
#endif
else
ifeq ($(TARGET),windows)
ifneq ($(HOST),windows)
# Set Mingw defaults
GCCSDK_INSTALL_ENV ?= /opt/netsurf/i686-w64-mingw32/env
GCCSDK_INSTALL_CROSSBIN ?= /opt/netsurf/i686-w64-mingw32/cross/bin
CC := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*gcc)
WINDRES := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*windres)
PKG_CONFIG := PKG_CONFIG_LIBDIR="$(GCCSDK_INSTALL_ENV)/lib/pkgconfig" pkg-config
else
# Building on Windows
CC := gcc
PKG_CONFIG :=
endif
else
ifeq ($(findstring amiga,$(TARGET)),amiga)
ifeq ($(findstring amiga,$(HOST)),amiga)
PKG_CONFIG := pkg-config
else
ifeq ($(TARGET),amigaos3)
GCCSDK_INSTALL_ENV ?= /opt/netsurf/m68k-unknown-amigaos/env
GCCSDK_INSTALL_CROSSBIN ?= /opt/netsurf/m68k-unknown-amigaos/cross/bin
SUBTARGET = os3
else
GCCSDK_INSTALL_ENV ?= /opt/netsurf/ppc-amigaos/env
GCCSDK_INSTALL_CROSSBIN ?= /opt/netsurf/ppc-amigaos/cross/bin
endif
override TARGET := amiga
CC := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*gcc)
PKG_CONFIG := PKG_CONFIG_LIBDIR="$(GCCSDK_INSTALL_ENV)/lib/pkgconfig" pkg-config
endif
else
ifeq ($(TARGET),atari)
ifeq ($(HOST),atari)
PKG_CONFIG := pkg-config
else
ifeq ($(HOST),mint)
PKG_CONFIG := pkg-config
else
GCCSDK_INSTALL_ENV ?= /opt/netsurf/m68k-atari-mint/env
GCCSDK_INSTALL_CROSSBIN ?= /opt/netsurf/m68k-atari-mint/cross/bin
CC := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*gcc)
PKG_CONFIG := PKG_CONFIG_LIBDIR="$(GCCSDK_INSTALL_ENV)/lib/pkgconfig" pkg-config
endif
endif
else
ifeq ($(TARGET),monkey)
ifeq ($(origin GCCSDK_INSTALL_ENV),undefined)
PKG_CONFIG := pkg-config
else
PKG_CONFIG := PKG_CONFIG_LIBDIR="$(GCCSDK_INSTALL_ENV)/lib/pkgconfig" pkg-config
endif
ifneq ($(origin GCCSDK_INSTALL_CROSSBIN),undefined)
CC := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*gcc)
CXX := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*g++)
endif
else
ifeq ($(TARGET),framebuffer)
ifeq ($(origin GCCSDK_INSTALL_ENV),undefined)
PKG_CONFIG := pkg-config
else
PKG_CONFIG := PKG_CONFIG_LIBDIR="$(GCCSDK_INSTALL_ENV)/lib/pkgconfig" pkg-config
endif
ifneq ($(origin GCCSDK_INSTALL_CROSSBIN),undefined)
CC := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*gcc)
CXX := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*g++)
endif
else
# All native targets
# use native package config
PKG_CONFIG := pkg-config
# gtk target processing
ifeq ($(TARGET),gtk3)
override TARGET := gtk
override NETSURF_GTK_MAJOR := 3
SUBTARGET = $(NETSURF_GTK_MAJOR)
else
ifeq ($(TARGET),gtk2)
override TARGET := gtk
override NETSURF_GTK_MAJOR := 2
SUBTARGET = $(NETSURF_GTK_MAJOR)
endif
endif
endif
endif
endif
endif
endif
endif
endif
# target specific tool overrides
include frontends/$(TARGET)/Makefile.tools
# compiler versioning to adjust warning flags
CC_VERSION := $(shell $(CC) -dumpfullversion -dumpversion)

122
frontends/Makefile.hts Normal file
View File

@ -0,0 +1,122 @@
# -*- mode: makefile-gmake -*-
##
## determine the HOST TARGET and SUBTARGET
##
# Determine host type
# NOTE: HOST determination on RISC OS could fail because of missing bug fixes
# in UnixLib which only got addressed in UnixLib 5 / GCCSDK 4.
# When you don't have 'uname' available, you will see:
# File 'uname' not found
# When you do and using a 'uname' compiled with a buggy UnixLib, you
# will see the following printed on screen:
# RISC OS
# In both cases HOST make variable is empty and we recover from that by
# assuming we're building on RISC OS.
# In case you don't see anything printed (including the warning), you
# have an up-to-date RISC OS build system. ;-)
HOST := $(shell uname -s)
# Sanitise host
# TODO: Ideally, we want the equivalent of s/[^A-Za-z0-9]/_/g here
HOST := $(subst .,_,$(subst -,_,$(subst /,_,$(HOST))))
ifeq ($(HOST),)
HOST := riscos
$(warning Build platform determination failed but that's a known problem for RISC OS so we're assuming a native RISC OS build.)
else
ifeq ($(HOST),RISC OS)
# Fixup uname -s returning "RISC OS"
HOST := riscos
endif
endif
ifeq ($(HOST),riscos)
# Build happening on RO platform, default target is RO backend
ifeq ($(TARGET),)
TARGET := riscos
endif
endif
ifeq ($(HOST),BeOS)
HOST := beos
endif
ifeq ($(HOST),Haiku)
# Haiku implements the BeOS API
HOST := beos
endif
ifeq ($(HOST),beos)
# Build happening on BeOS platform, default target is BeOS backend
ifeq ($(TARGET),)
TARGET := beos
endif
ifeq ($(TARGET),haiku)
override TARGET := beos
endif
endif
ifeq ($(HOST),AmigaOS)
HOST := amiga
ifeq ($(TARGET),)
TARGET := amiga
endif
endif
ifeq ($(HOST),FreeMiNT)
HOST := mint
endif
ifeq ($(HOST),mint)
ifeq ($(TARGET),)
TARGET := atari
endif
endif
ifeq ($(findstring MINGW,$(HOST)),MINGW)
# MSYS' uname reports the likes of "MINGW32_NT-6.0"
HOST := windows
endif
ifeq ($(HOST),windows)
ifeq ($(TARGET),)
TARGET := windows
endif
endif
# Setup (sub)targets
# empty default sub target
SUBTARGET=
# Default target is GTK 3 backend
ifeq ($(TARGET),)
override TARGET := gtk
SUBTARGET = 3
else
ifeq ($(TARGET),gtk)
# unspecified gtk is gtk3
SUBTARGET = 3
else
ifeq ($(TARGET),gtk3)
# gtk3 is gtk target with subtarget of 3
override TARGET := gtk
SUBTARGET = 3
else
ifeq ($(TARGET),gtk2)
# gtk2 is gtk target with subtarget of 2
override TARGET := gtk
SUBTARGET = 2
else
ifeq ($(TARGET),amigaos3)
override TARGET := amiga
SUBTARGET = os3
endif
endif
endif
endif
endif
# valid values for the TARGET
VLDTARGET := amiga atari beos framebuffer gtk monkey riscos windows
# Check for valid TARGET
ifeq ($(filter $(VLDTARGET),$(TARGET)),)
$(error Unknown TARGET "$(TARGET)", Must be one of $(VLDTARGET))
endif

View File

@ -0,0 +1,21 @@
# -*- mode: makefile-gmake -*-
##
## amiga target tool setup
##
ifeq ($(findstring amiga,$(HOST)),amiga)
# building for amiga on amiga
PKG_CONFIG := pkg-config
else
ifeq ($(SUBTARGET),os3)
GCCSDK_INSTALL_ENV ?= /opt/netsurf/m68k-unknown-amigaos/env
GCCSDK_INSTALL_CROSSBIN ?= /opt/netsurf/m68k-unknown-amigaos/cross/bin
else
GCCSDK_INSTALL_ENV ?= /opt/netsurf/ppc-amigaos/env
GCCSDK_INSTALL_CROSSBIN ?= /opt/netsurf/ppc-amigaos/cross/bin
endif
CC := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*gcc)
PKG_CONFIG := PKG_CONFIG_LIBDIR="$(GCCSDK_INSTALL_ENV)/lib/pkgconfig" pkg-config
endif

View File

@ -0,0 +1,19 @@
# -*- mode: makefile-gmake -*-
##
## atari target tool setup
##
ifeq ($(HOST),atari)
PKG_CONFIG := pkg-config
else
ifeq ($(HOST),mint)
PKG_CONFIG := pkg-config
else
GCCSDK_INSTALL_ENV ?= /opt/netsurf/m68k-atari-mint/env
GCCSDK_INSTALL_CROSSBIN ?= /opt/netsurf/m68k-atari-mint/cross/bin
CC := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*gcc)
PKG_CONFIG := PKG_CONFIG_LIBDIR="$(GCCSDK_INSTALL_ENV)/lib/pkgconfig" pkg-config
endif
endif

View File

@ -0,0 +1,14 @@
# -*- mode: makefile-gmake -*-
##
## BeOS target tool setup
##
# Building for BeOS/Haiku
#ifeq ($(HOST),beos)
# Build for BeOS on BeOS
GCCSDK_INSTALL_ENV := /boot/develop
CC := gcc
CXX := g++
EXEEXT :=
PKG_CONFIG := pkg-config
#endif

View File

@ -0,0 +1,15 @@
# -*- mode: makefile-gmake -*-
##
## tool setup for the framebuffer target
##
ifeq ($(origin GCCSDK_INSTALL_ENV),undefined)
PKG_CONFIG := pkg-config
else
PKG_CONFIG := PKG_CONFIG_LIBDIR="$(GCCSDK_INSTALL_ENV)/lib/pkgconfig" pkg-config
endif
ifneq ($(origin GCCSDK_INSTALL_CROSSBIN),undefined)
CC := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*gcc)
CXX := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*g++)
endif

View File

@ -0,0 +1,16 @@
# -*- mode: makefile-gmake -*-
##
## tool setup for the gtk target
##
# use native package config
PKG_CONFIG := pkg-config
# gtk target processing
ifeq ($(SUBTARGET),3)
override NETSURF_GTK_MAJOR := 3
endif
ifeq ($(SUBTARGET),2)
override NETSURF_GTK_MAJOR := 2
endif

View File

@ -0,0 +1,15 @@
# -*- mode: makefile-gmake -*-
##
## monkey target tool setup
##
ifeq ($(origin GCCSDK_INSTALL_ENV),undefined)
PKG_CONFIG := pkg-config
else
PKG_CONFIG := PKG_CONFIG_LIBDIR="$(GCCSDK_INSTALL_ENV)/lib/pkgconfig" pkg-config
endif
ifneq ($(origin GCCSDK_INSTALL_CROSSBIN),undefined)
CC := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*gcc)
CXX := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*g++)
endif

View File

@ -0,0 +1,52 @@
# -*- mode: makefile-gmake -*-
##
## RISC OS target tool setup
##
ifeq ($(HOST),riscos)
# Build for RO on RO
GCCSDK_INSTALL_ENV := <NSLibs$$Dir>
CCRES := ccres
TPLEXT :=
MAKERUN := makerun
SQUEEZE := squeeze
RUNEXT :=
CC := gcc
CXX := g++
EXEEXT :=
PKG_CONFIG :=
else
# Cross-build for RO (either using GCCSDK 3.4.6 - AOF,
# either using GCCSDK 4 - ELF)
ifeq ($(origin GCCSDK_INSTALL_ENV),undefined)
ifneq ($(realpath /opt/netsurf/arm-unknown-riscos/env),)
GCCSDK_INSTALL_ENV := /opt/netsurf/arm-unknown-riscos/env
else
GCCSDK_INSTALL_ENV := /home/riscos/env
endif
endif
ifeq ($(origin GCCSDK_INSTALL_CROSSBIN),undefined)
ifneq ($(realpath /opt/netsurf/arm-unknown-riscos/cross/bin),)
GCCSDK_INSTALL_CROSSBIN := /opt/netsurf/arm-unknown-riscos/cross/bin
else
GCCSDK_INSTALL_CROSSBIN := /home/riscos/cross/bin
endif
endif
CCRES := $(GCCSDK_INSTALL_CROSSBIN)/ccres
TPLEXT := ,fec
MAKERUN := $(GCCSDK_INSTALL_CROSSBIN)/makerun
SQUEEZE := $(GCCSDK_INSTALL_CROSSBIN)/squeeze
RUNEXT := ,feb
CC := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*gcc)
ifneq (,$(findstring arm-unknown-riscos-gcc,$(CC)))
SUBTARGET := -elf
EXEEXT := ,e1f
ELF2AIF := $(GCCSDK_INSTALL_CROSSBIN)/elf2aif
else
SUBTARGET := -aof
EXEEXT := ,ff8
endif
CXX := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*g++)
PKG_CONFIG := $(GCCSDK_INSTALL_ENV)/ro-pkg-config
endif

View File

@ -0,0 +1,19 @@
# -*- mode: makefile-gmake -*-
##
## windows (win32) target tool setup
##
ifneq ($(HOST),windows)
# Set Mingw defaults
GCCSDK_INSTALL_ENV ?= /opt/netsurf/i686-w64-mingw32/env
GCCSDK_INSTALL_CROSSBIN ?= /opt/netsurf/i686-w64-mingw32/cross/bin
CC := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*gcc)
WINDRES := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*windres)
PKG_CONFIG := PKG_CONFIG_LIBDIR="$(GCCSDK_INSTALL_ENV)/lib/pkgconfig" pkg-config
else
# Building on Windows
CC := gcc
PKG_CONFIG :=
endif