1 #
   2 # CDDL HEADER START
   3 #
   4 # The contents of this file are subject to the terms of the
   5 # Common Development and Distribution License (the "License").
   6 # You may not use this file except in compliance with the License.
   7 #
   8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9 # or http://www.opensolaris.org/os/licensing.
  10 # See the License for the specific language governing permissions
  11 # and limitations under the License.
  12 #
  13 # When distributing Covered Code, include this CDDL HEADER in each
  14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15 # If applicable, add the following below this CDDL HEADER, with the
  16 # fields enclosed by brackets "[]" replaced with your own identifying
  17 # information: Portions Copyright [yyyy] [name of copyright owner]
  18 #
  19 # CDDL HEADER END
  20 #
  21 #
  22 # Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
  23 # Copyright 2015, Joyent, Inc.
  24 # Copyright 2014 Garrett D'Amore <garrett@damore.org>
  25 # Copyright 2016 Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
  26 # Copyright (c) 2017 by Delphix. All rights reserved.
  27 #
  28 #       This Makefiles contains the common targets and definitions for
  29 #       all kernels. It is to be included in the Makefiles for specific
  30 #       implementation architectures and processor architecture dependent
  31 #       modules: i.e.: all driving kernel Makefiles.
  32 #
  33 
  34 #
  35 #       Default rule for building the lint library directory:
  36 #
  37 $(LINT_LIB_DIR):
  38         -@mkdir -p $@ 2> /dev/null
  39 
  40 #
  41 #       All C objects depend on inline files. However, cc(1) doesn't generate
  42 #       the correct dependency info. Also, these Makefiles don't contain a
  43 #       separate list of C-derived object files (but it is light weight to
  44 #       let the assembler files think they depend upon this when they don't).
  45 #       Fortunately, the inline files won't change very often. So, for now,
  46 #       all objects depend on the inline files. Remove this when the inliner
  47 #       is fixed to drop correct dependency information.
  48 #
  49 $(OBJECTS): $(INLINES)
  50 
  51 #
  52 #       Partially link .o files to generate the kmod. The fake dependency
  53 #       on modstubs simplifies things...
  54 #
  55 $(BINARY):              $(OBJECTS) $(DTRACE_MAPFILE)
  56         $(LD) -r $(LDFLAGS) -o $@ $(OBJECTS)
  57         $(CTFMERGE_UNIQUIFY_AGAINST_GENUNIX)
  58         $(POST_PROCESS)
  59 
  60 #
  61 #       This target checks each kmod for undefined entry points. It does not
  62 #       modify the kmod in any way.
  63 #
  64 $(MODULE).check:        FRC
  65         @BUILD_TYPE=DBG32 $(MAKE) $(MODULE).check.targ
  66 
  67 $(MODULE).check.targ:   $(BINARY) $(OBJECTS) $(EXTRA_CHECK_OBJS) $(UNIX_O) $(MODSTUBS_O) $(GENLIB)
  68         $(LD) -o /dev/null $(OBJECTS) $(EXTRA_CHECK_OBJS) $(UNIX_O) $(MODSTUBS_O) $(GENLIB)
  69 
  70 #
  71 #       Module lint library construction targets.
  72 #
  73 MOD_LINT_LIB    = $(LINT_LIB_DIR)/llib-l$(LINT_MODULE).ln
  74 
  75 $(MOD_LINT_LIB):        $(LINT_LIB_DIR) $(LINTS)
  76         @-$(ECHO) "\n$(OBJS_DIR)/$(MODULE): (library construction):"
  77         @($(LINT) -o $(LINT_MODULE)-$(OBJS_DIR) \
  78                 $(LINTFLAGS) $(LINTS) $(LTAIL))
  79         @$(MV) llib-l$(LINT_MODULE)-$(OBJS_DIR).ln $@
  80 
  81 $(LINT_MODULE).lint:    $(MOD_LINT_LIB) $(LINT_LIB) $(GEN_LINT_LIB)
  82         @-$(ECHO) "\n$(OBJS_DIR)/$(LINT_MODULE): global crosschecks:"
  83         @($(LINT) $(LINTFLAGS) $(MOD_LINT_LIB) \
  84                 $(LINT_LIB) $(GEN_LINT_LIB) $(LTAIL))
  85 
  86 #
  87 # Since assym.h is a derived file, the dependency must be explicit for
  88 # all files including this file. (This is only actually required in the
  89 # instance when the .nse_depinfo file does not exist.) It may seem that
  90 # the lint targets should also have a similar dependency, but they don't
  91 # since only C headers are included when #defined(lint) is true. The
  92 # actual lists are defined in */Makefile.files.
  93 #
  94 $(ASSYM_DEPS:%=$(OBJS_DIR)/%):  $(DSF_DIR)/$(OBJS_DIR)/assym.h
  95 
  96 #
  97 #       Everybody need to know how to create a modstubs.o built with the
  98 #       appropriate flags and located in the appropriate location.
  99 #
 100 $(MODSTUBS_O):  $(MODSTUBS)
 101         $(COMPILE.s) -o $@ $(MODSTUBS)
 102 
 103 $(LINTS_DIR)/modstubs.ln:       $(MODSTUBS)
 104         @($(LHEAD) $(LINT.s) $(MODSTUBS) $(LTAIL))
 105 
 106 #
 107 # Build the source file which contains the kernel's utsname,
 108 # with release, version and machine set as follows:
 109 #
 110 #       release: contents of $(RELEASE) (Spaces replaced by '_')
 111 #       version: contents of $(PATCHID) (Spaces replaced by '_')
 112 #       machine: contents of $(UNAME_M)
 113 #
 114 # Build environment information is only contained in the comment section.
 115 #
 116 
 117 $(OBJS_DIR)/vers.o: $(OBJECTS)
 118         $(COMPILE.c) -DUTS_RELEASE=\"`$(ECHO) $(RELEASE) | sed -e 's/ /_/g'`\" \
 119             -DUTS_VERSION=\"`$(ECHO) $(PATCHID) | sed -e 's/ /_/g'`\" \
 120             -DUTS_PLATFORM=\"$(UNAME_M)\" -o $@ $(SRC)/uts/common/os/vers.c
 121         $(CTFCONVERT_O)
 122         $(POST_PROCESS_O)
 123 
 124 $(LINTS_DIR)/vers.ln: $(SRC)/uts/common/os/vers.c
 125         @($(LHEAD) $(LINT.c) -DUTS_RELEASE=\"\" -DUTS_VERSION=\"\" \
 126             -DUTS_PLATFORM=\"\" $(SRC)/uts/common/os/vers.c $(LTAIL))
 127 
 128 #
 129 #       Installation targets and rules:
 130 #
 131 $(ROOT_MOD_DIR) $(USR_MOD_DIR):
 132         -$(INS.dir)
 133 
 134 $(ROOT_MOD_DIRS_32):    $(ROOT_MOD_DIR)
 135         -$(INS.dir)
 136 
 137 $(USR_MOD_DIRS_32):     $(USR_MOD_DIR)
 138         -$(INS.dir)
 139 
 140 $(ROOT_MOD_DIR)/%:      $(OBJS_DIR)/% $(ROOT_MOD_DIR) FRC
 141         $(INS.file)
 142 
 143 $(ROOT_CPU_DIR)/%:      $(OBJS_DIR)/% $(ROOT_CPU_DIR) FRC
 144         $(INS.file)
 145 
 146 $(ROOT_DRV_DIR)/%:      $(OBJS_DIR)/% $(ROOT_DRV_DIR) FRC
 147         $(INS.file)
 148 
 149 $(ROOT_DTRACE_DIR)/%:   $(OBJS_DIR)/% $(ROOT_DTRACE_DIR) FRC
 150         $(INS.file)
 151 
 152 $(ROOT_EXEC_DIR)/%:     $(OBJS_DIR)/% $(ROOT_EXEC_DIR) FRC
 153         $(INS.file)
 154 
 155 $(ROOT_FS_DIR)/%:       $(OBJS_DIR)/% $(ROOT_FS_DIR) FRC
 156         $(INS.file)
 157 
 158 $(ROOT_SCHED_DIR)/%:    $(OBJS_DIR)/% $(ROOT_SCHED_DIR) FRC
 159         $(INS.file)
 160 
 161 $(ROOT_SOCK_DIR)/%:     $(OBJS_DIR)/% $(ROOT_SOCK_DIR) FRC
 162         $(INS.file)
 163 
 164 $(ROOT_STRMOD_DIR)/%:   $(OBJS_DIR)/% $(ROOT_STRMOD_DIR) FRC
 165         $(INS.file)
 166 
 167 $(ROOT_IPP_DIR)/%:      $(OBJS_DIR)/% $(ROOT_IPP_DIR) FRC
 168         $(INS.file)
 169 
 170 $(ROOT_SYS_DIR)/%:      $(OBJS_DIR)/% $(ROOT_SYS_DIR) FRC
 171         $(INS.file)
 172 
 173 $(ROOT_MISC_DIR)/%:     $(OBJS_DIR)/% $(ROOT_MISC_DIR) FRC
 174         $(INS.file)
 175 
 176 $(ROOT_DACF_DIR)/%:     $(OBJS_DIR)/% $(ROOT_DACF_DIR) FRC
 177         $(INS.file)
 178 
 179 $(ROOT_BRAND_DIR)/%:    $(OBJS_DIR)/% $(ROOT_BRAND_DIR) FRC
 180         $(INS.file)
 181 
 182 $(ROOT_CC_DIR)/%:       $(OBJS_DIR)/% $(ROOT_MOD_DIR) $(ROOT_CC_DIR) FRC
 183         $(INS.file)
 184 
 185 $(ROOT_CRYPTO_DIR)/%:   $(OBJS_DIR)/% $(ROOT_CRYPTO_DIR) FRC
 186         $(INS.file)
 187 
 188 $(ROOT_KGSS_DIR)/%:     $(OBJS_DIR)/% $(ROOT_KGSS_DIR) FRC
 189         $(INS.file)
 190 
 191 $(ROOT_SCSI_VHCI_DIR)/%: $(OBJS_DIR)/% $(ROOT_SCSI_VHCI_DIR) FRC
 192         $(INS.file)
 193 
 194 $(ROOT_PMCS_FW_DIR)/%:  $(OBJS_DIR)/% $(ROOT_PMCS_FW_DIR) FRC
 195         $(INS.file)
 196 
 197 $(ROOT_QLC_FW_DIR)/%:   $(OBJS_DIR)/% $(ROOT_QLC_FW_DIR) FRC
 198         $(INS.file)
 199 
 200 $(ROOT_EMLXS_FW_DIR)/%: $(OBJS_DIR)/% $(ROOT_EMLXS_FW_DIR) FRC
 201         $(INS.file)
 202 
 203 $(ROOT_MACH_DIR)/%:     $(OBJS_DIR)/% $(ROOT_MACH_DIR) FRC
 204         $(INS.file)
 205 
 206 $(ROOT_FONT_DIR)/%:     $(OBJS_DIR)/% $(ROOT_MOD_DIR) $(ROOT_FONT_DIR) FRC
 207         $(INS.file)
 208 
 209 $(ROOT_MAC_DIR)/%:      $(OBJS_DIR)/% $(ROOT_MOD_DIR) $(ROOT_MAC_DIR) FRC
 210         $(INS.file)
 211 
 212 $(ROOT_OVERLAY_DIR)/%:  $(OBJS_DIR)/% $(ROOT_MOD_DIR) $(ROOT_OVERLAY_DIR) FRC
 213         $(INS.file)
 214 
 215 $(USR_DRV_DIR)/%:       $(OBJS_DIR)/% $(USR_DRV_DIR) FRC
 216         $(INS.file)
 217 
 218 $(USR_EXEC_DIR)/%:      $(OBJS_DIR)/% $(USR_EXEC_DIR) FRC
 219         $(INS.file)
 220 
 221 $(USR_FS_DIR)/%:        $(OBJS_DIR)/% $(USR_FS_DIR) FRC
 222         $(INS.file)
 223 
 224 $(USR_SCHED_DIR)/%:     $(OBJS_DIR)/% $(USR_SCHED_DIR) FRC
 225         $(INS.file)
 226 
 227 $(USR_SOCK_DIR)/%:      $(OBJS_DIR)/% $(USR_SOCK_DIR) FRC
 228         $(INS.file)
 229 
 230 $(USR_STRMOD_DIR)/%:    $(OBJS_DIR)/% $(USR_STRMOD_DIR) FRC
 231         $(INS.file)
 232 
 233 $(USR_SYS_DIR)/%:       $(OBJS_DIR)/% $(USR_SYS_DIR) FRC
 234         $(INS.file)
 235 
 236 $(USR_MISC_DIR)/%:      $(OBJS_DIR)/% $(USR_MISC_DIR) FRC
 237         $(INS.file)
 238 
 239 $(USR_DACF_DIR)/%:      $(OBJS_DIR)/% $(USR_DACF_DIR) FRC
 240         $(INS.file)
 241 
 242 $(USR_PCBE_DIR)/%:      $(OBJS_DIR)/% $(USR_PCBE_DIR) FRC
 243         $(INS.file)
 244 
 245 $(USR_DTRACE_DIR)/%:    $(OBJS_DIR)/% $(USR_DTRACE_DIR) FRC
 246         $(INS.file)
 247 
 248 $(USR_BRAND_DIR)/%:     $(OBJS_DIR)/% $(USR_BRAND_DIR) FRC
 249         $(INS.file)
 250 
 251 $(ROOT_KICONV_DIR)/%:   $(OBJS_DIR)/% $(ROOT_KICONV_DIR) FRC
 252         $(INS.file)
 253 
 254 $(ROOT_FIRMWARE_DIR)/$(MODULE):
 255         $(INS.dir)
 256 
 257 $(ROOT_FIRMWARE_DIR)/$(MODULE)/%:= FILEMODE = $(CFILEMODE)
 258 
 259 $(ROOT_FIRMWARE_DIR)/$(MODULE)/%: $(ROOT_FIRMWARE_DIR)/$(MODULE) $(FWDIR)/%
 260         $(INS.file)
 261 
 262 include $(SRC)/Makefile.psm.targ
 263 
 264 #
 265 #       Target for 64b modules
 266 #
 267 $(ROOT_KERN_DIR_64):
 268         -$(INS.dir)
 269 
 270 $(ROOT_KERN_DIR_64)/%:  $(OBJS_DIR)/% $(ROOT_KERN_DIR_64) FRC
 271         $(INS.file)
 272 
 273 %/$(SUBDIR64):          %
 274         -$(INS.dir)
 275 
 276 #
 277 #       Targets for '.conf' file installation.
 278 #
 279 $(ROOT_CONFFILE):       $(SRC_CONFFILE) $(ROOT_CONFFILE:%/$(CONFFILE)=%)
 280         $(INS.conffile)
 281 
 282 #
 283 #       Targets for creating links between common platforms. ROOT_PLAT_LINKS
 284 #       are are the /platform level while ROOT_PLAT_LINKS_2 are one level
 285 #       down (/platform/`uname -i`/{lib|sbin|kernel}.
 286 #
 287 $(ROOT_PLAT_LINKS):
 288         $(INS.slink1)
 289 
 290 $(ROOT_PLAT_LINKS_2):
 291         $(INS.slink2)
 292 
 293 $(USR_PLAT_LINKS):
 294         $(INS.slink1)
 295 
 296 $(USR_PLAT_LINKS_2):
 297         $(INS.slink2)
 298 
 299 #
 300 # multiple builds support
 301 #
 302 def $(DEF_DEPS)                 := TARGET = def
 303 all $(ALL_DEPS)                 := TARGET = all
 304 clean $(CLEAN_DEPS)             := TARGET = clean
 305 clobber $(CLOBBER_DEPS)         := TARGET = clobber
 306 lint $(LINT_DEPS)               := TARGET = lint
 307 modlintlib $(MODLINTLIB_DEPS)   := TARGET = modlintlib
 308 modlist $(MODLIST_DEPS)         := TARGET = modlist
 309 modlist $(MODLIST_DEPS)         := NO_STATE= -K $$MODSTATE$$$$
 310 clean.lint $(CLEAN_LINT_DEPS)   := TARGET = clean.lint
 311 install $(INSTALL_DEPS)         := TARGET = install
 312 symcheck $(SYM_DEPS)            := TARGET = symcheck
 313 
 314 ALL_TARGS       = def all clean clobber lint modlintlib \
 315                   clean.lint lintlib install symcheck
 316 
 317 ALL_OBJ64       = $(ALL_TARGS:%=%.obj64)
 318 
 319 $(ALL_OBJ64):   FRC
 320         @BUILD_TYPE=OBJ64 VERSION='$(VERSION)' $(MAKE) $(NO_STATE) $(TARGET).targ
 321 
 322 ALL_DEBUG64     = $(ALL_TARGS:%=%.debug64)
 323 
 324 $(ALL_DEBUG64): FRC
 325         @BUILD_TYPE=DBG64 VERSION='$(VERSION)' $(MAKE) $(NO_STATE) $(TARGET).targ
 326 
 327 #
 328 #       Currently only the IP module needs symbol checking on obj64.
 329 #       Other modules have the same global-objs nm output for debug64 and obj64.
 330 #
 331 $(SISCHECK_DEPS):       $(DEF_DEPS)
 332         @TARG=`$(ECHO) $@ | $(CUT) -d'.' -f2`; \
 333         MODSYMS=$(MODULE).symbols.$$TARG; \
 334         if [ -f "$(MODULE).global-objs.$$TARG" ]; then \
 335                 $(GREP) -v '#' $(MODULE).global-objs.$$TARG |$(GREP) . | \
 336                     $(SORT) -u > $$MODSYMS.tmp; \
 337                 $(NM) $$TARG/$(MODULE) |$(GREP) OBJT |$(GREP) -v UNDEF | \
 338                     $(CUT) -d'|' -f8 |$(GREP) -v '^___const_' | \
 339                     $(GREP) -v '\.[0-9]*$$' |$(SORT) -u \
 340                     > $$MODSYMS.tmp.new; \
 341                 $(DIFF) $$MODSYMS.tmp $$MODSYMS.tmp.new > $$MODSYMS.diff || \
 342                     ($(ECHO) "warning: $(MODULE) symbol checking:" \
 343                     "global variable(s) introduced and/or removed."; \
 344                     $(CAT) $$MODSYMS.diff; exit 1) \
 345         fi
 346 
 347 $(SISCLEAN_DEPS):
 348         -TARG=`$(ECHO) $@ | $(CUT) -d'.' -f2`; \
 349         MODSYMS=$(MODULE).symbols.$$TARG; \
 350         $(RM) $$MODSYMS.tmp $$MODSYMS.tmp.new $$MODSYMS.diff Nothing_to_remove
 351 
 352 
 353 $(OBJS_DIR):
 354         -@mkdir -p $@ 2> /dev/null
 355 
 356 def.targ:               $(OBJS_DIR) $(ALL_TARGET)
 357 
 358 all.targ:               $(OBJS_DIR) $(ALL_TARGET)
 359 
 360 lint.targ:              $(OBJS_DIR) $(LINT_TARGET)
 361 
 362 modlintlib.targ:        $(OBJS_DIR) $(MOD_LINT_LIB)
 363 
 364 install.targ:           $(OBJS_DIR) $(INSTALL_TARGET)
 365 
 366 #
 367 # Support for Install.sh.
 368 #
 369 
 370 modlist:        $(MODLIST_DEPS)
 371 
 372 # paths relative to $(ROOT).
 373 RELMODULE = $(ROOTMODULE:$(ROOT)/%=%)
 374 RELCONF = $(ROOT_CONFFILE:$(ROOT)/%=%)
 375 RELLINK = $(ROOTLINK:$(ROOT)/%=%)
 376 RELUNIX = $(UNIX32_LINK:$(ROOT)/%=%)
 377 RELSOFTLINKS = $(ROOTSOFTLINKS:$(ROOT)/%=%)
 378 
 379 MODSRC:sh=              pwd
 380 
 381 #
 382 # Generate module information for Install.sh, i.e., specify what files
 383 # Install.sh should include.  Each line looks like
 384 #   <tag> <srcdir> <arg1> <arg2> ...
 385 # where <tag> specifies the type of file, <srcdir> gives the source
 386 # path (useful if there is an error), and <argN> is one or more
 387 # additional bits of information that Install.sh needs (e.g., source
 388 # directory, install directory, filtering tags).  See Install.sh for
 389 # details on the arguments for each tag type, especially the functions
 390 # copymod, filtmod, and filtimpl.
 391 #
 392 # Changes to this target may require corresponding changes to
 393 # Install.sh.
 394 #
 395 # Don't issue a MOD entry if it's not in the install list.
 396 #
 397 
 398 $(MODLIST_DEPS): FRC
 399         @case $@ in \
 400         *32) \
 401                 class=32; \
 402                 [ -n "$(RELMODULE)" ] && relmodule=`dirname $(RELMODULE)`;; \
 403         *64) \
 404                 class=64; \
 405                 [ -n "$(RELMODULE)" ] && \
 406                     relmodule=`dirname $(RELMODULE)`/$(SUBDIR64);; \
 407         esac; \
 408         if [ -z "$(THISIMPL)" ]; then \
 409                 impl=all; \
 410         else \
 411                 impl=$(THISIMPL); \
 412         fi; \
 413         if [ -n "$(ROOTMODULE)" -a -n "$(INSTALL_TARGET)" ]; then \
 414                 if [ -z "$(MODULE)" ]; then \
 415                         module=`basename $(ROOTMODULE)`; \
 416                 else \
 417                         module=$(MODULE); \
 418                 fi; \
 419                 tinstall="$(INSTALL_TARGET)"; \
 420                 for t in $$tinstall; do \
 421                         if [ "$(ROOTMODULE)" = $$t ]; then \
 422                                 echo MOD $(MODSRC) $$module $$relmodule \
 423                                     $$class $$impl; \
 424                                 break; \
 425                         fi \
 426                 done \
 427         fi; \
 428         if [ -n "$(CONF_SRCDIR)" ]; then \
 429                 tinstall="$(INSTALL_TARGET)"; \
 430                 for t in $$tinstall; do \
 431                         if [ $(ROOT_CONFFILE) = $$t ]; then \
 432                                 echo CONF $(MODSRC) $(RELCONF) \
 433                                     $(MODSRC)/$(CONF_SRCDIR) $$impl $$module; \
 434                                 break; \
 435                         fi \
 436                 done \
 437         fi; \
 438         if [ -n "$(ROOTLINK)" ]; then \
 439                 rellinks="$(RELLINK)"; \
 440                 for r in $$rellinks; do \
 441                         if [ $$class = 32 ]; then \
 442                                 linkdir=`dirname $$r`; \
 443                         else \
 444                                 linkdir=`dirname $$r`/$(SUBDIR64); \
 445                         fi; \
 446                         echo LINK $(MODSRC) $$relmodule $$module \
 447                                 $$linkdir `basename $$r` $$impl; \
 448                 done \
 449         fi; \
 450         if [ -n "$(UNIX32_LINK)" ]; then \
 451                 echo SYMLINK $(MODSRC) $(SUBDIR64)/$(UNIX) \
 452                     `dirname $(RELUNIX)` unix $$impl $$module; \
 453         fi; \
 454         trelsoftlinks="$(RELSOFTLINKS)"; \
 455         for t in $$trelsoftlinks; do \
 456                 if [ $$class = 32 ]; then \
 457                         linkdir=`dirname $$t`; \
 458                 else \
 459                         linkdir=`dirname $$t`/$(SUBDIR64); \
 460                 fi; \
 461                 linkname=`basename $$t`; \
 462                 echo SYMLINK $(MODSRC) $(MODULE) $$linkdir $$linkname \
 463                     $$impl $$module; \
 464         done
 465 
 466 #
 467 #       Cleanliness is next to ...
 468 #
 469 clean.targ:
 470         -$(RM) $(CLEANFILES) Nothing_to_remove
 471 
 472 clobber.targ:
 473         -$(RM) $(CLOBBERFILES) Nothing_to_remove
 474 
 475 clean.lint.targ:
 476         -$(RM) $(CLEANLINTFILES) Nothing_to_remove
 477 
 478 #
 479 #       Create fake lintlibs in the 64b dirs so
 480 #       global linting works
 481 #
 482 lint64:
 483         @$(ECHO) $(MODULE) fake lints
 484         @for dir in $(LINT64_DIRS); do \
 485                 if [ ! -d $$dir ]; then mkdir $$dir; fi \
 486         done
 487         @for file in $(LINT64_FILES); do \
 488                 if [ ! -f $$file ]; then touch $$file; fi \
 489         done
 490 
 491 FRC: