Initial Spring 2016 commit.

This commit is contained in:
Geoffrey Challen
2015-12-23 00:50:04 +00:00
commit cafa9f5690
732 changed files with 92195 additions and 0 deletions

83
mk/fixdepends.sh Executable file
View File

@@ -0,0 +1,83 @@
#!/bin/sh
# fixdepends.sh - munge gcc -M output
# usage: gcc -M foo.c | fixdepends.sh INSTALLTOP host|native > .depend
# (where INSTALLTOP is $(INSTALLTOP) from the build makefiles)
if [ $# != 2 ]; then
echo "$0: Usage: $0 INSTALLTOP host|native" 1>&2
exit 1
fi
INSTALLTOP="$1"
MODE="$2"
case "$MODE" in
host|native) ;;
*) echo "$0: invalid mode $MODE; should be host or native" 1>&2
exit 1
;;
esac
awk '
# Any blank lines appear between object files.
/^$/ {
printit();
next;
}
# A line beginning with a space is a second or subsequent line of
# depends.
/^ / {
for (i=1;i<=NF;i++) {
if ($i != "\\") {
deps[++ndeps] = $i;
}
}
next;
}
# Any other line begins a new object file.
{
# Print the object file we already have, if any.
printit();
# Trim the colon after the object file name.
object = $1;
sub(":$", "", object);
# If in host mode, change .o to .ho.
if (mode == "host") {
sub("\\.o$", ".ho", object);
}
# Anything else on the line is a depend.
for (i=2;i<=NF;i++) {
if ($i != "\\") {
deps[++ndeps] = $i;
}
}
next;
}
END {
# Print the object file we have, if any, so as to not lose the
# last one.
printit();
}
function printit() {
if (ndeps == 0) {
# We have no object file in progress, so do nothing.
return;
}
# Insert MYBUILDDIR before the object file name.
printf "$(MYBUILDDIR)/%s: \\\n", object;
for (i=1;i<=ndeps;i++) {
printf " %s", deps[i];
# Lines before the last need continuation.
if (i < ndeps) {
printf " \\";
}
printf "\n";
}
# We no longer have anything to print.
ndeps = 0;
object = "/WRONG";
}
# Afterwards run sed to substitute INSTALLTOP.
' "mode=$MODE" | sed '
s,'"$INSTALLTOP"',$(INSTALLTOP),
'

20
mk/installheaders.sh Executable file
View File

