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