[Simh] [RFC] build script improvements experiment
Peter Lund
firefly at vax64.dk
Tue Sep 18 13:05:36 EDT 2007
I have improved the build script over that sent previously ("[RFC,
PATCH] Linux Installer for VAX emulator").
* dependencies on include files ("header files") are automatically
detected
* works well with ccache (and apbuild and distcc) because
compilation and linking isn't done in a single step
* each simulator is built in its own directory -- necessary
because some simulators are tangled up and because some shared
files are compiled with different macro defines between the
simulators.
* the output is pretty now!
* since the output is pretty, warnings become very visible
* more portable makefile (use the shell to test OSTYPE variable)
* more portable makefile (actually detect cygwin and act
accordingly)
Some of the mechanics in the makefile is more complicated than strictly
necessary. I expect to fix that, I just haven't gotten round to it yet.
I also expect to add some code that can generate a simple "static"
makefile from this makefile so we can have a single canonical build
script and still get the portability of a very simple makefile -- or
even a linear list of commands to run.
Did I write "still"? Actually, the current makefile relies so much on
the "compile-and-link" feature of gcc that it really doesn't work for
anything else. The build system in my mercurial "build" branch is much
better even *without* the ability to generate a simplified makefile.
Adding the remaining architectures is expected to be easy but the
makefile is more malleable with fewer architectures in it so I'll wait a
bit before porting them over.
So, how do you get it?
1. apply the included patch on top of the last patch I sent.
(cumbersome)
2. go to http://vax64.dyndns.org/repo/hg/build and download the
current version as a ZIP file. (better)
3. run hg clone http://vax64.dyndns.org/repo/hg/build (best)
-Peter
diffstat:
b/makefile.inc | 207 +++++++++++++++++++++++++++
makefile | 423 ++++++++++++++++++++++++++++++++++++++++-----------------
2 files changed, 508 insertions(+), 122 deletions(-)
diff -r b0a8c6ad8866 makefile
--- a/makefile Thu Sep 13 06:27:10 2007 +0200
+++ b/makefile Tue Sep 18 17:47:59 2007 +0200
@@ -4,39 +4,64 @@
# be reinstated once I'm satisfied with the structure of the makefile.
# -- Peter Lund <firefly at vax64.dk>
#
-
-
-# Decent values for toolchain program
-#
-# These gymnastics mean the user can override CC, LD, and CCACHE when invoking
-# the makefile.
-ifneq ("$(origin CC)", "command line")
- ifneq ("$(origin CC)", "environment")
- CC=gcc
- endif
-endif
-ifneq ("$(origin LD)", "command line")
- ifneq ("$(origin LD)", "environment")
- # gcc acts as a wrapper around ld and passes it some Seekret Parameters that
- # make things work. Using gcc instead of ld is standard practice.
- LD=gcc
- endif
-endif
-ifneq ("$(origin CCACHE)", "command line")
- ifneq ("$(origin CCACHE)", "environment")
- CCACHE:=$(shell which ccache)
- endif
-endif
-
-# Use ccache to speed things up
-CC:=$(CCACHE) $(CC)
-LD:=$(CCACHE) $(LD)
-
-# nice and simple flags, can be overridden from the command line
-# FIXME doesn't work yet. The += used below in the file get inactivated when
-# CFLAGS is set from the command line
-CFLAGS ?= -O2 -g
-LDFLAGS :=
+# Copyright 2006,2007 Peter Lund <firefly at vax64.dk>
+# Released under GPL v2.
+#
+# Portions come from the Linux project, copyrighted by their respective
+# authors and also released under GPL v2.
+#
+#
+# A lot of the stuff in this Makefile is fugly boiler-plate code which will be
+# moved into a separate file once things have stabilized.
+#
+# It does provide some benefits to make up for all the complexity.
+# In no particular order:
+# 1) It checks for the existence of GTK+/Gnome/Cairo packages before doing
+# anything else in order to give the user sensible error messages.
+# 2) It turns *all* gcc warnings on. No, neither -W nor -Wall turns them all
+# on; you actually need both. This is compounded by the fact that -W has
+# been deprecated in favour of the new flag -Wextra in newer gccs!
+# 3) Header file dependencies (i.e. include files) are handled automatically.
+# 4) It automatically checks for (and uses) ccache.
+# 5) The screen output during compilation is nice to look at (à la the current
+# Linux kernels). You can get the traditional information overload by
+# passing V=1 as a parameter on the 'make' command-line.
+# 6) The code knows when it was compiled due the DATE variable being passed to
+# all compilation units (just like its friend, VERSION).
+
+##########################################################################
+#
+# Maintainable variables
+#
+
+# default variables -- can be overriden on the make command line
+# (WARNFLAGS gets set automatically to either '-W -Wall' or '-Wextra -Wall'
+# by Makefile.inc depending on what the compiler supports)
+CFLAGS=-Os -fomit-frame-pointer $(WARNFLAGSX) -g
+LDFLAGS=
+
+# The version number to pass to the program
+# (both VERSION and DATE gets defined in all compilation units)
+VERSION=3.7-3pfl
+
+# This is the default target if someone just writes 'make'
+DEFAULT_TARGET=all
+
+# Targets that don't require compiling and linking should be added to NOWORK
+NOWORK:=help clean distclean
+
+# See also PROGS and .PHONY below.
+
+##########################################################################
+
+# Lots of magic inside this file!
+include makefile.inc
+
+# Add version info
+CFLAGS:=$(CFLAGS) -DVERSION='"$(VERSION)"' -DDATE='"$(DATE)"'
+
+##########################################################################
+
# Default for network
USE_NETWORK=1
@@ -45,118 +70,272 @@ USE_NETWORK=1
# FIXME this macro needs a better name
XCFLAGS = $(CFLAGS)
-ifeq ($(WIN32),)
- #Unix Environments
- ifeq ($(OSTYPE),solaris)
- OS_CCDEFS = -D_GNU_SOURCE
+ifeq ($(WIN32),)
+ #Unix Environments
+ ifeq ($(shell echo $$OSTYPE),solaris)
+ OS_CCDEFS = -D_GNU_SOURCE
LDFLAGS += -lsocket -lnsl -lpthread
- else
- OS_CCDEFS = -D_GNU_SOURCE -DHAVE_READLINE
- LDFLAGS += -lrt -lreadline
- endif
-
- ifeq ($(OSTYPE),macos)
+ else
+ ifeq ($(shell echo $$OSTYPE),cygwin)
+ OS_CCDEFS = -D_GNU_SOURCE
+ LDFLAGS += -lreadline
+ else
+ OS_CCDEFS = -D_GNU_SOURCE -DHAVE_READLINE
+ LDFLAGS += -lrt -lreadline
+ endif
+ endif
+
+ ifeq ($(shell echo $$OSTYPE),macos)
XCFLAGS += -std=c99 -U__STRICT_ANSI__ $(OS_CCDEFS) -I .
LDFLAGS += -lm -lrt
- else
+ else
XCFLAGS += -std=c99 -U__STRICT_ANSI__ $(OS_CCDEFS) -I .
LDFLAGS += -lm
- endif
-
- ifneq ($(USE_NETWORK),)
- NETWORK_OPT = -DUSE_NETWORK
+ endif
+
+ ifneq ($(USE_NETWORK),)
+ NETWORK_OPT = -DUSE_NETWORK
XCFLAGS += -DUSE_NETWORK
LDFLAGS += -lpcap
- endif
-else
- #Win32 Environments
- LDFLAGS = -lm -lwsock32 -lwinmm
- XCFLAGS += -std=c99 -U__STRICT_ANSI__ -O0 -I.
- EXE = .exe
-
- ifneq ($(USE_NETWORK),)
- NETWORK_OPT = -DUSE_NETWORK -lwpcap -lpacket
+ endif
+else
+ #Win32 Environments
+ LDFLAGS = -lm -lwsock32 -lwinmm
+ XCFLAGS += -std=c99 -U__STRICT_ANSI__ -O0 -I.
+ EXE = .exe
+
+ ifneq ($(USE_NETWORK),)
+ NETWORK_OPT = -DUSE_NETWORK -lwpcap -lpacket
XCFLAGS += -DUSE_NETWORK
LDFLAGS += -lwpcap -lpacket
- endif
-endif
+ endif
+endif
#
# switch off GNU Make "features"
#
.SUFFIXES: # delete all default suffixes
-
-#
-# Common Libraries
-#
-BIN = BIN/
-
-
-#
-# Build everything
-#
-ALL = vax
-
-all : ${ALL}
-
-
-SIM = scp.c sim_console.c sim_fio.c sim_timer.c sim_sock.c \
+
+#
+# Common Libraries
+#
+
+
+#
+# Build everything
+#
+ALL = vax vax780 pdp11 nova eclipse altair altairz80
+
+all: $(ALL)
+
+##############
+
+
+SIM = scp.c sim_console.c sim_fio.c sim_timer.c sim_sock.c \
sim_tmxr.c sim_ether.c sim_tape.c
-VAX= VAX/vax_cpu.c VAX/vax_cpu1.c VAX/vax_fpa.c VAX/vax_io.c \
- VAX/vax_cis.c VAX/vax_octa.c VAX/vax_cmode.c \
- VAX/vax_mmu.c VAX/vax_stddev.c VAX/vax_sysdev.c \
+##############
+
+BIN BUILD-VAX BUILD-VAX780 BUILD-PDP11 BUILD-NOVA BUILD-ECLIPSE \
+BUILD-ALTAIR BUILD-ALTAIRZ80:
+ $(call show,Creating,$@\ directory)
+ $(Q)mkdir -p $@
+
+##############
+
+VAX= VAX/vax_cpu.c VAX/vax_cpu1.c VAX/vax_fpa.c VAX/vax_io.c \
+ VAX/vax_cis.c VAX/vax_octa.c VAX/vax_cmode.c \
+ VAX/vax_mmu.c VAX/vax_stddev.c VAX/vax_sysdev.c \
VAX/vax_sys.c VAX/vax_syscm.c VAX/vax_syslist.c \
- PDP11/pdp11_rl.c PDP11/pdp11_rq.c PDP11/pdp11_ts.c \
- PDP11/pdp11_dz.c PDP11/pdp11_lp.c PDP11/pdp11_tq.c \
- PDP11/pdp11_xq.c PDP11/pdp11_ry.c \
- PDP11/pdp11_vh.c PDP11/pdp11_cr.c
-
-VAXOBJS = $(patsubst %.c,%.o,$(VAX))
-SIMOBJS = $(patsubst %.c,%.o,$(SIM))
-
-# Temporarily removed until we have squeaky clean, open source firmware
-#
-#VAX/ka655x.h: VAX/ka655x.bin
-# ./wrapblob.pl 'firmware_ka655x' < $< > $@
-
-vax: $(BIN) $(BIN)vax$(EXE)
-
-BIN:
- mkdir -p BIN
-
-$(BIN)vax$(EXE): $(VAXOBJS) $(SIMOBJS) autopackage/binreloc.o
- $(LD) $(LDFLAGS) $^ -o $@
+ PDP11/pdp11_rl.c PDP11/pdp11_rq.c PDP11/pdp11_ts.c \
+ PDP11/pdp11_dz.c PDP11/pdp11_lp.c PDP11/pdp11_tq.c \
+ PDP11/pdp11_xq.c PDP11/pdp11_ry.c \
+ PDP11/pdp11_vh.c PDP11/pdp11_cr.c
+VAXOBJS = $(addprefix BUILD-VAX/,$(notdir $(patsubst %.c,%.o,$(VAX) $(SIM))))
+
+vax: BIN BUILD-VAX BIN/vax$(EXE)
+
+BIN/vax$(EXE): $(VAXOBJS) autopackage/binreloc.o
+ $(call show,Linking,$@)
+ $(Q)$(LD) $(LDFLAGS) $^ -o $@
define VAX_template
- $(1): $(2) *.h VAX/*.h PDP11/*.h # VAX/ka655x.h
- $$(CC) $$(XCFLAGS) -I VAX -I PDP11 -DVM_VAX -DUSE_INT64 -DUSE_ADDR64 -c $$< -o $$@
-endef
-
-$(foreach file,$(VAX) $(SIM),$(eval $(call VAX_template,$(patsubst %.c,%.o,$(file)),$(file))))
-
-autopackage/binreloc.o: autopackage/binreloc.c
- $(CC) $(XCFLAGS) -DENABLE_BINRELOC -c $< -o $@
-
-
-clean :
-ifeq ($(WIN32),)
- ${RM} ${BIN}* *.o */*.o *.package *.meta *.xml
-else
- if exist BIN\*.exe del /q BIN\*.exe *.package *.meta *.xml
-endif
+ $$(call DEPD,$(2),BUILD-VAX)
+ $$(call show,Compiling,$$<)
+ $$(Q)$$(CC) $$(XCFLAGS) -I VAX -I PDP11 -DVM_VAX -DUSE_INT64 -DUSE_ADDR64 -c $$< -o $$@
+endef
+
+$(foreach file,$(VAX) $(SIM),$(eval $(call VAX_template ,$(patsubst %.c,%.o,$(file)),$(file))))
+
+##############
+
+
+VAX780= VAX/vax_cpu.c VAX/vax_cpu1.c VAX/vax_fpa.c \
+ VAX/vax_cis.c VAX/vax_octa.c VAX/vax_cmode.c \
+ VAX/vax_mmu.c VAX/vax_sys.c VAX/vax_syscm.c \
+ VAX/vax780_stddev.c VAX/vax780_sbi.c \
+ VAX/vax780_mem.c VAX/vax780_uba.c VAX/vax780_mba.c \
+ VAX/vax780_fload.c VAX/vax780_syslist.c \
+ PDP11/pdp11_rl.c PDP11/pdp11_rq.c PDP11/pdp11_ts.c \
+ PDP11/pdp11_dz.c PDP11/pdp11_lp.c PDP11/pdp11_tq.c \
+ PDP11/pdp11_xu.c PDP11/pdp11_ry.c PDP11/pdp11_cr.c \
+ PDP11/pdp11_rp.c PDP11/pdp11_tu.c PDP11/pdp11_hk.c
+VAX780OBJS = $(addprefix BUILD-VAX780/,$(notdir $(patsubst %.c,%.o,$(VAX780) $(SIM))))
+
+
+define VAX780_template
+ $$(call DEPD,$(2),BUILD-VAX780)
+ $$(call show,Compiling,$$<)
+ $$(Q)$$(CC) $$(XCFLAGS) -I VAX -I PDP11 -DVM_VAX -DVAX_780 -DUSE_INT64 -DUSE_ADDR64 -c $$< -o $$@
+endef
+
+$(foreach file,$(VAX780) $(SIM),$(eval $(call VAX780_template,$(patsubst %.c,%.o,$(file)),$(file))))
+
+vax780: BIN BUILD-VAX780 BIN/vax780$(EXE)
+
+BIN/vax780$(EXE): $(VAX780OBJS) autopackage/binreloc.o
+ $(call show,Linking,$@)
+ $(Q)$(LD) $(LDFLAGS) $^ -o $@
+
+##############
+
+PDP11 = PDP11/pdp11_fp.c PDP11/pdp11_cpu.c PDP11/pdp11_dz.c \
+ PDP11/pdp11_cis.c PDP11/pdp11_lp.c PDP11/pdp11_rk.c \
+ PDP11/pdp11_rl.c PDP11/pdp11_rp.c PDP11/pdp11_rx.c \
+ PDP11/pdp11_stddev.c PDP11/pdp11_sys.c PDP11/pdp11_tc.c \
+ PDP11/pdp11_tm.c PDP11/pdp11_ts.c PDP11/pdp11_io.c \
+ PDP11/pdp11_rq.c PDP11/pdp11_tq.c PDP11/pdp11_pclk.c \
+ PDP11/pdp11_ry.c PDP11/pdp11_pt.c PDP11/pdp11_hk.c \
+ PDP11/pdp11_xq.c PDP11/pdp11_xu.c PDP11/pdp11_vh.c \
+ PDP11/pdp11_rh.c PDP11/pdp11_tu.c PDP11/pdp11_cpumod.c \
+ PDP11/pdp11_cr.c PDP11/pdp11_rf.c PDP11/pdp11_dl.c \
+ PDP11/pdp11_ta.c
+PDP11OBJS = $(addprefix BUILD-PDP11/,$(notdir $(patsubst %.c,%.o,$(PDP11) $(SIM))))
+
+define PDP11_template
+ $$(call DEPD,$(2),BUILD-PDP11)
+ $$(call show,Compiling,$$<)
+ $$(Q)$$(CC) $$(XCFLAGS) -I PDP11 -DVM_PDP11 -c $$< -o $$@
+endef
+
+$(foreach file,$(PDP11) $(SIM),$(eval $(call PDP11_template,$(patsubst %.c,%.o,$(file)),$(file))))
+
+pdp11: BUILD-PDP11 BIN/pdp11$(EXE)
+
+BIN/pdp11$(EXE): $(PDP11OBJS) autopackage/binreloc.o
+ $(call show,Linking,$@)
+ $(Q)$(LD) $(LDFLAGS) $^ -o $@
+
+
+#######################################
+
+
+NOVA= NOVA/nova_sys.c NOVA/nova_cpu.c NOVA/nova_dkp.c \
+ NOVA/nova_dsk.c NOVA/nova_lp.c NOVA/nova_mta.c \
+ NOVA/nova_plt.c NOVA/nova_pt.c NOVA/nova_clk.c \
+ NOVA/nova_tt.c NOVA/nova_tt1.c NOVA/nova_qty.c
+NOVAOBJS = $(addprefix BUILD-NOVA/,$(notdir $(patsubst %.c,%.o,$(NOVA) $(SIM))))
+
+ECLIPSE=NOVA/eclipse_cpu.c NOVA/eclipse_tt.c NOVA/nova_sys.c \
+ NOVA/nova_dkp.c NOVA/nova_dsk.c NOVA/nova_lp.c \
+ NOVA/nova_mta.c NOVA/nova_plt.c NOVA/nova_pt.c \
+ NOVA/nova_clk.c NOVA/nova_tt1.c NOVA/nova_qty.c
+ECLIPSEOBJS = $(addprefix BUILD-ECLIPSE/,$(notdir $(patsubst %.c,%.o,$(ECLIPSE) $(SIM))))
+
+
+define NOVA_template
+ $$(call DEPD,$(2),BUILD-NOVA)
+ $$(call show,Compiling,$$<)
+ $$(Q)$$(CC) $$(XCFLAGS) -I NOVA -c $$< -o $$@
+endef
+
+define ECLIPSE_template
+ $$(call DEPD,$(2),BUILD-ECLIPSE)
+ $$(call show,Compiling,$$<)
+ $$(Q)$$(CC) $$(XCFLAGS) -I NOVA -DECLIPSE -DUSE_INT64 -c $$< -o $$@
+endef
+
+$(foreach file,$(NOVA) $(SIM),$(eval $(call NOVA_template, $(patsubst %.c,%.o,$(file)),$(file))))
+$(foreach file,$(ECLIPSE) $(SIM),$(eval $(call ECLIPSE_template,$(patsubst %.c,%.o,$(file)),$(file))))
+
+nova: BUILD-NOVA BIN/nova$(EXE)
+
+BIN/nova$(EXE): $(NOVAOBJS) autopackage/binreloc.o
+ $(call show,Linking,$@)
+ $(Q)$(LD) $(LDFLAGS) $^ -o $@
+
+eclipse:BUILD-ECLIPSE BIN/eclipse$(EXE)
+
+BIN/eclipse$(EXE): $(ECLIPSEOBJS) autopackage/binreloc.o
+ $(call show,Linking,$@)
+ $(Q)$(LD) $(LDFLAGS) $^ -o $@
+
+
+#######################################
+
+ALTAIR= ALTAIR/altair_sio.c ALTAIR/altair_cpu.c ALTAIR/altair_dsk.c \
+ ALTAIR/altair_sys.c
+ALTAIROBJS = $(addprefix BUILD-ALTAIR/,$(notdir $(patsubst %.c,%.o,$(ALTAIR) $(SIM))))
+
+ALTAIRZ80= AltairZ80/altairz80_cpu.c AltairZ80/altairz80_dsk.c \
+ AltairZ80/altairz80_sio.c AltairZ80/altairz80_sys.c \
+ AltairZ80/altairz80_hdsk.c AltairZ80/altairz80_net.c
+ALTAIRZ80OBJS = $(addprefix BUILD-ALTAIRZ80/,$(notdir $(patsubst %.c,%.o,$(ALTAIRZ80) $(SIM))))
+
+
+define ALTAIR_template
+ $$(call DEPD,$(2),BUILD-ALTAIR)
+ $$(call show,Compiling,$$<)
+ $$(Q)$$(CC) $$(XCFLAGS) -I . -I ALTAIR -c $$< -o $$@
+endef
+
+define ALTAIRZ80_template
+ $$(call DEPD,$(2),BUILD-ALTAIRZ80)
+ $$(call show,Compiling,$$<)
+ $$(Q)$$(CC) $$(XCFLAGS) -I . -I AltairZ80 -c $$< -o $$@
+endef
+
+$(foreach file,$(ALTAIR) $(SIM),$(eval $(call ALTAIR_template, $(patsubst %.c,%.o,$(file)),$(file))))
+$(foreach file,$(ALTAIRZ80) $(SIM),$(eval $(call ALTAIRZ80_template,$(patsubst %.c,%.o,$(file)),$(file))))
+
+
+altair: BUILD-ALTAIR BIN/altair$(EXE)
+
+BIN/altair$(EXE): $(ALTAIROBJS) autopackage/binreloc.o
+ $(call show,Linking,$@)
+ $(Q)$(LD) $(LDFLAGS) $^ -o $@
+
+altairz80: BUILD-ALTAIRZ80 BIN/altairz80$(EXE)
+
+BIN/altairz80$(EXE): $(ALTAIRZ80OBJS) autopackage/binreloc.o
+ $(call show,Linking,$@)
+ $(Q)$(LD) $(LDFLAGS) $^ -o $@
+
+
+#######################################
+
+
+$(call DEP,autopackage/binreloc.c)
+ $(call show,Compiling,$<)
+ $(Q)$(CC) $(XCFLAGS) -DENABLE_BINRELOC -c $< -o $@
+
+
+clean:
+ rm -rf BIN BUILD-* *.o */*.o *.package *.meta *.xml a.out *.ps *.pdf
distclean: clean
rm -f *~ */*~ */*/*~ xx.ps xxx.ps *.package *.meta *.xml *.xml.old
help:
- @echo 'make {vax|pdp11|nova|eclipse|...} builds specific emulators'
- @echo 'make [all] builds all emulators'
+ @echo 'make [all] -- builds all emulators'
+ @echo 'make {vax|pdp11|nova|...} -- builds specific emulators'
@echo ''
- @echo 'make clean delete compiled programs'
- @echo 'make distclean delete everything but source'
- @echo 'make USE_NETWORK=1 <target> enable network emulation'
- @echo 'make CC=... <target> override default C compiler'
-
-
+ @echo 'make clean -- deletes compiled programs'
+ @echo 'make distclean -- deletes everything but source'
+ @echo ''
+ @echo 'make USE_NETWORK= <target> -- disable network emulation'
+ @echo 'make CC=... <target> -- override default C compiler'
+ @echo ''
+ @echo ' add V=1 for copious output, C=0 for bland output'
+
diff -r b0a8c6ad8866 makefile.inc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/makefile.inc Sun Sep 16 23:58:04 2007 +0200
@@ -0,0 +1,207 @@
+# -*-Makefile-*- (make Emacs colour us nicely)
+#
+# Makefile magic for Aqua-Planner
+# (but actually rather project agnostic)
+#
+# Copyright 2006,2007 Peter Lund <firefly at vax64.dk>
+# Released under GPL v2.
+#
+# Portions come from the Linux project, copyrighted by their respective
+# authors and also released under GPL v2.
+#
+# This GNU Make include file communicates with the encompassing Makefile
+# through a number of variables. Furthermore, a thing or two happens as a
+# side effect of including this file.
+#
+# Input:
+# // automatic package dependency check
+# PACKAGES - pkg-config packages to check for
+#
+# // optimization for simple targets
+# NOWORK - makefile targets that don't produce output files
+#
+# Output:
+# // compilation timestamp in about box and --version
+# DATE - current date (i.e. '2007-03-23')
+#
+# // gcc compatibility fix
+# WARNFLAGS - '-W -Wall' or '-Wextra -Wall'
+#
+# // automatic fast compilation + can be overridden from the command-line
+# CC - 'gcc' (or 'ccache gcc')
+# CXX - 'g++' (or 'ccache g++')
+# LD - 'ld' (or 'ccache ldd')
+#
+# // faster (re)compilation
+# CCACHE - empty or the path to ccache
+#
+# // better dependency checking
+# DEP - a macro that checks a top-level C file for include file
+# dependencies.
+#
+# // beautifying the socalled "compile spew"
+# show - potentially writes a human-readable explanatory text
+# Q - "$(Q)...commands..." potentially hides the command-line
+#
+# Side effects:
+# Checks that the pkg-config packages listed in PACKAGES are installed.
+#
+
+
+# This would be a good place to check the input variables to see if the
+# contract is being respected. However, it is perfectly fine if PACKAGES
+# is empty (= don't check for any packages) or NOWORK is empty (because it's
+# only an optimization).
+
+
+# ---------------------------------------------------------------------------
+# Decent values for toolchain program
+#
+# These gymnastics mean the user can override CC, LD, and CCACHE when invoking
+# the makefile.
+ifneq ("$(origin CC)", "command line")
+ ifneq ("$(origin CC)", "environment")
+ CC=gcc
+ endif
+endif
+ifneq ("$(origin LD)", "command line")
+ ifneq ("$(origin LD)", "environment")
+ # gcc acts as a wrapper around ld and passes it some Seekret Parameters that
+ # make things work. Using gcc instead of ld is standard practice.
+ LD=gcc
+ endif
+endif
+ifneq ("$(origin CCACHE)", "command line")
+ ifneq ("$(origin CCACHE)", "environment")
+ CCACHE:=$(shell which ccache)
+ endif
+endif
+
+
+
+# ---------------------------------------------------------------------------
+# Handle command-line flags: C={0|1} V={0|1}
+
+ifdef C
+ ifeq ("$(origin C)", "command line")
+ COLOURS := $(C)
+ endif
+endif
+ifndef COLOURS
+ COLOURS := 1
+endif
+
+ifeq ($(COLOURS),1)
+ # ESC [1m - intensity on
+ bold := \\033[1m
+
+ # ESC [0m - intensity off
+ normal := \\033[0m
+else
+ bold :=
+ normal :=
+endif
+
+
+# Copied from Linux 2.6.5 Makefile (GPL)
+# To put more focus on warnings, be less verbose by default
+# Use 'make V=1' to see the full commands
+
+ifdef V
+ ifeq ("$(origin V)", "command line")
+ VERBOSE := $(V)
+ endif
+endif
+ifndef VERBOSE
+ VERBOSE := 0
+endif
+
+ifeq ($(VERBOSE),1)
+ quiet :=
+ Q :=
+ devnull:=
+else
+ quiet := quiet_
+ Q := @
+ devnull:= > /dev/null 2>&1
+endif
+
+# Do not print "Entering directory ..."
+MAKEFLAGS += --no-print-directory
+
+
+# ---------------------------------------------------------------------------
+# Decent output
+
+# either print a msg such as "Compiling BUILD/debug-a/api.o" or do nothing
+show2= $(if $(quiet),printf $(bold)%-13s$(normal)%s\\n $(1) $(2);)
+show= @$(if $(quiet),printf $(bold)%-13s$(normal)%s\\n $(1) $(2))
+
+# ---------------------------------------------------------------------------
+
+# The default make target is 'all'
+ifeq ($(MAKECMDGOALS),)
+ MAKECMDGOALS:=$(DEFAULT_TARGET)
+endif
+
+REALWORK:=$(filter-out $(NOWORK),$(MAKECMDGOALS))
+
+# In order to make simple make invocations quick (such as 'make help'), try not
+# to make any unnecessary work. Calling out to the shell to get the current
+# date, check supported gcc flags, or installed packages should not be done
+# unless necessary.
+ifneq ($(REALWORK),)
+
+DATE:=$(shell date +%Y-%m-%d)
+
+# Older versions of gcc (pre 3.4) required -W -Wall if you really wanted
+# *all* warnings. -Wall was NOT enough.
+# Newer versions (3.4+) deprecate -W in favour of -Wextra.
+# Presumably future versions won't recognize -W anymore.
+ifeq ($(shell $(CC) --verbose --help 2>&1 | grep -- -Wextra),)
+ WARNFLAGS:=-W -Wall
+else
+ WARNFLAGS:=-Wextra -Wall
+endif
+
+CCACHE:=$(shell which ccache)
+
+CC =$(CCACHE) gcc
+CXX=$(CCACHE) g++
+LD =$(CCACHE) gcc
+
+
+endif # REALWORK
+
+
+# Automatically check and add dependencies
+#
+# Use as a replacement for the normal explicit target/dependency listing.
+#
+# Instead of writing this:
+# src/ap.o: src/ap.c src/model.h src/region.h
+# ...commands...
+#
+# you write this:
+# $(call DEP,src/ap.c)
+# ...commands...
+#
+#
+# Obfuscated GNU Make warning:
+# line feeds get changed to spaces by GNU make so '\' characters used as line
+# continuations must be removed lest they confuse make later on into believing
+# there are dependencies on files named ' ' (quoted spaces). Hence the
+# $(subst).
+#
+# Caveat:
+# Only works with gcc or compatible C compilers.
+ifneq ($(REALWORK),)
+DEP =$(subst \, ,$(shell cpp -MM $(1) -MT $(basename $(1)).o -I . $(CFLAGS)))
+DEPD=$(subst \, ,$(shell cpp -MM $(1) -MT $(2)/$(notdir $(basename $(1))).o -I . $(CFLAGS)))
+else
+DEP =$(basename $(1)).o: $(1)
+DEPD=$(2)/$(basename $(1)).o: $(1)
+endif
+
+
+
More information about the Simh
mailing list