# /usr/src/sys/Makefile V2.2 For FreeBSD 2.2.-current ${DEFAULT_CONFIG} # Low: Makefile internally does CONFIG=`hostname` # EXTERNAL ENVIRONMENT VARIABLES: # MACHINE Mandatory, Must be preset, example: i386. # DESTDIR Optional If preset in the environment,it is recognised. # CONFIG Optional Usage as shown above. # MAINTENANCE NOTES: See end of file. # Be Careful ! It's very easy to break these Makefile, If you Must # change things - Don't commit changes back to master sources until # you have checked for all cases: compile/ under src & obj, src on CD, # src/ on remote NFS etc. # ============================================================================= SUBDIR = ${MACHINE}/boot # .if exists(${MACHINE}/doc) && exists(${MACHINE}/doc/Makefile) #{ # SUBDIR += ${MACHINE}/doc # so people can document architectures # .endif #} .PATH= # No directories searched for files not found in current dir. #CONFIG_D=compile/config_name OBJJ!=pwd OBJJJ=/usr/obj/${OBJJ} CONFIG_D=${OBJJJ}//config_name DEFAULT_CONFIG= ${CONFIG_D}/name # May contain default config name. THIS_CONFIG= ${CONFIG_D}/now # What to make now. LAST_CONFIG= ${CONFIG_D}/last # What M_SUB was last produced for. FORCE_MAKEFILE= ${CONFIG_D}/force # If new M_SUB to be forcibly built. F_SUB=Makefile_sub M_SUB=${CONFIG_D}/${F_SUB} C_SUB=${F_SUB}.c #Do not change C_SUB name without also changing Makefile_sub.c. TREE_TEST= Makefile # used as: compile/CONFIG_NAME/$TREE_TEST, # ( typically compile/GENERIC/Makefile ) # compared with config file date. swap386bsd.c is newer, but doubt if # swap${MACHINE}.c would be an architecture independent portable name, # (Gary Palmer on the ARM port may know this) # Convert hostnames such as freebsd.org & # vector.eikon.e-technik.tu-muenchen.de to VECTOR & FREEFALL. # Each sed removes one level of sub domain, 4 seds is enough for most, so use 6. # tr converts to upper case to match most people''s habit. HOSTNAME !=hostname | \ sed "s/\.[a-zA-Z0-9]*//" | sed "s/\.[a-zA-Z0-9]*//" | \ sed "s/\.[a-zA-Z0-9]*//" | sed "s/\.[a-zA-Z0-9]*//" | \ sed "s/\.[a-zA-Z0-9]*//" | sed "s/\.[a-zA-Z0-9]*//" | \ tr a-z A-Z CONFIG:= ${HOSTNAME} # Can be overridden by bsd_make CONFIG=whatever CLEANFILES += ${LAST_CONFIG} ${THIS_CONFIG} ${FORCE_MAKEFILE} ${M_SUB} # Transient temporary files, created by config_makefile. # uses CLEANFILES for same purpose, & says: # Additional files to remove for the clean and cleandir targets. .if defined(DEBUG_SYS_MAKEFILE) #{ DBG!= echo "+ " E_DBG= echo SHOW= @echo "${DBG} .TARGET=${.TARGET} .CURDIR=${.CURDIR} pwd=`pwd`" .else #}{ # Do nothing. E_DBG= true SHOW= true .endif #} # ----------------------------------------------------------------------------- # EXTERNALLY CALLABLE LABELS all: _SUBDIRUSE config_tree compile_tree ${SHOW} make -f ${M_SUB} ${.TARGET} # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - DATE != date +%y%m%d_%H%M install: _SUBDIRUSE config_tree ${SHOW} make DATE=${DATE} -f ${M_SUB} ${.TARGET} @${E_DBG} ${DBG} ${INSTALLFLAGS} # INSTALLFLAGS is unset ${INSTALL} -m 444 -c ${.CURDIR}/${MACHINE}/conf/`cat ${THIS_CONFIG}` \ $(DESTDIR)/config.`cat ${THIS_CONFIG}`.${DATE} # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - clean: _SUBDIRUSE config_makefile ${SHOW} @# Clean current-flavour compile tree, but not other config names. make -f ${M_SUB} ${.TARGET} @${E_DBG} "${DBG} Removing makefile temporary files." -rm -f ${CLEANFILES} # Done after cd compile above JJ @# To do more extensive cleaning, use make cleandir. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cleandir: _SUBDIRUSE config_makefile ${SHOW} @# Prevent a first time make cleandir reporting @# cat: /usr/home/jhs/config_name/now: No such file or directory @# echo "DUMMY" > ${THIS_CONFIG} @# ${FORCE_MAKEFILE} make ${M_SUB} make -f ${M_SUB} ${.TARGET} @${E_DBG} "${DBG} Note we have not cleaned all compile sub directories," @${E_DBG} "${DBG} only compile/`cat ${THIS_CONFIG}`" -rm -f ${CLEANFILES} # deletes ${THIS_CONFIG} @${E_DBG} "${DBG} (as other compile trees may still be wanted)." # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # removed 960607 after jordans change to obj in mk macros # # as per bsd.prog.mk & bsd.kmod.mk, # obj: _SUBDIRUSE # .if !defined(NO_OBJ) # { # ${SHOW} # @cd ${.CURDIR}; rm -rf obj; \ # here=`pwd`; dest=/usr/obj`echo $$here | sed 's,^/usr/src,,'`; \ # echo "$$here -> $$dest"; ln -s $$dest obj; \ # if test -d /usr/obj -a ! -d $$dest; then \ # mkdir -p $$dest; \ # else \ # true; \ # fi; # .endif # } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - depend: _SUBDIRUSE config_tree ${SHOW} @echo "/sys depend is done automatically after config, from 'all:' calling Makefile_sub," make -f ${M_SUB} ${.TARGET} # ----------------------------------------------------------------------------- # INTERNAL LABELS (only designed for internal use within this Makefile) curdir_chk: ${SHOW} @echo "Checking PWD env. var. is /usr/src/sys (and not merely /sys)." @# The symbolic links involving /usr/obj/usr/src/sys will break if @# .CURDIR detects you got this far from: "cd /sys ; make", as opposed @# to "cd /usr/src/sys ; make". FreeBSD PWD env. variable is involved. @# If you have typed "cd /usr/src" and there is a sym link @# /usr/src --> /usr1/src, this will be OK, @# But if you typed "cd /sys" & relied on a symbolic link @# "/sys --> /usr/src/sys", it causes problems .if ${.CURDIR} != "/usr/src/sys" #{ @${E_DBG} "${DBG} .CURDIR should be /usr/src/sys, but is instead ${.CURDIR}" @echo "Type \"cd /usr/src/sys;\" then use \"make\" again." @echo " (If you do not uderstand why, try this:" @echo " make curdir_tst ; sleep 10 ; vi -c/curdir_chk: Makefile" abort .else #}{ @# echo OK, .CURDIR is /usr/src/sys. .endif #} # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - mk_compile_d: curdir_chk ${SHOW} #.if !exists(obj) # { this obj is tested for in the src tree # @echo "You Have No ./obj, You Might Want To Interrupt, Then Run:" # @echo " make cleandir ; make obj ; make all" # @echo " (Do not concatenate the last two to \"make obj all\"" # @echo " as \".if exist (obj)\" is only evaluted at make start up)." # @# obj symbolic links created by `make obj' are essential if # @# multiple hosts are sharing one nfs mounted common source tree. # @# sleep 20 # give user time to abort #.endif #} # @echo -n "Ensuring either ./obj/compile/ exists, or ./compile/," # @echo "(but not both)." #.if ! exists(obj) # { # @if ! test -d compile ; then \ # echo "No obj or compile exists, mkdir ${.CURDIR}/compile." ; \ # mkdir ${.CURDIR}/compile ; \ # fi #.else # }{ # @# We assume the user will break the make & manually run a `make obj', # @# if required, however this label `mk_compile_d' will be called # @# several times (at least twice from `make all install', thus # @# construct like # @# .if exists(compile) wont detect compile existing in later passes of # @# mk_compile_d (perhaps called by make install), if it only first comes # @# into existence as a product of `make all'. # @# # @# This test # @# @if test -d ${.CURDIR}/compile ; then # @# does not work, because it tests what it points at, not itself # @# one might be tempted to combine it with a test -h # @# but the result seems to be affected by whether the target exists # @# or not. # @# No point using any test that involves whether target # @# of src/sys/compile (ie dir. /usr/obj/usr1/src/sys/compile) exists, # @# /usr/obj/... are host dependent, & while this host may have no # @# obj/.../compile directory, another host may be already running make, # @# using src/sys/obj/compile symbolic link, thus we dare not remove # @# src/sys/obj/compile. # @# # @echo "Ensuring ${.CURDIR}/obj/compile/ exists" # ls -l ${.CURDIR}/obj ${.CURDIR}/obj/compile # if test -d ${.CURDIR}/obj/compile ; then \ # echo "Directory ${.CURDIR}/obj/compile exists." ; \ # else \ # mkdir ${.CURDIR}/obj/compile ; \ # fi; # @# # @echo "Ensuring symbolic link ${.CURDIR}/compile --> obj/compile." # ls -l ${.CURDIR}/compile # @if test -h ${.CURDIR}/compile ; then \ # echo "Sym link ${.CURDIR}/compile exists." ; \ # else \ # ln -s obj/compile ${.CURDIR}/compile ; \ # fi ; # @# # @echo "Visual check that compile is in the obj tree." # cd ${.CURDIR}/compile ; pwd # @# # @echo "Checking that compile is in the obj tree." # @# Makefile exit status check # cd ${.CURDIR}/compile ; pwd | grep -q obj # acting on grep return code # @echo "Check succeeds." # @# #.endif #} # @echo "Ensuring {CONFIG_D} exists." # @# for kernel flavour selection temporary files." # -mkdir -p ${CONFIG_D} # if test -d ${CONFIG_D} ; then \ # echo "Directory ${CONFIG_D}/ exists." ; \ # else \ # mkdir -p ${CONFIG_D} ; \ # fi # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - config_which: # Determine which config name kernel to compile. ${SHOW} @${E_DBG} "${DBG} Determining which kernel config name to make." @${E_DBG} "${DBG} Initial CONFIG variable (from hostname)=${CONFIG}" .if exists(${DEFAULT_CONFIG}) #{ @${E_DBG} "${DBG} ${DEFAULT_CONFIG} exists" @# Seeing if ${DEFAULT_CONFIG} has contents. @# " chars in next line are in case name in config file has a space @if [ -z "`grep -v ^# ${DEFAULT_CONFIG}`" ] ; \ then \ ${E_DBG} "${DBG} ${DEFAULT_CONFIG} is empty" ; \ echo "${CONFIG}" > ${THIS_CONFIG}; \ else \ ${E_DBG} "${DBG} ${DEFAULT_CONFIG} has contents" ; \ echo "`grep -v ^# ${DEFAULT_CONFIG}`" > ${THIS_CONFIG}; \ fi .else #}{ @${E_DBG} "${DBG} ${DEFAULT_CONFIG} does not exist." .if defined(CONFIG) ${E_DBG} "${DBG} CONFIG Makefile variable=${CONFIG}" @echo ${CONFIG} > ${THIS_CONFIG} .else #}{ ${E_DBG} "${DBG} CONFIG Makefile variable is unset" ${E_DBG} "${DBG} Assuming existence of ${MACHINE}/conf/${HOSTNAME}" echo ${HOSTNAME} > ${THIS_CONFIG} .endif #} .endif #} @${E_DBG} "${DBG} Config name to be worked on is `cat ${THIS_CONFIG}`." .if !exists(${LAST_CONFIG}) @# Creating a dummy ${LAST_CONFIG} as no previous make has left one. touch ${LAST_CONFIG} .endif #} # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - config_makefile: mk_compile_d config_which ${M_SUB} # Decide if Makefile_sub to be remade. ${SHOW} @${E_DBG} "${DBG} Determining if ${M_SUB} needs to be remade." .if !exists(${FORCE_MAKEFILE}) #{ touch ${FORCE_MAKEFILE} @# This touch only needs to be in the "then", not the "else", @# however getting it there causes problems with backslash delimeters. .endif #} @# " chars in next line are in case name in config file has a space @if [ "`cat ${LAST_CONFIG}`" = "`cat ${THIS_CONFIG}`" ] ; \ then \ ${E_DBG} "${DBG} Same configuration name as last time," ; \ ${E_DBG} "${DBG} no need to remake ${M_SUB}" ; \ else \ ${E_DBG} -n "${DBG} Configuration changed from " ; \ ${E_DBG} "${DBG} `cat ${LAST_CONFIG}` to `cat ${THIS_CONFIG}`." ; \ ${E_DBG} "${DBG} Forcing a new ${M_SUB}" ; \ touch ${FORCE_MAKEFILE}; \ echo "---{> _${M_SUB}_" ; \ make ${M_SUB} ; \ echo "<}--- _${M_SUB}_" ; \ fi # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - config_tree: config_makefile # Make a compile tree (of sources). ${SHOW} @# hope compile/${THIS_CONFIG} gets evalauted ok - JJ IT WONT .if !exists(compile/${THIS_CONFIG}) #{ mkdir -p compile/`cat ${THIS_CONFIG}` @# If obj exists when makefile starts, @# compile gets created within /usr/obj/usr/src/sys .else #}{ @${E_DBG} "${DBG} Already exists: compile/`cat ${THIS_CONFIG}`" .endif #} @${E_DBG} "${DBG} Determining if compile tree needs to be remade." @echo "---{> _${M_SUB}_" make -f ${M_SUB} compile/`cat ${THIS_CONFIG}`/${TREE_TEST} @echo "<}--- _${M_SUB}_" # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Create a file who's sole purpose is to be a timestamp, # if this file is newer than ${M_SUB}, then ${M_SUB} needs to be remade. ${FORCE_MAKEFILE}: ${SHOW} touch $@ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Make Makefile_sub. ${M_SUB}: Makefile ${C_SUB} ${FORCE_MAKEFILE} ${SHOW} cpp -P -DCONFIG_NAME=`cat ${THIS_CONFIG}` -Ui386 \ -DCONFIG_TREE_TEST=compile/`cat ${THIS_CONFIG}`/${TREE_TEST} \ -DC_SUB=${.CURDIR}/${C_SUB} \ -DCURDIR=${.CURDIR} \ ${.CURDIR}/${C_SUB} > ${M_SUB} @# -Ui386 avoids damage to names like .../i386/conf/... cp ${THIS_CONFIG} ${LAST_CONFIG} # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - compile_tree: # Compile a tree. ${SHOW} @${E_DBG} "${DBG} Making kernel compile tree for `cat ${THIS_CONFIG}`." @echo "---{> compile/`cat ${THIS_CONFIG}`" cd ./compile/`cat ${THIS_CONFIG}`; make @echo "<}--- compile/`cat ${THIS_CONFIG}`" # ============================================================================= # Debug code not necessary for compiling, but to help humans understand # what may be going wrong with .CURDIR, PWD, /usr/src/sys, & /sys. curdir_tst: @echo Test of .CURDIR ${.CURDIR} .if ${.CURDIR} == "/usr/src/sys" #{ @echo Yes .CURDIR is /usr/src/sys .else #}{ @echo No .CURDIR is not /usr/src/sys @echo "Please type \"cd /usr/src/sys\" and try make again." abort .endif #} .if ${.CURDIR} == "/sys" #{ @echo Yes .CURDIR is /sys .else #}{ @echo No .CURDIR is not /sys .endif #} # ----------------------------------------------------------------------------- .if defined(DEBUG_SYS_MAKEFILE) #{ # OBJECT TREE RESEARCH: DBG_CWD!= pwd obj_tst: ls -l obj @echo cwd is ${DBG_CWD} @echo pwd is `pwd` @echo .CURDIR is ${.CURDIR} # if obj exists such as # obj@ -> /usr/obj//usr2/data/freebsd/src/sys # one gets: # cwd is /usr3/obj/usr2/data/freebsd/src/sys # pwd is /usr3/obj/usr2/data/freebsd/src/sys # .CURDIR is /usr2/data/freebsd/src/sys # if one then does # rm obj # one gets: # cwd is /usr2/data/freebsd/src/sys # pwd is /usr2/data/freebsd/src/sys # .CURDIR is /usr2/data/freebsd/src/sys obj_tst2: @pwd @ln -s /usr/obj/`pwd` obj @pwd obj_tst3: @pwd # this command: # rm obj ; make obj_tst2 obj_tst3 ; make obj_tst3 # produces 3 of "/usr2/data/freebsd/src/sys" # then "/usr3/obj/usr2/data/freebsd/src/sys" # which tells us the cwd shift to obj is done only when the Makefile # starts, if obj pre exists then. .endif #} # ============================================================================= .include # Does the subdir stuff # .include # Supplies KERNEL_NAME=kernel # sys.mk hashed out 2001.03.08 # (C programs should use /usr/include/paths.h: #define _PATH_UNIX "/kernel") # ----------------------------------------------------------------------------- # MAINTENANCE NOTES: # - sys/Makefile & sys/Makefile_sub.c use /usr/share/mk/bsd.subdir.mk # - These makefile were far from easy to write & test, # please don't underestimate it, & don't offer patches for it till you # understand the comments & how bsd make with share/mk/* works, # and have considered multiple parallel makes off nfs mounted or # cd-rom filesystems etc. # If you don't fully undestand FreeBSD make & macros in share/mk, # don't start here, learn with something simpler such as # /usr/src/bin/ls/Makefile. # - When reading include files remember: # First target found is the target that is used. # Last macro definition is macro used. # - The driving source is simply called Makefile to allow default # make rules to work when recursing down tree from /usr/src/Makefile. # - For Makefile_sub.c: Cpp is used to generate the ${M_SUB}, # to get dependency labels (to the left of the colon) such as # CONFIG_TREE_TEST # to be recognised by freebsd make. # (I couldnt in a simple makefile use labels like: # compile/${THIS_CONFIG}/kernel: # imake was not part of FreeBSD base, so is not used). # - I do not use a method whereby I would assume a local hostname in # DEFAULT_CONFIG, instead I call `hostname` if it is empty # (as distributed) this avoids problems of: # a) source tree copied unclean to other systems # b) source tree shared by several nfs mounted hosts, # - Make builds a dependency list at startup, # timestamps are also checked at startup, not on the fly. # so we have to run a second make to notice if ${FORCE_MAKEFILE} # has been touched by commands within label `config_makefile`. # - Constructs such as: # foo: `bar` # won't work, so cannot have # ${M_SUB}: ${MACHINE}/conf/`cat ${THIS_CONFIG}` # as `cat ${THIS_CONFIG}` would not evaluate. # - These makefile were designed prior to the availability of safe # usable 4.4BSD style stackable/overlay file systems, # perhaps later overlay file systems might simplify the design. # - Never insert a space after macro equates & before comment # delimeter #, without carefully examining every usage of macro, # to see if space will break something (for instance # "KERNEL_NAME= kernel #comment" # would be an error). # Call Sequence # - The dest tree (/usr/dest/usr2/data/freebsd/src/sys ) is # created by /usr/src/Makefile:directories: calling etc/Makefile: # distrib-dirs: # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # PIERO WROTE: # serini@_ERASE_dsi.unimi.it # Tell me when you want (if ever) my changes # to it, to move all the configure stuff in /etc/kconf # ----- # > > > If someone wants the patchs to try this out, mail me. # > > I have to finish sys/Makefile upgrade first, else our work will collide. # > Mail me when you're ready. # OK # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Rod wrote # Thanks for looking at this one, # > it may very well turn out to be a real bear since the kernel does # > things like cc -I../../sys and such, and that will break if # > /sys/compile/X is someplace else! I think you can get around # > that one with a ${.CURDIR}../../sys, that may very well make it # > work for the include files, and the same type of thing can be # > done for the other files. This is going to be MAJOR surgery on # > src/sys/i386/Makefile.i386 to say the least! # from src/Mak: # + if test -d /usr/obj -a ! -d $$dest; then \ # + mkdir -p $$dest; \ # + else \ # + true; \ # + fi; # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # COPYRIGHT (c) 1993 Julian Stacey, Munich, Germany. All rights reserved. # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # This software is provided by Julian Stacey ``as is'' and # any express or implied warranties, including, but not limited to, the # implied warranties of merchantability and fitness for a particular # purpose are disclaimed. In no event shall Julian Stacey be liable # for any direct, indirect, incidental, special, exemplary, or # consequential damages (including, but not limited to, procurement of # substitute goods or services; loss of use, data, or profits; or # business interruption) however caused and on any theory of liability, # whether in contract, strict liability, or tort (including negligence # or otherwise) arising in any way out of the use of this software, # even if advised of the possibility of such damage. # End of sys/Makefile.