17c478bd9Sstevel@tonic-gate# 27c478bd9Sstevel@tonic-gate# CDDL HEADER START 37c478bd9Sstevel@tonic-gate# 47c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the 5*a237e38eSth199096# Common Development and Distribution License (the "License"). 6*a237e38eSth199096# You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate# 87c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate# and limitations under the License. 127c478bd9Sstevel@tonic-gate# 137c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate# 197c478bd9Sstevel@tonic-gate# CDDL HEADER END 207c478bd9Sstevel@tonic-gate# 21*a237e38eSth199096 22*a237e38eSth199096# 23*a237e38eSth199096# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate# Use is subject to license terms. 257c478bd9Sstevel@tonic-gate# 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gateKERNEL MAKEFILE STRUCTURE 287c478bd9Sstevel@tonic-gate------------------------- 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gateThe advent of dynamic loading of kernel modules has obsoleted the 317c478bd9Sstevel@tonic-gate4.x kernel configuration scheme which was centered around a derived 327c478bd9Sstevel@tonic-gateMakefile and a collection of derived header files generated by the 337c478bd9Sstevel@tonic-gateconfig(8) program. This file describes the structure of the replacement 347c478bd9Sstevel@tonic-gate"static" set of Makefiles. 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gateSome additional secondary goals were associated with the generation 377c478bd9Sstevel@tonic-gateof these Makefiles. It should be noted that the ability to properly 387c478bd9Sstevel@tonic-gatedeal with derived Makefiles is an explicit non-goal of the ongoing 397c478bd9Sstevel@tonic-gateNSE enhancements, so this project is a necessary consequence of that 407c478bd9Sstevel@tonic-gatedecision. 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gateAll project goals are enumerated below: 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate1] To provide a set of static Makefiles to support kernel build 457c478bd9Sstevel@tonic-gate and installation. 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate2] To provide a set of static Makefiles which conform to the 487c478bd9Sstevel@tonic-gate "Makefiles Guidelines". (This document is currently available 497c478bd9Sstevel@tonic-gate on-line as "terminator:/usr/integration/doc/make.std") 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate3] To completely eliminate the config(8) program. 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate4] To provide a framework for linting the kernel (so that "lint free" 547c478bd9Sstevel@tonic-gate can be made an integration criterion, in addition to being general 557c478bd9Sstevel@tonic-gate good hygiene). 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate5] To eliminate the need for the small headers generated by config(8). 587c478bd9Sstevel@tonic-gate In the ddi/dki world this need is completely eliminated as drivers 597c478bd9Sstevel@tonic-gate will be expected to dynamically configure themselves. Interim support 607c478bd9Sstevel@tonic-gate for existing drivers will be provided. 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate6] To be able to "acquire" only the files needed to build a specific 637c478bd9Sstevel@tonic-gate module, if that is all that is needed. 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate7] To provide a framework suitable for the production of "implementation 667c478bd9Sstevel@tonic-gate architecture" independent modules. 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate8] To restructure the assembly language files to support the generation 697c478bd9Sstevel@tonic-gate of "lint-libraries" from them. 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate9] To provide support for the incidental Makefile targets many developers 727c478bd9Sstevel@tonic-gate are accustomed to (such as cscope and tags). These can be added to the 737c478bd9Sstevel@tonic-gate Makefiles asd required. (cscope is currently supported.) 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gateGENERAL STRUCTURE 777c478bd9Sstevel@tonic-gate----------------- 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gateThe source code layout is not generally effected by the Makefiles. However, 807c478bd9Sstevel@tonic-gatethe location of the generated files has changed dramatically. 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate"Implementation architecture" independent modules are produced in 837c478bd9Sstevel@tonic-gateindividual directories (one per module) under the "instruction-set 847c478bd9Sstevel@tonic-gatearchitecture" directory (i.e.: sparc). Similarly, "implementation 857c478bd9Sstevel@tonic-gatearchitecture" dependent modules are produced in individual directories 867c478bd9Sstevel@tonic-gateunder the "implementation architecture" directory (i.e.: sun4, sun4c). 877c478bd9Sstevel@tonic-gateIt should be noted that currently (4/14/91) no implementation architecture 887c478bd9Sstevel@tonic-gatemodules exist. This situation is expected to change shortly. 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gateThe driving Makefile for any module is located in the leaf directory 917c478bd9Sstevel@tonic-gatewhere the module (and associated objects) are built. After a 'make 927c478bd9Sstevel@tonic-gateclobber' operation, the Makefile is the only file remaining in that 937c478bd9Sstevel@tonic-gatedirectory. Common definitions and rules are contained in suffixed 947c478bd9Sstevel@tonic-gateMakefiles in non-leaf directories which are included in the leaf 957c478bd9Sstevel@tonic-gateMakefiles. Non-suffixed Makefiles in non-leaf directories generally 967c478bd9Sstevel@tonic-gateinvoke lower level Makefiles to perform the actual tasks. 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gateuts/Makefile 997c478bd9Sstevel@tonic-gateuts/sparc/Makefile 1007c478bd9Sstevel@tonic-gateuts/sun4c/Makefile 1017c478bd9Sstevel@tonic-gateuts/sun4c/svvs/Makefile 1027c478bd9Sstevel@tonic-gate These Makefiles generally are cognizant of the components 1037c478bd9Sstevel@tonic-gate made in subdirectories and invoke Makefiles in those sub- 1047c478bd9Sstevel@tonic-gate directories to perform the actual build. Some targets (or 1057c478bd9Sstevel@tonic-gate pseudo-targets) may be directly built at this level (such 1067c478bd9Sstevel@tonic-gate as the cscope databases). 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gateuts/Makefile.uts 1097c478bd9Sstevel@tonic-gate Contains common definitions for all possible architectures. 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gateuts/Makefile.targ 1127c478bd9Sstevel@tonic-gate Contains common targets for all possible architectures. 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gateuts/common/Makefile.files 1157c478bd9Sstevel@tonic-gateuts/sun/Makefile.files 1167c478bd9Sstevel@tonic-gateuts/sparc/Makefile.files 1177c478bd9Sstevel@tonic-gateuts/sun4c/Makefile.files 1187c478bd9Sstevel@tonic-gateuts/sun4/Makefile.files 1197c478bd9Sstevel@tonic-gate These Makefiles are divided into two sections. The first 1207c478bd9Sstevel@tonic-gate section can be viewed as the equivalent of the "files" (sparc 1217c478bd9Sstevel@tonic-gate and sun4c) and "files.cmn" (common and sun) files. These 1227c478bd9Sstevel@tonic-gate define the object lists which define each module. The second 1237c478bd9Sstevel@tonic-gate section defines the appropriate header search paths and other 1247c478bd9Sstevel@tonic-gate machine specific global build parameters. 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gateuts/common/Makefile.rules 1277c478bd9Sstevel@tonic-gateuts/sun/Makefile.rules 1287c478bd9Sstevel@tonic-gateuts/sparc/Makefile.rules 1297c478bd9Sstevel@tonic-gateuts/sun4c/Makefile.rules 1307c478bd9Sstevel@tonic-gateuts/sun4/Makefile.rules 1317c478bd9Sstevel@tonic-gate The files provide build rules (targets) which allow make to function 1327c478bd9Sstevel@tonic-gate in a multiple directory environment. Each source tree below the 1337c478bd9Sstevel@tonic-gate directory containing the Makefile has a build rule in the file. 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gateuts/sun4c/Makefile.sun4c 1367c478bd9Sstevel@tonic-gateuts/sun4/Makefile.sun4 1377c478bd9Sstevel@tonic-gate These Makefile contains the definitions specific (defaults) to 1387c478bd9Sstevel@tonic-gate the obvious "implementation architecture". These rules can be 1397c478bd9Sstevel@tonic-gate overridden in specific leaf node Makefiles if necessary. 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gateuts/sun4c/unix/Makefile 1427c478bd9Sstevel@tonic-gate Main driving Makefile for building /unix. 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gateuts/sun4c/MODULE/Makefile (for MODULE in arp, aoutexec, ...) 1457c478bd9Sstevel@tonic-gate Main driving Makefile for building MODULE.kmod. 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gateuts/sun4c/unix.static/Makefile 1487c478bd9Sstevel@tonic-gate Main driving Makefile for building a static unix (for development 1497c478bd9Sstevel@tonic-gate work only). This Makefile is known to NSE, but its targets are 1507c478bd9Sstevel@tonic-gate not. This makefile may be copied to additional parallel directories 1517c478bd9Sstevel@tonic-gate to build multiple configurations. This configuration is roughly 1527c478bd9Sstevel@tonic-gate equivalent to the GENERIC kernel of SunOS 4.x. 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gateThe Makefiles are verbosely commented. It is desired that they should 1557c478bd9Sstevel@tonic-gatestay this way. 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gateUSE 1597c478bd9Sstevel@tonic-gate--- 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gateIssuing the command 'make' in the uts directory will cause all supported, 1627c478bd9Sstevel@tonic-gatemodularized kernels and modules to be built. 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gateIssuing the command 'make' in a uts/ARCHITECTURE directory (i.e.: uts/sparc) 1657c478bd9Sstevel@tonic-gatewill cause all supported, "implementation architecture" independent modules 1667c478bd9Sstevel@tonic-gatefor ARCHITECTURE to be built. 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gateIssuing the command 'make' in a uts/MACHINE directory (i.e.: uts/sun4c) 1697c478bd9Sstevel@tonic-gatewill cause that kernel and all supported, "implementation architecture" 1707c478bd9Sstevel@tonic-gatedependent modules for MACHINE to be built. 1717c478bd9Sstevel@tonic-gate 1727c478bd9Sstevel@tonic-gateIssuing the command 'make' in the uts/MACHINE/unix directory will cause the 1737c478bd9Sstevel@tonic-gatekernel for MACHINE to be built (and unix.o). 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gateIssuing the command 'make' in a uts/MACHINE/MODULE or a uts/ARCHITECTURE/MODULE 1767c478bd9Sstevel@tonic-gatedirectory will cause MODULE.kmod to be built. 1777c478bd9Sstevel@tonic-gate 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gateLINT 1807c478bd9Sstevel@tonic-gate---- 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gateLinting is fairly similar to the builds, but it has an additional complication. 1837c478bd9Sstevel@tonic-gateIn order to get meaningful output from lint pass2, all the modules must be 1847c478bd9Sstevel@tonic-gatelinted together. This is accomplished by each module being responsible to 1857c478bd9Sstevel@tonic-gateproduce its own pass1 output (file.ln, one per .c/.s file). It is also 1867c478bd9Sstevel@tonic-gateresponsible for placing the a lint-library (llib-lMODULE) in the 1877c478bd9Sstevel@tonic-gateuts/MACHINE/lint-libs directory. The final full lint is accomplished by the 1887c478bd9Sstevel@tonic-gateMakefile in the uts/MACHINE directory by linting all the lint-libraries 1897c478bd9Sstevel@tonic-gateagainst each other. 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gateNote that there is no equivalent to Locore.c in the current source base. 1927c478bd9Sstevel@tonic-gateThe C prototypes are in the .s files. As example: 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate #if defined(lint) 1957c478bd9Sstevel@tonic-gate int 1967c478bd9Sstevel@tonic-gate blort(int, int) 1977c478bd9Sstevel@tonic-gate { return 0 } 1987c478bd9Sstevel@tonic-gate #else /* lint */ 1997c478bd9Sstevel@tonic-gate 2007c478bd9Sstevel@tonic-gate ENTRY(blort) 2017c478bd9Sstevel@tonic-gate ld [%i0],.... 2027c478bd9Sstevel@tonic-gate .... 2037c478bd9Sstevel@tonic-gate SET_SIZE(blort) 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate #endif /* lint */ 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gateCOMPONENT HIERARCHY 2097c478bd9Sstevel@tonic-gate------------------ 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gateThe component hierarchy has been restructured to allow the acquisition of 2127c478bd9Sstevel@tonic-gatemore finely grained objects; specificly a kernel module. The basic component 2137c478bd9Sstevel@tonic-gatestructure is: 2147c478bd9Sstevel@tonic-gate 2157c478bd9Sstevel@tonic-gate :src:uts.all --+--> :sparc --+--> :MODULES... (none currently) 2167c478bd9Sstevel@tonic-gate | 2177c478bd9Sstevel@tonic-gate +--> :sun4c --+--> :unix 2187c478bd9Sstevel@tonic-gate | | 2197c478bd9Sstevel@tonic-gate | +--> :MODULES... 2207c478bd9Sstevel@tonic-gate | | 2217c478bd9Sstevel@tonic-gate | +--> :unix.static 2227c478bd9Sstevel@tonic-gate | 2237c478bd9Sstevel@tonic-gate +--> :sun4 ---+--> :unix 2247c478bd9Sstevel@tonic-gate | | 2257c478bd9Sstevel@tonic-gate | +--> :MODULES... 2267c478bd9Sstevel@tonic-gate | | 2277c478bd9Sstevel@tonic-gate | +--> :unix.static 2287c478bd9Sstevel@tonic-gate ... 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gateThe above diagram does not reflect the full component tree. The full component 2317c478bd9Sstevel@tonic-gatetree may be displayed with the "nsecomp list -r :src:uts.all" command. 2327c478bd9Sstevel@tonic-gate 2337c478bd9Sstevel@tonic-gate 2347c478bd9Sstevel@tonic-gateCOMMON OPERATIONS 2357c478bd9Sstevel@tonic-gate----------------- 2367c478bd9Sstevel@tonic-gate 2377c478bd9Sstevel@tonic-gateAdding a New Kernel Module 2387c478bd9Sstevel@tonic-gate-------------------------- 2397c478bd9Sstevel@tonic-gate 2407c478bd9Sstevel@tonic-gate 0] Create the source files (and directories) as usual. 2417c478bd9Sstevel@tonic-gate 242*a237e38eSth199096 1] Edit uts/*/Makefile.files to define the set of objects. By convention 2437c478bd9Sstevel@tonic-gate the symbolic name of this set is of the form MODULE_OBJS, where 2447c478bd9Sstevel@tonic-gate MODULE is the module name (i.e.: namefs). The files in each subtree 2457c478bd9Sstevel@tonic-gate should be defined in the Makefile.files in the root directory of that 2467c478bd9Sstevel@tonic-gate subtree. Note that they are defined using the += operator, so that 2477c478bd9Sstevel@tonic-gate the set can be built across multiple files. As example: 2487c478bd9Sstevel@tonic-gate 2497c478bd9Sstevel@tonic-gate NAMEFS_OBJS += namevfs.o namevno.o 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate Each source file needs a build rule in the corresponding Makefile.rules 2527c478bd9Sstevel@tonic-gate file (compilation and lint). A typical pair of entries would be: 2537c478bd9Sstevel@tonic-gate 2547c478bd9Sstevel@tonic-gate $(OBJS_DIR)/mem.o: $(UTSBASE)/sun4c/io/mem.c 2557c478bd9Sstevel@tonic-gate $(COMPILE.c) -o $@ $(UTSBASE)/sun4c/io/mem.c 2567c478bd9Sstevel@tonic-gate 2577c478bd9Sstevel@tonic-gate $(LINTS_DIR)/mem.ln: $(UTSBASE)/sun4c/io/mem.c 2587c478bd9Sstevel@tonic-gate @($(LHEAD) $(LINT.c) $(UTSBASE)/sun4c/io/mem.c $(LTAIL)) 2597c478bd9Sstevel@tonic-gate 2607c478bd9Sstevel@tonic-gate 2] Create build directories in the appropriate places. If the module 2617c478bd9Sstevel@tonic-gate can be built in a machine independent way, this would be in the 2627c478bd9Sstevel@tonic-gate "instruction set architecture" directory (i.e.: sparc). If not, these 2637c478bd9Sstevel@tonic-gate directories would be created for all appropriate "implementation 2647c478bd9Sstevel@tonic-gate architecture" dependent directories (i.e.: sun4, sun4c). 2657c478bd9Sstevel@tonic-gate 2667c478bd9Sstevel@tonic-gate 3] In each build directory, create a Makefile. This can usually be 2677c478bd9Sstevel@tonic-gate accomplished by copying a Makefile from a parallel directory and 2687c478bd9Sstevel@tonic-gate editing the following lines (in addition to comments). 2697c478bd9Sstevel@tonic-gate 2707c478bd9Sstevel@tonic-gate MODULE = namefs 2717c478bd9Sstevel@tonic-gate - replace with module name 2727c478bd9Sstevel@tonic-gate OBJECTS = $(NAMEFS_OBJS:%=$(OBJS_DIR)/%) 2737c478bd9Sstevel@tonic-gate LINTS = $(NAMEFS_OBJS:%.o=$(LINTS_DIR)/%.ln) 2747c478bd9Sstevel@tonic-gate - replace with MODULE_OBJS 2757c478bd9Sstevel@tonic-gate ROOTMODULE = $(ROOT_FS_DIR)/$(MODULE).kmod 2767c478bd9Sstevel@tonic-gate - replace directory part with the appropriate 2777c478bd9Sstevel@tonic-gate installation directory name (see Makefile.uts) 2787c478bd9Sstevel@tonic-gate 2797c478bd9Sstevel@tonic-gate If a custom version of modstubs.o is needed to check the undefines 2807c478bd9Sstevel@tonic-gate for this routine, the following lines need to appear in the 2817c478bd9Sstevel@tonic-gate Makefile (after the inclusion of Makefile.mach (i.e.: Makefile.sun4c)). 2827c478bd9Sstevel@tonic-gate 2837c478bd9Sstevel@tonic-gate MODSTUBS_DIR = $(OBJS_DIR) 2847c478bd9Sstevel@tonic-gate $(MODSTUBS_O) := AS_CPPFLAGS += -DNAMEFS_MODULE 2857c478bd9Sstevel@tonic-gate - replace "-DNAMEFS_MODULE" with the appropriate flag 2867c478bd9Sstevel@tonic-gate for the modstubs.o assembly. 2877c478bd9Sstevel@tonic-gate CLEANFILES += $(MODSTUBS_O) 2887c478bd9Sstevel@tonic-gate 2897c478bd9Sstevel@tonic-gate 4] Edit the parent Makefile.mach (i.e.: Makefile.sun4c) to know about 2907c478bd9Sstevel@tonic-gate the new module: 2917c478bd9Sstevel@tonic-gate 2927c478bd9Sstevel@tonic-gate FS_KMODS += fd fifo namefs nfs proc spec ufs 2937c478bd9Sstevel@tonic-gate ------ 2947c478bd9Sstevel@tonic-gateAny additional questions can be easily answered by looking at the many 2957c478bd9Sstevel@tonic-gateexisting examples. 2967c478bd9Sstevel@tonic-gate 2977c478bd9Sstevel@tonic-gate 2987c478bd9Sstevel@tonic-gateMoving a Module to the "Implementation Architecture" Independent Build 2997c478bd9Sstevel@tonic-gate---------------------------------------------------------------------- 3007c478bd9Sstevel@tonic-gate 3017c478bd9Sstevel@tonic-gate 1] Create the build directory under the appropriate "instruction 3027c478bd9Sstevel@tonic-gate set architecture" build directory (i.e.: sparc/MODULE). 3037c478bd9Sstevel@tonic-gate 3047c478bd9Sstevel@tonic-gate 2] Move the Makefile from the "implementation architecture" build 3057c478bd9Sstevel@tonic-gate directory (i.e.: sun4c/MODULE) to the directory created above. 3067c478bd9Sstevel@tonic-gate Edit this Makefile to reflect the change of parent (trivial: 3077c478bd9Sstevel@tonic-gate comments, paths and includes). 3087c478bd9Sstevel@tonic-gate 3097c478bd9Sstevel@tonic-gate 3] Edit the "implementation architecture" directory Makefile (i.e.: 3107c478bd9Sstevel@tonic-gate Makefile.sun4c) to *not* know about this module and edit the 3117c478bd9Sstevel@tonic-gate "instruction set architecture" directory Makefile (i.e.: 3127c478bd9Sstevel@tonic-gate Makefile.sparc) to know about it. 3137c478bd9Sstevel@tonic-gate 314