@@ -0,0 +1,20 @@
#!/bin/sh
# installheaders.sh - install header files
# usage: installheaders.sh srcdir destdir
# srcdir/*.h is copied to destdir, if different.
#
if [ $# != 2 ]; then
echo "$0: Usage: $0 srcdir destdir" 1>&2
exit 1
fi
for H in "$1"/*.h; do
BH=`basename "$H"`
if diff "$H" "$2/$BH" >/dev/null 2>&1; then
:
else
echo cp "$H" "$2/$BH"
cp "$H" "$2/$BH"
fi
done

78
mk/os161.baserules.mk Normal file
View File

@@ -0,0 +1,78 @@
#
# OS/161 build environment: some very basic rules.
#
# Individual program makefiles should use os161.prog.mk or
# os161.lib.mk instead of including this file directly.
#
# The variable MKDIRS is used to generate rules for creating
# (mostly installation) directories via os161.mkdirs.mk.
# Process this file only once even if included repeatedly
.if !defined(_BASERULES_MK_)
_BASERULES_MK_=# empty
#
# Establish that all these (basic) rules exist and depend on the
# local (non-subdir) version.
#
.for _T_ in all depend install install-staging clean distclean tags
$(_T_): ;
$(_T_): $(_T_)-local
.PHONY: $(_T_) $(_T_)-local
.endfor
# distclean implies clean
distclean: clean-local
#
# Some other derived rules.
#
# cleandir is the same as distclean (cleandir is the old BSD name)
cleandir: distclean-local
# "stage" is a good short name for install-staging
stage: install-staging-local
# dependall means depend then compile, but it's important to run a
# new make after depending so the new depends take effect.
dependall-local: depend-local
$(MAKE) all-local
dependall: dependall-local
# build means depend, compile, and install-staging; it also needs a
# new make after depending. It could use the same one for compile
# and install-staging, but that turns out to be awkward.
build-local: dependall-local
$(MAKE) install-staging-local
build: build-local
# rebuild cleans first
rebuild: clean-local .WAIT build-local
# fullrebuild does distclean
fullrebuild: distclean-local .WAIT build-local
# implement BUILDSYMLINKS
.if "$(BUILDSYMLINKS)" == "yes"
.if !exists(build)
all depend: buildlink
.endif
buildlink:
ln -s $(MYBUILDDIR) build
clean: remove-buildlink
remove-buildlink:
rm -f build
.PHONY: buildlink remove-buildlink
.endif
.PHONY: cleandir stage dependall build rebuild fullrebuild
.PHONY: dependall-local build-local
.endif # _BASERULES_MK_
.include "$(TOP)/mk/os161.mkdirs.mk"
# End.

75
mk/os161.compile.mk Normal file
View File

@@ -0,0 +1,75 @@
#
# OS/161 build environment: compile source files.
#
# Usage: use os161.prog.mk or os161.lib.mk
#
# Variables controlling this file:
#
# SRCS .c and .S files to compile.
#
# Provides:
#
# OBJS .o files from compilation.
#
# Objects list starts empty. It is added to below.
OBJS=
clean-local: cleancompile
cleancompile:
rm -f $(MYBUILDDIR)/*.[oa]
distclean-local: distcleancompile
distcleancompile:
rm -f $(MYBUILDDIR)/.depend
#
# Depend: generate dependency information.
# Use gcc's -M argument for this.
#
# Note that we use -M rather than -MM, to get both system headers
# and program-local headers. This is because we *are* the system and
# we might well change those system headers.
#
# The fixdepends script transforms the results by substituting some
# make variables back into them; this way the depend files are
# independent of (at least some of) the build configuration. It also
# allows for placing the .o files in the build directory.
#
depend-local: $(MYBUILDDIR) .WAIT predepend .WAIT dependcompile
dependcompile:
$(CC) $(CFLAGS) $(MORECFLAGS) -M $(SRCS) |\
$(TOP)/mk/fixdepends.sh '$(INSTALLTOP)' native \
> $(MYBUILDDIR)/.deptmp
mv -f $(MYBUILDDIR)/.deptmp $(MYBUILDDIR)/.depend
.-include "$(MYBUILDDIR)/.depend"
predepend:
.PHONY: predepend
tags: tagscompile
tagscompile:
ctags -wtd $(SRCS) *.h
#
# Compile rules.
# We can use the same rules for .c and .S because gcc knows how to handle
# .S files.
#
# Make it so typing "make foo.o" does the right thing.
#
.for _S_ in $(SRCS:M*.[cS])
OBJS+=$(MYBUILDDIR)/$(_S_:T:R).o
$(MYBUILDDIR)/$(_S_:T:R).o: $(_S_)
$(CC) $(CFLAGS) $(MORECFLAGS) -c $(_S_) -o $(.TARGET)
$(_S_:T:R).o: $(MYBUILDDIR)/$(_S_:T:R).o
.PHONY: $(_S_:T:R).o
.endfor
# Make non-file rules PHONY.
.PHONY: clean-local cleancompile distclean-local distcleancompile
.PHONY: depend-local dependcompile tags tagscompile
# End.

32
mk/os161.config-mips.mk Normal file
View File

@@ -0,0 +1,32 @@
#
# OS/161 build environment extra definitions for MIPS.
# This is included by os161.config.mk.
#
#
# The MIPS toolchain for OS/161 is an ELF toolchain that by default
# generates SVR4 ELF ABI complaint code. This means that by default
# all code is PIC (position-independent code), which is all very well
# but not something we need or want in the kernel. So we use -fno-pic
# to turn this behavior off.
#
# We turn it off for userland too because we don't support shared
# libraries. Before trying to implement shared libraries, these
# options need to be taken out of CFLAGS.
#
# It turns out you also need -mno-abicalls to turn it off completely.
#
CFLAGS+=-mno-abicalls -fno-pic
KCFLAGS+=-mno-abicalls -fno-pic
#
# Extra stuff required for the kernel.
#
# -ffixed-23 reserves register 23 (s7) to hold curthread. This register
# number must match the curthread definition in mips/thread.h and the
# code in trap.S.
#
KCFLAGS+=-ffixed-23
KLDFLAGS+=

476
mk/os161.config.mk Normal file
View File

@@ -0,0 +1,476 @@
#
# OS/161 build environment base definitions
#
# Proper usage:
# TOP=../.. # or however many levels needed
# .include "$(TOP)/mk/os161.config.mk"
#
# This file takes care of including $(TOP)/defs.mk and sets defaults
# for things that can be defined there.
#
# It and defs.mk collaboratively set various make variables that
# control the build environment.
#
############################################################
#
# These build variables are meant to be user-settable:
#
# (Locations.)
#
# OSTREE The root directory you run OS/161 in.
# Default is ~/os161/root.
#
# WORKDIR Top of a tree to use for compiling.
# Default is $(TOP)/build.
#
# BUILDSYMLINKS If set to "yes", symlinks in each directory
# will be made to point into $(BUILDTOP).
# Default is "yes".
#
# By default the system will be built within the source tree and
# installed to ~/os161/root. It is expected this will be sufficient
# for most uses. If your root directory is somewhere else, set OSTREE
# in defs.mk. If you're running on a large computing cluster with
# networked home directories, setting WORKDIR to point somewhere on a
# local disk will probably make your builds quite a bit faster, at the
# cost of having to recompile if you switch to a different machine.
# If you want the source tree to be completely read-only, which is
# occasionally useful for tracking down build glitches, you can set
# WORKDIR and also set BUILDSYMLINKS to no.
#
# (Platform.)
#
# PLATFORM The type of system we're building for.
# Should always be set by defs.mk.
#
# MACHINE The processor type we're building for.
# Should always be set by defs.mk.
#
# The target machine type is set when you configure the source tree.
# If you change it, be sure to make distclean and recompile everything.
# Not all possible combinations of PLATFORM and MACHINE are allowed.
# See the logic at the bottom of this file for a list of supported
# combinations. If you are trying to port OS/161 to a new machine, the
# first step is to update that list.
#
# (Compilation.)
#
# DEBUG Compiler option for debug vs. optimize.
# Default: -O2
#
# WARNINGS Compiler options for warnings.
# Default: -Wall -Wextra -Wwrite-strings
# -Wmissing-prototypes
#
# WERROR Compiler option to make warnings fatal.
# Default: -Werror
#
# Since debugging of user-level programs is not supported in OS/161
# (and not really supportable without a lot of work on your part)
# there's usually not much reason to change DEBUG. If you want to,
# however, the easiest way is to usually set it on the make command
# line:
# make clean
# make DEBUG=-g all
# recompiles the current directory with debug info.
#
# Similarly, if you have a lot of warnings and you want to temporarily
# ignore them while you fix more serious problems, you can turn off
# the error-on-warning behavior on the fly by setting WERROR to empty:
# make WERROR=
#
# This convenience is why these variables are separately defined
# rather than just being rolled into CFLAGS.
#
############################################################
#
# These build variables can be set explicitly for further control if
# desired, but should in general not need attention.
#
# (Locations.)
#
# BUILDTOP Top of tree where .o files go.
# Default is $(WORKDIR).
#
# TOOLDIR Place for compiled programs used in
# the build. Default is $(WORKDIR)/tooldir.
#
# INSTALLTOP Staging directory for installation.
# Default is $(WORKDIR)/install
#
# Probably the only reason to change these would be if you're short on
# diskspace in $(WORKDIR).
#
# (Platform.)
#
# GNUTARGET The GNU gcc/binutils name for the
# target we're building for.
# Defaults to $(MACHINE)-harvard-os161.
#
# This should not need to be changed.
#
# (Programs.)
#
# CC (Cross-)compiler.
# Default is $(GNUTARGET)-gcc.
#
# LDCC (Cross-)compiler when invoked for linking.
# Default is $(CC).
#
# AS (Cross-)assembler.
# Default is $(GNUTARGET)-as.
#
# LD (Cross-)linker.
# Default is $(GNUTARGET)-ld.
#
# AR Archiver (librarian).
# Default is $(GNUTARGET)-ar.
#
# RANLIB Library postprocessor/indexer.
# Default is $(GNUTARGET)-ranlib.
#
# NM Tool to print symbol tables.
# Default is $(GNUTARGET)-nm.
#
# SIZE Tool to print sizes of binaries.
# Default is $(GNUTARGET)-size.
#
# STRIP Tool to remove debugging information.
# Default is $(GNUTARGET)-strip.
#
# The above are the compilation tools for OS/161. They create programs
# that run on OS/161. Since OS/161 is not meant to be self-hosting,
# programs that we need to run during the build, or run manually
# outside of the machine simulator, need to be compiled with a
# different compiler that creates programs that run for the "host" OS,
# whatever that is (Linux, NetBSD, FreeBSD, MacOS X, Solaris, etc.)
# The host compilation tools are prefixed with HOST_ as follows:
#
#
# HOST_CC Host compiler.
# Default is gcc.
#
# HOST_LDCC Host compiler when invoked for linking.
# Default is $(HOST_CC).
#
# HOST_AS Host assembler.
# Default is as.
#
# HOST_LD Host linker.
# Default is ld.
#
# HOST_AR Host archiver (librarian).
# Default is ar.
#
# HOST_RANLIB Host library postprocessor/indexer.
# Default is ranlib.
#
# HOST_NM Host tool to print symbol tables.
# Default is nm.
#
# HOST_SIZE Host tool to print sizes of binaries.
# Default is size.
#
# HOST_STRIP Host tool to remove debugging information.
# Default is strip.
#
# In general there should be no need to change the cross-compiler
# variables, unless you are e.g. trying to build OS/161 with something
# other than gcc, or you want to supply an explicit location for a
# specific copy of gcc somewhere rather than use the one on your
# $PATH.
#
# However, on some systems it might conceivably be necessary to change
# the host tool variables. For example, there are some (now extremely
# old) systems where "ranlib" is not only not needed but also corrupts
# libraries, in which case you might set HOST_RANLIB=true. If your
# host machine doesn't have "gcc" you may be able to set HOST_CC=cc
# and fiddle with HOST_WARNINGS and HOST_CFLAGS (below) and have
# things still more or less work.
#
# (Compilation.)
#
# HOST_DEBUG Like DEBUG, but for programs to be
# built to run on the host OS.
# Default is $(DEBUG).
#
# HOST_WARNINGS Like WARNINGS, but for programs to be
# built to run on the host OS.
# Default is $(WARNINGS).
#
# HOST_WERROR Like WERROR, but for programs to be
# built to run on the host OS.
# Default is $(WERROR).
#
############################################################
#
# These build variables should probably not be tinkered with in
# defs.mk and serve as baseline values to be added to by individual
# program makefiles and used by other os161.*.mk files.
#
# (Compilation.)
#
# CFLAGS Full baseline compile flags.
# Default is $(DEBUG) $(WARNINGS) $(WERROR),
# plus what's needed for -nostdinc.
#
# KCFLAGS Like CFLAGS, but for the kernel, which
# configures debug/optimize separately.
# Default is $(KDEBUG) $(WARNINGS) $(WERROR).
# (KDEBUG is set by the kernel config script.)
#
# HOST_CFLAGS Like CFLAGS, but for programs to be
# built to run on the host OS. Default is
# $(HOST_DEBUG) $(HOST_WARNINGS) $(HOST_WERROR).
#
# LDFLAGS Baseline link-time flags.
# Default is empty plus what's needed for
# -nostdlib.
#
# KLDFLAGS Baseline link-time flags for kernel.
# Default is empty.
#
# HOST_LDFLAGS Like LDFLAGS, but for programs to be
# built to run on the host OS.
# Default is empty.
#
# LIBS Baseline list of libraries to link to.
# Default is empty plus what's needed for
# -nostdlib.
#
# HOST_LIBS Like LIBS, but for programs to be
# built to run on the host OS.
# Default is empty.
#
############################################################
#
# These variables should not be changed directly, or by individual
# program makefiles either, and are for use by other os161.*.mk files.
#
# (Locations.)
#
# MYDIR Name of current source directory, relative
# to $(TOP); e.g. bin/sh.
#
# MYBUILDDIR Build directory for current source directory.
#
# MKDIRS Directories to create, mostly for installing.
#
# ABSTOP_PATTERN, ABSTOP Private, used to compute other locations.
#
# (Compilation.)
#
# MORECFLAGS Same as CFLAGS but comes later on the
# compile command line. In general individual
# makefiles shouldn't touch this.
# Default is empty plus what's needed for
# -nostdinc.
#
# MORELIBS Same as LIBS but comes after on the link
# line. In general individual makefiles
# shouldn't touch this.
# Default is empty plus what's needed for
# -nostdlib.
#
############################################################
# Some further vars that currently exist but should be moved
# around elsewhere:
#
# COMPAT_CFLAGS
# COMPAT_TARGETS
############################################################
# Establish defaults.
# (Variables are set in the order documented above.)
#
# These definitions are set firmly here (that is, not with ?=) because
# some of them, like CC, are predefined by make. Because defs.mk is
# included afterwards it can override any of these settings.
#
#
# User-settable configuration
#
# Locations of things.
OSTREE=$(HOME)/os161/root # Root directory to install into.
WORKDIR=$(TOP)/build # Top of tree to build into.
BUILDSYMLINKS=yes # yes => link build -> $(BUILDTOP)/$(HERE).
# Platform we're building for.
PLATFORM=sys161
MACHINE=mips
# Compilation
DEBUG=-O2
WARNINGS=-Wall -W -Wwrite-strings -Wmissing-prototypes
WERROR=-Werror
#
# Less-likely-to-need-setting
#
# Locations of things.
BUILDTOP=$(WORKDIR) # Top of directory for compiler output.
TOOLDIR=$(WORKDIR)/tooldir # Place for host progs used in the build.
INSTALLTOP=$(WORKDIR)/install # Staging area for installation.
# Platform.
GNUTARGET=$(MACHINE)-harvard-os161
# Programs and tools.
CC=$(GNUTARGET)-gcc # Compiler.
LDCC=$(CC) # Compiler when used for linking.
AS=$(GNUTARGET)-as # Assembler.
LD=$(GNUTARGET)-ld # Linker.
AR=$(GNUTARGET)-ar # Archiver.
RANLIB=$(GNUTARGET)-ranlib # Library indexer.
NM=$(GNUTARGET)-nm # Symbol dumper.
SIZE=$(GNUTARGET)-size # Size tool.
STRIP=$(GNUTARGET)-strip # Debug strip tool.
HOST_CC=gcc # Host compiler.
HOST_LDCC=$(HOST_CC) # Host compiler when used for linking.
HOST_AS=as # Host assembler.
HOST_LD=ld # Host linker.
HOST_AR=ar # Host archiver.
HOST_RANLIB=ranlib # Host library indexer.
HOST_NM=nm # Host symbol dumper.
HOST_SIZE=size # Host size tool.
HOST_STRIP=strip # Host debug strip tool.
# Compilation.
HOST_DEBUG=$(DEBUG)
HOST_WARNINGS=$(WARNINGS)
HOST_WERROR=$(WERROR)
#
# Probably-shouldn't-be-touched
#
CFLAGS=$(DEBUG) $(WARNINGS) $(WERROR) -std=gnu99
KCFLAGS=$(KDEBUG) $(WARNINGS) $(WERROR) -std=gnu99
HOST_CFLAGS=$(HOST_DEBUG) $(HOST_WARNINGS) $(HOST_WERROR) \
-I$(INSTALLTOP)/hostinclude
LDFLAGS=
KLDFLAGS=
HOST_LDFLAGS=
LIBS=
HOST_LIBS=
#
# Don't touch.
#
MORECFLAGS=
MORELIBS=
# lib/hostcompat.
COMPAT_CFLAGS=
COMPAT_TARGETS=
############################################################
# Get defs.mk to get the real configuration for this tree.
# If it doesn't exist, we'll go with the defaults.
.-include "$(TOP)/defs.mk"
############################################################
# Make sure we have a supported PLATFORM and MACHINE.
# We support mips on system/161.
SUPPORTED_TARGETS=sys161 mips
_OK_=0
.for _P_ _M_ in $(SUPPORTED_TARGETS)
.if "$(PLATFORM)" == "$(_P_)" && "$(MACHINE)" == "$(_M_)"
_OK_=1
.endif
.endfor
.if "$(_OK_)" != "1"
.init:
@echo "Platform $(PLATFORM) and machine $(MACHINE) not supported"
@false
.endif
############################################################
# Get any machine-dependent flags or makefile definitions
.-include "$(TOP)/mk/os161.config-$(MACHINE).mk"
############################################################
# Establish some derived locations.
#
# Absolute location of the top of the source tree. This should only be
# used to un-absolutize other paths; the tree ought to be independent
# of where it happens to live.
#
# This works by turning $(TOP) into a regexp and substituting it into
# the current directory. Note that it doesn't escape all regexp
# metacharacters -- if you make a directory named "foo*bar" or
# something you deserve the consequences.
#
# .CURDIR is a make builtin.
#
ABSTOP_PATTERN=$(TOP:S/./\\./g:S/\\.\\./[^\/]*/g)
ABSTOP=$(.CURDIR:C/$(ABSTOP_PATTERN)\$//)
# Find the name of the current directory relative to TOP.
# This works by removing ABSTOP from the front of .CURDIR.
MYDIR=$(.CURDIR:S/^$(ABSTOP)//)
# Find the build directory corresponding to the current source dir.
.if "$(MYDIR)" == ""
# avoid stray slash
MYBUILDDIR=$(BUILDTOP)
.else
MYBUILDDIR=$(BUILDTOP)/$(MYDIR)
.endif
############################################################
# Ensure we compile a consistent tree.
#
# Traditionally in Unix the first step of recompiling the system is to
# install new header files. Furthermore, the second step is to compile
# and install new libraries, before continuing on to the rest of the
# OS, which can then be compiled with those new headers and new
# libraries.
#
# Combining the compile and install phases like this is simpler and
# uses less disk space on extra copies of things (which mattered, back
# in the day) but has a number of problems. Chief among these is that
# if the build bombs out halfway through you end up with a partly
# updated and maybe broken system. It also means that once you start
# recompiling the system you can't easily back out. And the behavior
# violates the principle of least surprise.
#
# OS/161 1.x had, intentionally, a very traditional build environment.
# In OS/161 2.x, however, we use a staging area to avoid mixing build
# and install. This means that we must compile only against the
# staging area, $(INSTALLTOP), and never use the headers or libraries
# installed in $(OSTREE) until install time.
#
# This means that regardless of whether we have a gcc configured so it
# includes from our $(OSTREE) by default or not, we must use -nostdinc
# and -nostdlib and explicitly link with materials from $(INSTALLTOP).
#
# Use MORECFLAGS and MORELIBS, which are supported by os161.compile.mk
# for this purpose, so the include paths and library list come out in
# the right order.
#
CFLAGS+=-nostdinc
MORECFLAGS+=-I$(INSTALLTOP)/include
LDFLAGS+=-nostdlib -L$(INSTALLTOP)/lib $(INSTALLTOP)/lib/crt0.o
MORELIBS+=-lc
LIBDEPS+=$(INSTALLTOP)/lib/crt0.o $(INSTALLTOP)/lib/libc.a
############################################################
# end.

75
mk/os161.hostcompile.mk Normal file
View File

@@ -0,0 +1,75 @@
#
# OS/161 build environment: compile source files for the host system.
#
# Usage: use os161.hostprog.mk or os161.hostlib.mk
#
# Variables controlling this file:
#
# SRCS .c and .S files to compile.
#
# Provides:
#
# HOST_OBJS .ho files from compilation.
#
# Objects list starts empty. It is added to below.
HOST_OBJS=
# .ho is a host object.
.SUFFIXES: .ho
clean-local: cleanhostcompile
cleanhostcompile:
rm -f $(MYBUILDDIR)/*.ho $(MYBUILDDIR)/*.ha
distclean-local: distcleanhostcompile
distcleanhostcompile:
rm -f $(MYBUILDDIR)/.hostdepend
#
# Depend: generate dependency information.
# Use gcc's -MM argument for this.
#
# Note that we use -MM rather than -M, so we don't get system headers.
# They would be host system headers and we don't want to get involved
# with those.
#
# The fixdepends script transforms the results by substituting some
# make variables back into them; this way the depend files are
# independent of (at least some of) the build configuration. It also
# changes .o files to .ho files so the host and native builds are
# independent, and allows for placing the .ho files in the build
# directory.
#
depend-local: $(MYBUILDDIR) .WAIT predepend .WAIT dependhostcompile
dependhostcompile:
$(HOST_CC) $(HOST_CFLAGS) -DHOST -MM $(SRCS) |\
$(TOP)/mk/fixdepends.sh '$(INSTALLTOP)' host \
> $(MYBUILDDIR)/.hostdeptmp
mv -f $(MYBUILDDIR)/.hostdeptmp $(MYBUILDDIR)/.hostdepend
.-include "$(MYBUILDDIR)/.hostdepend"
predepend:
.PHONY: predepend
# No tags for host programs.
tags: tagshostcompile
tagshostcompile: ;
#
# Compile rules.
# We can use the same rules for .c and .S because gcc knows how to handle
# .S files.
#
.for _S_ in $(SRCS:M*.[cS])
HOST_OBJS+=$(MYBUILDDIR)/$(_S_:T:R).ho
$(MYBUILDDIR)/$(_S_:T:R).ho: $(_S_)
$(HOST_CC) $(HOST_CFLAGS) -DHOST -c $(_S_) -o $(.TARGET)
.endfor
# Make non-file rules PHONY.
.PHONY: clean-local cleanhostcompile distclean-local distcleanhostcompile
.PHONY: depend-local dependhostcompile tags tagshostcompile
# End.

78
mk/os161.hostlib.mk Normal file
View File

@@ -0,0 +1,78 @@
#
# OS/161 build environment: build a library for the compile host
#
# Usage:
# TOP=../..
# .include "$(TOP)/mk/os161.config.mk"
# [defs go here]
# .include "$(TOP)/mk/os161.hostlib.mk"
# [any extra rules go here]
#
# Variables controlling this file:
#
# LIB Name of library. We create lib$(LIB).a.
# SRCS .c and .S files to compile.
#
# HOST_CFLAGS Compile flags.
#
# Note that individual program makefiles should only *append* to
# HOST_CFLAGS, not assign it. Otherwise stuff set by os161.config.mk
# will get lost and bad things will happen.
#
# Because we only build static libs, we can't use and don't need
# LDFLAGS or LIBS. (Shared libs would want these.)
#
# Note that there's no HOSTLIBDIR; host libs are always put in
# $(TOOLDIR)/hostlib and do not end up in $(OSTREE).
#
_LIB_=lib$(LIB).a
# We may want these directories created. (Used by os161.baserules.mk.)
MKDIRS+=$(MYBUILDDIR)
MKDIRS+=$(TOOLDIR)/hostlib
# Default rule: create the program.
# (In make the first rule found is the default.)
all: all-local
all-local: $(MYBUILDDIR) .WAIT $(MYBUILDDIR)/$(_LIB_)
# Now get rules to compile the SRCS.
.include "$(TOP)/mk/os161.hostcompile.mk"
# Further rules for libraries.
#
# Install: we can install into either $(INSTALLTOP) or $(OSTREE).
# When building the whole system, we always install into the staging
# area. We provide the same direct install that os161.prog.mk
# provides; however, because it this doesn't relink anything using the
# library it generally isn't a very useful thing to do. Hence the
# warning.
#
# Note that we make a hard link instead of a copy by default to reduce
# overhead.
#
install-staging-local: $(TOOLDIR)/hostlib .WAIT $(TOOLDIR)/hostlib/$(_LIB_)
$(TOOLDIR)/hostlib/$(_LIB_): $(MYBUILDDIR)/$(_LIB_)
rm -f $(.TARGET)
ln $(MYBUILDDIR)/$(_LIB_) $(.TARGET) || \
cp $(MYBUILDDIR)/$(_LIB_) $(.TARGET)
install-local:
@echo "Nothing to manually install"
# Build the library.
$(MYBUILDDIR)/$(_LIB_): $(HOST_OBJS)
rm -f $(.TARGET)
$(HOST_AR) -cq $(.TARGET) $(HOST_OBJS)
$(HOST_RANLIB) $(.TARGET)
# Mark targets that don't represent files PHONY, to prevent various
# lossage if files by those names appear.
.PHONY: all all-local install-staging-local install-local
# Finally, get the shared definitions for the most basic rules.
.include "$(TOP)/mk/os161.baserules.mk"
# End.

109
mk/os161.hostprog.mk Normal file
View File

@@ -0,0 +1,109 @@
#
# OS/161 build environment: build a host-system program
#
# Usage:
# TOP=../..
# .include "$(TOP)/mk/os161.config.mk"
# [defs go here]
# .include "$(TOP)/mk/os161.hostprog.mk"
# [any extra rules go here]
#
# Variables controlling this file:
#
# PROG Name of program to generate.
# SRCS .c and .S files to compile.
#
# HOST_CFLAGS Compile flags.
# HOST_LDFLAGS Link flags.
# HOST_LIBS Libraries to link with.
#
# HOSTBINDIR Directory under $(OSTREE) to install into,
# e.g. /hostbin. Should have a leading slash.
# If not set, the program goes in
# $(TOOLDIR)/hostbin instead.
#
# Note that individual program makefiles should only *append* to
# HOST_CFLAGS, HOST_LDFLAGS, and HOST_LIBS, not assign them. Otherwise
# stuff set by os161.config.mk will get lost and bad things will
# happen.
#
# This is set up so it can be used together with os161.prog.mk if
# necessary.
#
# Real name
_PROG_=host-$(PROG)
# Directory to install into
.if defined(HOSTBINDIR)
_INSTALLDIR_=$(INSTALLTOP)$(HOSTBINDIR)
.else
_INSTALLDIR_=$(TOOLDIR)/hostbin
.endif
# We may want these directories created. (Used by os161.baserules.mk.)
MKDIRS+=$(MYBUILDDIR)
MKDIRS+=$(_INSTALLDIR_)
.if defined(HOSTBINDIR)
MKDIRS+=$(OSTREE)$(HOSTBINDIR)
.endif
# Default rule: create the program.
# (In make the first rule found is the default.)
all: all-local
all-local: $(MYBUILDDIR) .WAIT $(MYBUILDDIR)/$(_PROG_)
# Now get rules to compile the SRCS.
.include "$(TOP)/mk/os161.hostcompile.mk"
# Further rules for programs.
# Clean: delete extraneous files.
clean-local: cleanhostprog
cleanhostprog:
rm -f $(MYBUILDDIR)/$(_PROG_)
#
# Install: we can install into either $(INSTALLTOP) or $(OSTREE).
# When building the whole system, we always install into the staging
# area. However, if you're working on a particular program it is
# usually convenient to be able to install it directly to $(OSTREE)
# instead of doing a complete top-level install.
#
# Note that we make a hard link instead of a copy by default to reduce
# overhead.
#
install-staging-local: $(_INSTALLDIR_) .WAIT $(_INSTALLDIR_)/$(_PROG_)
$(_INSTALLDIR_)/$(_PROG_): $(MYBUILDDIR)/$(_PROG_)
rm -f $(.TARGET)
ln $(MYBUILDDIR)/$(_PROG_) $(.TARGET) || \
cp $(MYBUILDDIR)/$(_PROG_) $(.TARGET)
.if defined(HOSTBINDIR)
install-local: install-hostprog
install-hostprog: $(OSTREE)$(HOSTBINDIR) $(MYBUILDDIR)/$(_PROG_)
rm -f $(OSTREE)$(HOSTBINDIR)/$(_PROG_)
ln $(MYBUILDDIR)/$(_PROG_) $(OSTREE)$(HOSTBINDIR)/$(_PROG_) || \
cp $(MYBUILDDIR)/$(_PROG_) $(OSTREE)$(HOSTBINDIR)/$(_PROG_)
.else
install-local:
@echo "Nothing to manually install"
.endif
# Always implicitly include the compat library.
_COMPATLIB_=$(TOOLDIR)/hostlib/libhostcompat.a
# Link the program.
$(MYBUILDDIR)/$(_PROG_): $(HOST_OBJS) $(_COMPATLIB_)
$(HOST_LDCC) $(HOST_LDFLAGS) $(HOST_OBJS) $(HOST_LIBS) $(_COMPATLIB_) \
-o $(.TARGET)
# Mark targets that don't represent files PHONY, to prevent various
# lossage if files by those names appear.
.PHONY: all all-local clean-local cleanhostprog install-staging-local
.PHONY: install-local install-hostprog
# Finally, get the shared definitions for the most basic rules.
.include "$(TOP)/mk/os161.baserules.mk"
# End.

56
mk/os161.includes.mk Normal file
View File

@@ -0,0 +1,56 @@
#
# OS/161 build environment: include file installation.
#
# Set INCLUDES to a list of pairs:
#
# source-dir destination-dir
#
# where the destination dir should begin with include/.
# All header files in each dir are copied.
#
# Optionally set INCLUDELINKS to a list of pairs
#
# target linkname
#
# This will create symlinks target <- linkname. linkname
# should begin with include/. target usually won't.
#
#
# If you forcibly make install, header files are copied to $(OSTREE).
#
all depend install-staging clean distclean tags: ;
all-local depend-local install-staging-local clean-local distclean-local: ;
.for _SRC_ _DEST_ in $(INCLUDES)
MKDIRS+=$(INSTALLTOP)/$(_DEST_)
includes: $(INSTALLTOP)/$(_DEST_) .WAIT
MKDIRS+=$(OSTREE)/$(_DEST_)
install: $(OSTREE)/$(_DEST_) .WAIT
.endfor
includes: includes-local
includes-local:
.for _SRC_ _DEST_ in $(INCLUDES)
$(TOP)/mk/installheaders.sh $(_SRC_) $(INSTALLTOP)/$(_DEST_)
.endfor
.for _TGT_ _LINK_ in $(INCLUDELINKS)
[ -h $(INSTALLTOP)/$(_LINK_) ] || \
ln -sf $(_TGT_) $(INSTALLTOP)/$(_LINK_)
.endfor
install-local:
.for _SRC_ _DEST_ in $(INCLUDES)
$(TOP)/mk/installheaders.sh $(_SRC_) $(OSTREE)/$(_DEST_)
.endfor
.for _TGT_ _LINK_ in $(INCLUDELINKS)
[ -h $(INSTALLTOP)/$(_LINK_) ] || \
ln -sf $(_TGT_) $(INSTALLTOP)/$(_LINK_)
.endfor
.PHONY: all depend install-staging clean distclean tags
.PHONY: includes includes-local install-local
.include "$(TOP)/mk/os161.baserules.mk"

217
mk/os161.kernel.mk Normal file
View File

@@ -0,0 +1,217 @@
#
# OS/161 build environment: build a kernel
#
# Note that kernels build in kernel build directories and not into
# $(BUILDDIR).
#
#
# The makefile stub generated by the kernel config script looks like this:
# KTOP=../.. # top of the kernel tree
# TOP=$(KTOP)/.. # top of the whole tree
# KDEBUG=-g # debug vs. optimize
# CONFNAME=GENERIC # name of the kernel config file
# .include "$(TOP)/mk/os161.config.mk"
# .include "files.mk"
# .include "$(TOP)/mk/os161.kernel.mk"
#
# files.mk is also generated by the kernel config script.
#
#
# Additional defs for building a kernel.
#
# All sources.
ALLSRCS=$(SRCS) $(SRCS.MACHINE.$(MACHINE)) $(SRCS.PLATFORM.$(PLATFORM))
# Filename for the kernel.
KERNEL=kernel
# Don't use headers and libraries that don't belong to the kernel.
# Kernels have to be standalone.
KCFLAGS+=-nostdinc
KLDFLAGS+=-nostdlib
# Do use the kernel's header files.
KCFLAGS+=-I$(KTOP)/include -I$(KTOP)/dev -I. -Iincludelinks
# Tell gcc that we're building something other than an ordinary
# application, so it makes fewer assumptions about standard library
# functions.
KCFLAGS+=-ffreestanding
# Define _KERNEL so code in src/common can tell which header files
# it should use.
KCFLAGS+=-D_KERNEL
# Provide the linker with a "linker script". This is a piece of
# obscure mumble that tells the linker how to put together the output
# program. We need it because a kernel needs (in general) to be linked
# to run at a different virtual address from an ordinary program.
#
# Traditionally all you need to do is pass -Ttext to set the address
# for the text (code), but this doesn't work with the GNU linker by
# default because of a silly design bug.
#
# Look for a linker script for the PLATFORM first, and if not that try
# MACHINE, and if neither of those exists assume we don't actually
# need one.
.if exists($(KTOP)/arch/$(PLATFORM)/conf/ldscript)
KLDFLAGS+=-T $(KTOP)/arch/$(PLATFORM)/conf/ldscript
.elif exists($(KTOP)/arch/$(MACHINE)/conf/ldscript)
KLDFLAGS+=-T $(KTOP)/arch/$(MACHINE)/conf/ldscript
.endif
#
# This should expand to all the header files in the kernel so they can
# be fed to tags.
#
TAGS_HEADERS=\
$(KTOP)/*/*.h \
$(KTOP)/include/kern/*.h \
$(KTOP)/dev/*/*.h \
$(KTOP)/arch/$(MACHINE)/*/*.h \
$(KTOP)/arch/$(MACHINE)/include/kern/*.h \
$(KTOP)/arch/$(PLATFORM)/*/*.h
#
# Rules.
#
# Default rule: link the kernel.
all: includelinks .WAIT $(KERNEL)
#
# Here's how we link the kernel.
#
# vers.c/.o is generated on every build. It contains a numeric serial
# number incremented every time newvers.sh is run. These values are
# printed out by newvers.sh and are also displayed at boot time. This
# makes it possible to tell at a glance whether you're actually
# running the same kernel you just compiled.
#
# The version number is kept in the file called "version" in the build
# directory.
#
# By immemorial tradition, "size" is run on the kernel after it's linked.
#
$(KERNEL):
$(KTOP)/conf/newvers.sh $(CONFNAME)
$(CC) $(KCFLAGS) -c vers.c
$(LD) $(KLDFLAGS) $(OBJS) vers.o -o $(KERNEL)
@echo '*** This is $(CONFNAME) build #'`cat version`' ***'
$(SIZE) $(KERNEL)
#
# Use the -M argument to gcc to get it to output dependency information.
# Note that we use -M, which includes deps for #include <...> files,
# rather than -MM, which doesn't. This is because we are the operating
# system: the #include <...> files are part of our project -- in fact, in
# the kernel they're the kernel's own include files -- and they will be
# changing!
#
# Each source file's depend info gets dumped into its own .depend file
# so the overall depend process parallelizes. Otherwise (assuming you
# have a reasonably modern machine) this is the slowest part of the
# kernel build.
#
depend:
$(MAKE) includelinks
rm -f .depend.* || true
$(MAKE) realdepend
.for _S_ in $(ALLSRCS)
DEPFILES+=.depend.$(_S_:T)
.depend.$(_S_:T):
$(CC) $(KCFLAGS) -M $(_S_) > .depend.$(_S_:T)
.endfor
realdepend: $(DEPFILES)
cat $(DEPFILES) > .depend
# our make does this implicitly
#.-include ".depend"
#
# This allows includes of the forms
# <machine/foo.h>
# <kern/machine/foo.h>
# <platform/foo.h>
# and also (for this platform/machine)
# <mips/foo.h>
# <kern/mips/foo.h>
# <sys161/foo.h>
# to go to the right place.
#
includelinks:
mkdir includelinks
mkdir includelinks/kern
ln -s ../../../arch/$(MACHINE)/include includelinks/$(MACHINE)
ln -s ../../../../arch/$(MACHINE)/include/kern \
includelinks/kern/$(MACHINE)
ln -s ../../../arch/$(PLATFORM)/include includelinks/$(PLATFORM)
ln -s $(MACHINE) includelinks/machine
ln -s $(MACHINE) includelinks/kern/machine
ln -s $(PLATFORM) includelinks/platform
#
# Remove everything generated during the compile.
# (To remove absolutely everything automatically generated, you can just
# blow away the whole compile directory.)
#
clean:
rm -f *.o *.a tags $(KERNEL)
rm -rf includelinks
distclean cleandir: clean
rm -f .depend
#
# Rerun config for this configuration.
#
reconfig:
(cd $(KTOP)/conf && ./config $(CONFNAME))
#
# [ -d $(OSTREE) ] succeeds if $(OSTREE) is a directory.
# (See test(1).) Thus, if $(OSTREE) doesn't exist, it will be created.
#
# The kernel gets installed at the top of the installed system tree.
# Since with OS/161 it's relatively likely that you'll be working with
# several configurations at once, it gets installed under the name of
# this config, and a symbolic link with the "real" name is set up to
# point to the last kernel installed.
#
install:
[ -d $(OSTREE) ] || mkdir $(OSTREE)
cp $(KERNEL) $(OSTREE)/$(KERNEL)-$(CONFNAME)
-rm -f $(OSTREE)/$(KERNEL)
ln -s $(KERNEL)-$(CONFNAME) $(OSTREE)/$(KERNEL)
#
# Run tags on all the sources and header files. This is probably not
# the most useful way to do this and may need attention. (XXX?)
#
tags:
ctags -wtd $(ALLSRCS) $(TAGS_HEADERS)
#
# This tells make that these rules are not files so it (hopefully)
# won't become confused if files by those names appear.
#
.PHONY: all depend realdepend clean reconfig install tags
#
# Compilation rules.
#
.for _S_ in $(ALLSRCS)
OBJS+=$(_S_:T:R).o
$(_S_:T:R).o: $(_S_)
$(CC) $(KCFLAGS) -c $(_S_)
.endfor
# Make the kernel depend on all the object files.
$(KERNEL): $(OBJS)
# End.

84
mk/os161.lib.mk Normal file
View File

@@ -0,0 +1,84 @@
#
# OS/161 build environment: build a library
#
# Usage:
# TOP=../..
# .include "$(TOP)/mk/os161.config.mk"
# [defs go here]
# .include "$(TOP)/mk/os161.lib.mk"
# [any extra rules go here]
#
# Variables controlling this file:
#
# LIB Name of library. We create lib$(LIB).a.
# SRCS .c and .S files to compile.
#
# CFLAGS Compile flags.
#
# LIBDIR Directory under $(OSTREE) to install into,
# e.g. /lib. Should have a leading slash.
#
# Note that individual program makefiles should only *append* to
# CFLAGS, not assign it. Otherwise stuff set by os161.config.mk will
# get lost and bad things will happen.
#
# Because we only build static libs, we can't use and don't need
# LDFLAGS, LIBS, or LIBDEPS. (Shared libs would want these.)
#
LIBDIR?=/lib
_LIB_=lib$(LIB).a
# We may want these directories created. (Used by os161.baserules.mk.)
MKDIRS+=$(MYBUILDDIR)
MKDIRS+=$(INSTALLTOP)$(LIBDIR)
MKDIRS+=$(OSTREE)$(LIBDIR)
# Default rule: create the program.
# (In make the first rule found is the default.)
all: all-local
all-local: $(MYBUILDDIR) .WAIT $(MYBUILDDIR)/$(_LIB_)
# Now get rules to compile the SRCS.
.include "$(TOP)/mk/os161.compile.mk"
# Further rules for libraries.
#
# Install: we can install into either $(INSTALLTOP) or $(OSTREE).
# When building the whole system, we always install into the staging
# area. We provide the same direct install that os161.prog.mk
# provides; however, because it this doesn't relink anything using the
# library it generally isn't a very useful thing to do. Hence the
# warning.
#
# Note that we make a hard link instead of a copy by default to reduce
# overhead.
#
install-staging-local: $(INSTALLTOP)$(LIBDIR) .WAIT $(INSTALLTOP)$(LIBDIR)/$(_LIB_)
$(INSTALLTOP)$(LIBDIR)/$(_LIB_): $(MYBUILDDIR)/$(_LIB_)
rm -f $(.TARGET)
ln $(MYBUILDDIR)/$(_LIB_) $(.TARGET) || \
cp $(MYBUILDDIR)/$(_LIB_) $(.TARGET)
install-local: $(OSTREE)$(LIBDIR) $(MYBUILDDIR)/$(_LIB_)
@echo "Warning: manually installing library without relinking anything"
rm -f $(OSTREE)$(LIBDIR)/$(_LIB_)
ln $(MYBUILDDIR)/$(_LIB_) $(OSTREE)$(LIBDIR)/$(_LIB_) || \
cp $(MYBUILDDIR)/$(_LIB_) $(OSTREE)$(LIBDIR)/$(_LIB_)
# Build the library.
$(MYBUILDDIR)/$(_LIB_): $(OBJS)
rm -f $(.TARGET)
$(AR) -cq $(.TARGET) $(OBJS)
$(RANLIB) $(.TARGET)
# Mark targets that don't represent files PHONY, to prevent various
# lossage if files by those names appear.
.PHONY: all all-local install-staging-local install-local
# Finally, get the shared definitions for the most basic rules.
.include "$(TOP)/mk/os161.baserules.mk"
# End.

66
mk/os161.man.mk Normal file
View File

@@ -0,0 +1,66 @@
#
# OS/161 build environment: install man pages
#
# Usage:
# TOP=../..
# .include "$(TOP)/mk/os161.config.mk"
# [defs go here]
# .include "$(TOP)/mk/os161.man.mk"
# [any extra rules go here]
#
# Variables controlling this file:
#
# MANFILES Files to install.
#
# MANDIR Directory under $(OSTREE) to install into,
# e.g. /man/bin. Should have a leading slash.
#
# We may want these directories created. (Used by os161.baserules.mk.)
# We don't use the build directory because we don't currently generate
# anything for man pages.
#MKDIRS+=$(MYBUILDDIR)
MKDIRS+=$(INSTALLTOP)$(MANDIR)
MKDIRS+=$(OSTREE)$(MANDIR)
# Default rule: do nothing.
# (In make the first rule found is the default.)
all: all-local
all-local: ;
#
# Install: we can install into either $(INSTALLTOP) or $(OSTREE).
# When building the whole system, we always install into the staging
# area. However, if you're working on a particular program it is
# usually convenient to be able to install it directly to $(OSTREE)
# instead of doing a complete top-level install.
#
# Note that we make a hard link instead of a copy by default to reduce
# overhead.
#
install-staging-local: $(INSTALLTOP)$(MANDIR) .WAIT
.for _F_ in $(MANFILES)
install-staging-local: $(INSTALLTOP)$(MANDIR)/$(_F_)
$(INSTALLTOP)$(MANDIR)/$(_F_): $(_F_)
rm -f $(.TARGET)
ln $(_F_) $(.TARGET) || cp $(_F_) $(.TARGET)
.endfor
install-local: $(OSTREE)$(MANDIR) .WAIT installmanpages
installmanpages:
.for _F_ in $(MANFILES)
rm -f $(OSTREE)$(MANDIR)/$(_F_)
ln $(_F_) $(OSTREE)$(MANDIR)/$(_F_) || \
cp $(_F_) $(OSTREE)$(MANDIR)/$(_F_)
.endfor
# Mark targets that don't represent files PHONY, to prevent various
# lossage if files by those names appear.
.PHONY: all all-local install-staging-local install-local installmanpages
# Finally, get the shared definitions for the most basic rules.
.include "$(TOP)/mk/os161.baserules.mk"
# End.

59
mk/os161.mkdirs.mk Normal file
View File

@@ -0,0 +1,59 @@
#
# MKDIRS logic
#
# This generates rules for all intermediate directories as well as
# the directories listed. (That is, if you say MKDIRS=/usr/bin/foo
# you get rules for /usr and /usr/bin as well as /usr/bin/foo.)
#
# Variable for complete list of dirs. Start empty.
_MKDIRS_=
# For each dir in the list...
.for _DIR_ in $(MKDIRS)
#
# Initialize some temporaries.
# _HEAD_ contains / if the path was absolute.
# _INCR_DIR_ accumulates the full directory name incrementally.
#
# Use := to force full evaluation of the RHS of each expression while
# still in the loop, instead of when the variables are used later.
#
_HEAD_:=$(_DIR_:M/*:C/..*/\//)
_INCR_DIR_:=
# For each component in the directory, split on slashes...
.for _COMPONENT_ in $(_DIR_:S/\// /g)
# Add the component to _INCR_DIR_.
_INCR_DIR_:=$(_INCR_DIR_)$(_COMPONENT_)/
# Add the current partial directory to the main list.
# Lose the trailing slash.
_MKDIRS_:=$(_MKDIRS_) $(_HEAD_)$(_INCR_DIR_:S/\/$//)
.endfor # _COMPONENT_
.endfor # _DIR_
#
# Now issue a rule for each directory in the expanded list,
# ordering and uniquifying it.
#
# XXX use /dev/null to suppress curious messages like "../../.. is up
# to date". This scheme probably ought to be reworked.
#
.for _DIR_ in $(_MKDIRS_:O:u)
.if !target($(_DIR_))
$(_DIR_):
.for _PRE_ in $(_DIR_:M*/*:H:N..)
@$(MAKE) $(_PRE_) >/dev/null 2>&1 || true
.endfor
mkdir $(_DIR_) || true
.endif
.endfor
# Clear MKDIRS in case we're included again.
MKDIRS=
# End.

85
mk/os161.prog.mk Normal file
View File

@@ -0,0 +1,85 @@
#
# OS/161 build environment: build a program
#
# Usage:
# TOP=../..
# .include "$(TOP)/mk/os161.config.mk"
# [defs go here]
# .include "$(TOP)/mk/os161.prog.mk"
# [any extra rules go here]
#
# Variables controlling this file:
#
# PROG Name of program to generate.
# SRCS .c and .S files to compile.
#
# CFLAGS Compile flags.
# LDFLAGS Link flags.
# LIBS Libraries to link with.
# LIBDEPS Full paths of LIBS for depending on.
#
# BINDIR Directory under $(OSTREE) to install into,
# e.g. /bin. Should have a leading slash.
#
# Note that individual program makefiles should only *append* to
# CFLAGS, LDFLAGS, LIBS, and LIBDEPS, not assign them. Otherwise stuff
# set by os161.config.mk will get lost and bad things will happen.
#
BINDIR?=/bin
# We may want these directories created. (Used by os161.baserules.mk.)
MKDIRS+=$(MYBUILDDIR)
MKDIRS+=$(INSTALLTOP)$(BINDIR)
MKDIRS+=$(OSTREE)$(BINDIR)
# Default rule: create the program.
# (In make the first rule found is the default.)
all: all-local
all-local: $(MYBUILDDIR) .WAIT $(MYBUILDDIR)/$(PROG)
# Now get rules to compile the SRCS.
.include "$(TOP)/mk/os161.compile.mk"
# Further rules for programs.
# Clean: delete extraneous files.
clean-local: cleanprog
cleanprog:
rm -f $(MYBUILDDIR)/$(PROG)
#
# Install: we can install into either $(INSTALLTOP) or $(OSTREE).
# When building the whole system, we always install into the staging
# area. However, if you're working on a particular program it is
# usually convenient to be able to install it directly to $(OSTREE)
# instead of doing a complete top-level install.
#
# Note that we make a hard link instead of a copy by default to reduce
# overhead.
#
install-staging-local: $(INSTALLTOP)$(BINDIR) .WAIT $(INSTALLTOP)$(BINDIR)/$(PROG)
$(INSTALLTOP)$(BINDIR)/$(PROG): $(MYBUILDDIR)/$(PROG)
rm -f $(.TARGET)
ln $(MYBUILDDIR)/$(PROG) $(.TARGET) || \
cp $(MYBUILDDIR)/$(PROG) $(.TARGET)
install-local: install-prog
install-prog: $(OSTREE)$(BINDIR) $(MYBUILDDIR)/$(PROG)
rm -f $(OSTREE)$(BINDIR)/$(PROG)
ln $(MYBUILDDIR)/$(PROG) $(OSTREE)$(BINDIR)/$(PROG) || \
cp $(MYBUILDDIR)/$(PROG) $(OSTREE)$(BINDIR)/$(PROG)
# Link the program.
$(MYBUILDDIR)/$(PROG): $(OBJS) $(LIBDEPS)
$(LDCC) $(LDFLAGS) $(OBJS) $(LIBS) $(MORELIBS) -o $(.TARGET)
# Mark targets that don't represent files PHONY, to prevent various
# lossage if files by those names appear.
.PHONY: all all-local clean cleanprog install-staging-local
.PHONY: install-local install-prog
# Finally, get the shared definitions for the most basic rules.
.include "$(TOP)/mk/os161.baserules.mk"
# End.

51
mk/os161.subdir.mk Normal file
View File

@@ -0,0 +1,51 @@
#
# OS/161 build environment: recurse into subdirectories
#
# Usage:
# TOP=../..
# .include "$(TOP)/mk/os161.config.mk"
# [defs go here]
# .include "$(TOP)/mk/os161.subdir.mk"
# [any extra rules go here]
#
# Variables controlling this file:
#
# SUBDIRS Directories to recurse into.
# EXTRATARGETS Additional targets to define.
#
# BASETARGETS may also be set to empty to suppress the usual targets.
#
# Note: SUBDIRS may contain .WAIT, which is treated as a parallelism
# barrier like in the right hand side of a make rule.
#
# Further note: if combining os161.subdir.mk with other os161.*.mk
# files (other than os161.config.mk), include os161.subdir.mk first;
# then the ordering of things will cause recursion to happen
# first. Also, .WAIT is inserted so that the recursion will finish
# before anything else happens, which is almost always desirable.
#
BASETARGETS?=\
all depend install install-staging clean distclean tags \
cleandir stage dependall build rebuild fullrebuild
# first, make each target depend on its -subdirs target,
# and declare both PHONY.
.for _T_ in $(BASETARGETS) $(EXTRATARGETS)
$(_T_): $(_T_)-subdirs .WAIT
.PHONY: $(_T_) $(_T_)-subdirs
.endfor
# now, make each -subdirs target depend on a rule for each subdir.
.for _D_ in $(SUBDIRS)
.for _T_ in $(BASETARGETS) $(EXTRATARGETS)
.if "$(_D_)" == ".WAIT"
$(_T_)-subdirs: .WAIT
.else
$(_T_)-subdirs: $(_T_)-subdirs-$(_D_)
.PHONY: $(_T_)-subdirs-$(_D_)
$(_T_)-subdirs-$(_D_):
(cd $(_D_) && $(MAKE) $(_T_))
.endif
.endfor
.endfor