added my responsibility for the `cpm' port
[unix-history] / sys / Makefile
CommitLineData
68bcb3ab
RG
1# From: /usr/src/sys/Makefile V1.4 <stacey@guug.de>
2# $Id$
3#
4# Copyright Julian Stacey, Munich Oct. 1993, Free Software, No Liability
5# For Legalities see end of file.
6#
7# OVERVIEW:
8# Makefile & Makefile_sub.c are for the FreeBSD kernel usually
9# found in /usr/src/sys. They provide:
10# - Kernel configuration & make, defaulting to a kernel flavour
11# automatically selected on a host name basis.
12# - Automatic config prior to make if configuration name changes.
13# - depend is done automatically.
14# - Overide of default flavour by either "make CONFIG=whatever"
15# or by editing default file.
16# - Selection precedence order & examples:
17# PRIORITY METHOD
18# Highest: make CONFIG=your_flavour
19# else
20# Medium: edit ${DEFAULT_FLAVOUR} contents to flavour
21# else
22# Lowest: Makefile internally does CONFIG=`hostname`
23# TO SELECT YOUR FAVOURITE KERNEL FLAVOUR BY DEFAULT:
24# Move your favourite i386/conf configuration file to
25# [/sys/]i386/conf/`hostname`
26# Examples of how to force compilation of non hostname configurations:
27# a) make CONFIG=LINT
28# b) echo "GENERICAH" > .config.default ; make
29# EXTERNAL ENVIRONMENT VARIABLES:
30# MACHINE Mandatory. Must be preset before make is invoked,
31# example: i386.
32# DESTDIR Optional. If preset in the environment,
33# it is recognised.
34# BOOT_SYS Optional. Set to enable makes in the i386/boot
35# (mdec) sub directory,
36# (may later be un-necessary,
37# if we use SUBDIR=${MACHINE}/boot).
38# BOOT_FLAG Optional. Set to null (with "BOOT_FLAG=") to
39# allow makes in i386/boot,
40# (overrides the default make -n).
41# CONFIG Optional Usage as shown above.
42# DEBUG_SYS Optional Preset to debug makefile.
43# REQUIREMENTS: bsd-make, a cpp.
44# PENDING:
45# obj: label needs to be filled out:
46# Till then binaries get compiled in source tree,
47# which isnt nice for following reasons:
48# - If source is on a cd-rom,
49# - If source is on a networked source tree serving
50# several simultaneous compiles
51# Local variants of Makefile_sub .config.now, .config.last
52# .config.makefile will collide).
53# Work around problem for now by ensuring each compile is
54# done in its own seperate writable source tree, with symbolic
55# links pointing to each source file (including such as
56# Makefile & Makefile_sub.c)
57# Review whether I still need .config.import in
58# Makefile & Makefile_sub.c
59# BUGS: If old config that does not recognise config "386bsd" at 0x...
60# complains of syntax error, no error code is received
61# the make then later fails.
62# -----------------------------------------------------------------------------
63# MAINTENANCE NOTES
64# - If changing names ensure consistency in Makefile & Makefile_sub.c.
65# - I do not use a method whereby I would assume a local hostname in
66# DEFAULT_FLAVOUR, instead I take `hostname` if it is empty
67# (as distributed) this avoids problems of:
68# a) source tree copied unclean to other systems
69# b) source tree shared by several nfs mounted hosts,
70# - Cpp is used to generate the $(MAKEFILE_KERNEL), to get dependency labels
71# (to the left of the colon) such as CONFIG_TREE_TEST to be recognised
72# by freebsd make (I couldnt in a simple makefile use labels like:
73# compile/${THIS_FLAVOUR}/386bsd: )
74# - The driving source is simply called Makefile to allow default
75# make rules to work when recursing down tree from /usr/src/Makefile.
76# - make builds a dependency list at startup,
77# timestamps are also checked at startup, not on the fly.
78# so we have to run a second make to notice if ${FORCE_MAKEFILE} has been
79# touched by commands within label `config_makefile`.
80# - constructs such as:
81# foo: `bar`
82# won't work.
83# - Cannot have $(MAKEFILE_KERNEL): ${MACHINE}/conf/`cat ${THIS_FLAVOUR}`
84# as `cat ${THIS_FLAVOUR}` would not evaluate.
85# ----------------------------------------------------------------------------
86# INTERNAL ENVIRONMENT VARIABLES, & FILE NAMES:
87# Changeable by user (but if changed, do a make cleandir first, and
88# leave no gap between assigned variable string and # comment delimiter !
89KERNEL_NAME= 386bsd# Kernel Name
90DEFAULT_FLAVOUR= .config.default# Contains name of what to make by default
91THIS_FLAVOUR= .config.now# Contains what to make now, (a temp variable).
92LAST_FLAVOUR= .config.last# What MAKEFILE_KERNEL was last produced for.
93FORCE_MAKEFILE= .config.makefile# If new MAKEFILE_KERNEL to be forcibly built.
94BOOT_FLAG= -n # Prevents real make in i386/boot/, Can be overridden by bsd_make BOOT_FLAG=
95# ----------------------------------------------------------------------------
96# INTERNAL ENVIRONMENT VARIABLES:
97# Do NOT change these without reading Makefile & Makefile_sub.c.
98# Do not add gaps between assigned variable string and # comment delimiter !
99MAKEFILE_KERNEL=Makefile_sub# also used to refer to Makefile_sub.c
100TREE_TEST= Makefile# used as: compile/CONFIG_NAME/$TREE_TEST,
101# ( typically compile/GENERICAH/Makefile )
102# compared with config file date.
103# swap386bsd.c is newer, but not sure if
104# swap${MACHINE}.c would be an architecture
105# independent portable name.
106.PATH= # No directories searched for files not found in current dir.
107CONFIG:= `hostname`# Can be overridden by bsd_make CONFIG=whatever
108CWD!= pwd
109INFORM= echo
110.if defined(DEBUG_SYS)
111CALL_BEFORE= " /sys/makefile label "
112CALL_AFTER= " has been invoked."
113.else
114# Suppress chat about what config being made etc.
115DIVERT= > /dev/null
116.endif
117BOOT_START="Start considering (with make ${BOOT_FLAG}) what could be done in ${MACHINE}/boot:"
118BOOT_END="End of considering ${MACHINE}/boot."
119TRANSIENT= ${LAST_FLAVOUR} ${THIS_FLAVOUR} \
120 ${FORCE_MAKEFILE} ${MAKEFILE_KERNEL} .config.import
121# Transient temporary files, created by config_makefile.
122
123# =============================================================================
124
125# EXTERNALLY CALLABLE LABELS
126
127# This label is callable from /usr/src/Makefile.
128all: all_start config_tree compile_tree boot_all all_end
129
130# This label is callable from /usr/src/Makefile,
131# Clean current-flavour compile tree, but not other flavours.
132clean: clean_start lifebelt config_makefile boot_clean
133 @${INFORM} "Cleaning compile tree for configuration name `cat $(THIS_FLAVOUR)`". ${DIVERT}
134 @echo "==={> compile/`cat $(CWD)/$(THIS_FLAVOUR)`"
135 -(cd ./compile; cd ./`cat $(CWD)/$(THIS_FLAVOUR)`; make clean)
136 @echo "<}=== compile/`cat $(CWD)/$(THIS_FLAVOUR)`"
137# # cd is done in 2 stages in case directory named in $(THIS_FLAVOUR)
138# # is not there, else make would recurse endlessly.
139# # A more drastic alternative to the above make clean could be:
140# # -rm -r -f ./compile/`cat ./$(THIS_FLAVOUR)`/*
141 @${INFORM} Removing makefile temporary files. ${DIVERT}
142 -rm -f ${TRANSIENT}
143# # Dont move "rm TRANSIENT" before "rm compile/`cat ${THIS_FLAVOUR}`"
144 @${INFORM} To do more extensive cleaning, use make cleandir ${DIVERT}
145
146# This label is callable from /usr/src/Makefile,
147cleandir: cleandir_start boot_cleandir
148 @${INFORM} Removing all kernel compile trees. ${DIVERT}
149 -rm -f -r compile/*
150 -rm -f ${TRANSIENT}
151 @echo "Warning: Removing $(DEFAULT_FLAVOUR)."
152 @echo Future makes will default to generate a flavour for `hostname`.
153 -rm -f $(DEFAULT_FLAVOUR)
154 @${INFORM} To also clean kernel in destination tree, use make clean_dest ${DIVERT}
155
156clean_dest:
157 @${INFORM} Cleaning destination tree kernel. ${DIVERT}
158 -rm -f $(DESTDIR)/${KERNEL_NAME}.untested.`cat ${THIS_FLAVOUR}`
159 -rm -f $(DESTDIR)/config.untested.`cat ${THIS_FLAVOUR}`
160# # Suprisingly the - before the rm above is needed for
161# # $(DESTDIR)/${KERNEL_NAME}.untested.${CONFIG_NAME} else make clean
162# # fails, yet rm exit value bug supposed to have been fixed way back.
163
164# This label is callable from /usr/src/Makefile,
165depend: boot_depend
166 @${INFORM} "${CALL_BEFORE}'all'${CALL_AFTER}" ${DIVERT}
167 @echo This a dummy depend label in sys/Makefile to satisfy possible callers.
168# # Currently the config depend gets done from `all', later
169# # when I've thought more about it, maybe I'll add `depend:'
170# # to be dependent on `config_tree'.
171# # As dependencies get evaluated anyway, & as /sys/make call
172# # make depend
173
174# This label is callable from /usr/src/Makefile,
175obj: obj_start boot_obj
176 @echo "NOT YET DEVELOPED AN obj ENTRY FOR /sys/Makefile."
177 @echo "So compiles are in source directory."
178 @echo Do not attempt to share a common source directory with others,
179 @echo "as transient files will conflict (eg ${TRANSIENT})"
180
181# This label is callable from /usr/src/Makefile,
182install: install_start all boot_install
183 install -c -m 644 compile/`cat $(THIS_FLAVOUR)`/${KERNEL_NAME} \
184 $(DESTDIR)/${KERNEL_NAME}.untested.`cat $(THIS_FLAVOUR)`
185# # Beware: If you remove the word untested, & then `cat $(THIS_FLAVOUR)`
186# # does not evaluate properly, you will overwrite your current
187# # working kernel.
188 install -c -m 644 ${MACHINE}/conf/`cat $(THIS_FLAVOUR)` \
189 $(DESTDIR)/config.untested.`cat $(THIS_FLAVOUR)`
190 sync # ensure complete kernel in root even if update dead
191 @${INFORM} "Looking at kernel sizes (> 593920 may overlap floppy buffers):" ${DIVERT}
192 -find $(DESTDIR)/$(KERNEL_NAME)* \! -name \*.gz -print | xargs size
193 @${INFORM} -n "For local notes on kernel sizes etc:" ${DIVERT}
194 @${INFORM} -n " cat ${MACHINE}/doc/`cat $(THIS_FLAVOUR)`" ${DIVERT}
195 @${INFORM} -n To test: fasthalt, wait, select $(DESTDIR)/${KERNEL_NAME}.untested. ${DIVERT}
196 @${INFORM} "`cat ${THIS_FLAVOUR}`" ${DIVERT}
197
198# =============================================================================
199# LABELS BELOW HERE ARE INTERNAL, (not to be called from outside this Makefile)
200# =============================================================================
201lifebelt:
202 @${INFORM} "make clean decides what flavour to clean in a rather complex" ${DIVERT}
203 @${INFORM} "way using tools such as cpp. If make clean breaks" ${DIVERT}
204 @${INFORM} "call the more simplistic make cleandir." ${DIVERT}
205
206clean_start cleandir_start all_start install_start obj_start all_end:
207 @${INFORM} "${CALL_BEFORE}$@${CALL_AFTER}" ${DIVERT}
208
209# -----------------------------------------------------------------------------
210# STUFF TO SUPERCEDE ../Makefile mdec:
211# (maybe to be in turn superceeded by SUBDIR=${MACHINE}/boot
212
213boot_all:
214 @${INFORM} ${BOOT_START} ${DIVERT}
215.if defined (BOOT_SYS)
216.if ${MACHINE} == "i386"
217# # mdec work is called from /usr/src/Makefile, this was done before
218# # this /usr/src/sys/Makefile was written, boot_all work could/should
219# # now be moved down to here
220# # (but not until people have had time to object)
221 @${INFORM} /usr/src/Makefile currently deals with mdec work. ${DIVERT}
222 @echo "==={> ${MACHINE}/boot"
223 cd ./${MACHINE}/boot; make ${BOOT_FLAG} depend all install ${CLEANDIR}
224 @echo "<}=== ${MACHINE}/boot"
225.if defined (DESTDIR)
226 @${INFORM} -n "NOT DOING: " ${DIVERT}
227 @${INFORM} "cd /usr/mdec; find . | cpio -pdamuv ${DESTDIR}/usr/mdec" ${DIVERT}
228# # The above is what /usr/src/Makefile does,
229# # however it should be improved,
230# # because boot blocks going to DESTDIR should come from the obj tree,
231# # not from out current live /usr/mdec.
232# # cpio flags:
233# -a: Reset the access times of files after reading them,
234# so that it does not look like they have just been
235# read.
236# -d: Create leading directories where needed.
237# -m: Retain previous file modification times when creat-
238# ing files.
239# -p: Run in copy-pass mode.
240# -u: Replace all files, without asking whether to
241# replace existing newer files with older files.
242# -v: List the files processed, or with -t, give an `ls
243# -l' style table of contents listing. In a verbose
244# table of contents of a ustar archive, user and
245# group names in the archive that do not exist on the
246# local system are replaced by the names that corre-
247# spond locally to the numeric UID and GID stored in
248# the archive.
249.endif
250.endif
251.endif
252 @${INFORM} ${BOOT_END} ${DIVERT}
253
254boot_install: boot_start
255.if defined (BOOT_SYS)
256 @echo "==={> ${MACHINE}/boot"
257 cd ./${MACHINE}/boot; make ${BOOT_FLAG} install
258 @echo "<}=== ${MACHINE}/boot"
259.endif
260 @${INFORM} ${BOOT_END} ${DIVERT}
261
262boot_clean: boot_start
263.if defined (BOOT_SYS)
264 @echo "==={> ${MACHINE}/boot"
265 cd ./${MACHINE}/boot; make ${BOOT_FLAG} clean
266 @echo "<}=== ${MACHINE}/boot"
267.endif
268 @${INFORM} ${BOOT_END} ${DIVERT}
269
270boot_cleandir: boot_start
271.if defined (BOOT_SYS)
272 @echo "==={> ${MACHINE}/boot"
273 cd ./${MACHINE}/boot; make ${BOOT_FLAG} cleandir
274 @echo "<}=== ${MACHINE}/boot"
275.endif
276 @${INFORM} ${BOOT_END} ${DIVERT}
277
278boot_depend: boot_start
279.if defined (BOOT_SYS)
280 @echo "==={> ${MACHINE}/boot"
281 cd ./${MACHINE}/boot; make ${BOOT_FLAG} depend
282 @echo "<}=== ${MACHINE}/boot"
283.endif
284 @${INFORM} ${BOOT_END} ${DIVERT}
285
286boot_obj: boot_start
287.if defined (BOOT_SYS)
288 @echo "==={> ${MACHINE}/boot"
289 cd ./${MACHINE}/boot; make ${BOOT_FLAG} obj
290 @echo "<}=== ${MACHINE}/boot"
291.endif
292 @${INFORM} ${BOOT_END} ${DIVERT}
293
294boot_start:
295 @${INFORM} ${BOOT_START} ${DIVERT}
296
297# -----------------------------------------------------------------------------
298# Stuff to determine which flavour kernel to compile.
299
300config_which:
301 @${INFORM} Determining which kernel flavour to make. ${DIVERT}
302 @${INFORM} CONFIG variable is $(CONFIG). ${DIVERT}
303.if exists(${DEFAULT_FLAVOUR})
304 @${INFORM} "${DEFAULT_FLAVOUR} exists" ${DIVERT}
305 @${INFORM} Seeing if ${DEFAULT_FLAVOUR} has contents. ${DIVERT}
306 if ( XX==X`cat ${DEFAULT_FLAVOUR}`X ); \
307 then \
308 ${INFORM} "${DEFAULT_FLAVOUR} is empty" ${DIVERT} ; \
309 echo "$(CONFIG)" > ${THIS_FLAVOUR}; \
310 else \
311 ${INFORM} "${DEFAULT_FLAVOUR} is not empty" ${DIVERT} ; \
312 echo "`cat ${DEFAULT_FLAVOUR}`" > ${THIS_FLAVOUR}; \
313 fi
314.else
315 @${INFORM} "${DEFAULT_FLAVOUR} not extant." ${DIVERT}
316.if defined(CONFIG)
317 @${INFORM} "CONFIG Makefile variable in ${THIS_FLAVOUR} set to ${CONFIG}." ${DIVERT}
318 @echo ${CONFIG} > ${THIS_FLAVOUR}
319.else
320 @${INFORM} "CONFIG Makefile variable unset" ${DIVERT}
321 @${INFORM} "Assuming existence of $(MACHINE)/conf/`hostname`" ${DIVERT}
322 hostname > ${THIS_FLAVOUR}
323.endif
324.endif
325 @${INFORM} "Flavour to be worked on is `cat ${THIS_FLAVOUR}`." ${DIVERT}
326.if !exists(${LAST_FLAVOUR})
327 @${INFORM} "Creating a dummy ${LAST_FLAVOUR} as no previous make" ${DIVERT}
328 cp /dev/null ${LAST_FLAVOUR}
329# # ${LAST_FLAVOUR} is used to sense change of configuration to be made.
330.endif
331# -----------------------------------------------------------------------------
332# Decide if Makefile_sub should be remade.
333config_makefile: config_which $(MAKEFILE_KERNEL)
334 @${INFORM} Determining if $(MAKEFILE_KERNEL) needs to be remade. ${DIVERT}
335.if !exists(${FORCE_MAKEFILE})
336 touch ${FORCE_MAKEFILE} ;
337# # This touch only needs to be in the "then", not the "else",
338# # however getting it there causes problems with backslash delimeters.
339.endif
340 if ( XX==X`cmp ${LAST_FLAVOUR} ${THIS_FLAVOUR}`X ); \
341 then \
342 ${INFORM} -n "Same configuration name as last time," ${DIVERT} ; \
343 ${INFORM} " no need to remake $(MAKEFILE_KERNEL)." ${DIVERT} ; \
344 else \
345 ${INFORM} -n "Configuration changed from " ${DIVERT} ; \
346 ${INFORM} "`cat ${LAST_FLAVOUR}` to `cat ${THIS_FLAVOUR}`." ${DIVERT} ; \
347 ${INFORM} "Forcing a new $(MAKEFILE_KERNEL)" ${DIVERT} ; \
348 touch ${FORCE_MAKEFILE}; \
349 echo "==={> $(MAKEFILE_KERNEL)" ; \
350 make $(MAKEFILE_KERNEL); \
351 echo "<}=== $(MAKEFILE_KERNEL)" ; \
352 fi
353# -----------------------------------------------------------------------------
354# Make a compile tree (of sources).
355.if defined(LOAD_ADDRESS)
356T_LD_ADR=LOAD_ADDRESS=${LOAD_ADDRESS}
357.else
358T_LD_ADR=
359.endif
360.if defined(DEBUG_SYS)
361T_DBG=DEBUG_SYS=YES
362.else
363T_DBG=
364.endif
365config_tree: config_makefile
366 @${INFORM} Determining if compile tree needs to be remade. ${DIVERT}
367 @echo "==={> $(MAKEFILE_KERNEL)"
368 make -f $(MAKEFILE_KERNEL) ${T_DBG} ${T_LD_ADR} \
369 compile/`cat ${THIS_FLAVOUR}`/${TREE_TEST}
370 @echo "<}=== $(MAKEFILE_KERNEL)"
371# -----------------------------------------------------------------------------
372# Create a file who's sole purpose is to be a timestamp,
373# if this file is newer than $(MAKEFILE_KERNEL), then $(MAKEFILE_KERNEL)
374# needs to be remade.
375${FORCE_MAKEFILE}:
376 touch $@
377# -----------------------------------------------------------------------------
378# Make Makefile_sub.
379$(MAKEFILE_KERNEL): Makefile ${MAKEFILE_KERNEL}.c ${FORCE_MAKEFILE}
380 @${INFORM} "${CALL_BEFORE}$@${CALL_AFTER}" ${DIVERT}
381 cpp -P -DCONFIG_NAME=`cat ${THIS_FLAVOUR}` -Ui386 \
382 -DCONFIG_TREE_TEST=compile/`cat ${THIS_FLAVOUR}`/${TREE_TEST} \
383 -DMAKEFILE_KERNEL=${MAKEFILE_KERNEL} \
384 ${MAKEFILE_KERNEL}.c > $(MAKEFILE_KERNEL) \
385# # -Ui386 avoids damage to names like .../i386/conf/...
386 cp ${THIS_FLAVOUR} ${LAST_FLAVOUR}
387# -----------------------------------------------------------------------------
388# Compile a tree.
389compile_tree:
390 @${INFORM} $(MAKEFILE) label $@ ${DIVERT}
391 @${INFORM} "Making kernel compilation tree for `cat ${THIS_FLAVOUR}`." ${DIVERT}
392 @echo "==={> compile/`cat ${THIS_FLAVOUR}`"
393 cd ./compile/`cat ${THIS_FLAVOUR}`; make
394 @echo "<}=== compile/`cat ${THIS_FLAVOUR}`"
395# -----------------------------------------------------------------------------
396.include <bsd.subdir.mk>
397# Maybe a subsidiary make in compile/something or i386/boot will want bsd.subdir.mk,
398# but Makefile_sub.c does not need it, (neither does it cause harm).
399# -----------------------------------------------------------------------------
400# LEGALITIES (as refered to from top of file).
401#
402# Copyright (c) 1993 Julian Stacey, Munich, Germany.
403# All rights reserved.
404#
405# Redistribution and use in source and binary forms, with or without
406# modification, are permitted provided that the following conditions
407# are met:
408# 1. Redistributions of source code must retain the above copyright
409# notice, this list of conditions and the following disclaimer.
410# 2. Redistributions in binary form must reproduce the above copyright
411# notice, this list of conditions and the following disclaimer in the
412# documentation and/or other materials provided with the distribution.
413#
414# This software is provided by Julian Stacey (and subsequent
415# contributors) ``as is'' and
416# any express or implied warranties, including, but not limited to, the
417# implied warranties of merchantability and fitness for a particular purpose
418# are disclaimed. In no event shall Julian Stacey (and subsequent
419# contributors) be liable
420# for any direct, indirect, incidental, special, exemplary, or consequential
421# damages (including, but not limited to, procurement of substitute goods
422# or services; loss of use, data, or profits; or business interruption)
423# however caused and on any theory of liability, whether in contract, strict
424# liability, or tort (including negligence or otherwise) arising in any way
425# out of the use of this software, even if advised of the possibility of
426# such damage.
427
428# End of Makefile.
429
430# End of Makefile