# rules.library - Host independent rules for making libraries # # Copyright 1984-2005, Wind River Systems, Inc. # # modification history # -------------------- # 03v,22aug05,pee added target name to make depend rules # 03x,05aug05,??? fix for too long expansion # 03w,22jul05,pee cleaned precomp rules. They failed on large paths. # 03v,07jul05,pee added opath target to help find object files. # 02u,31may05,md,pee moved dependencies to object directory # 02t,18apr05,pee added support for precomp objs. # 02s,07apr05,h_a LIB_ROOT to replace $(TGT_DIR)/lib for building components # 02r,04feb05,lei no need a dependency file for "make man" # 02q,14may04,yvp Added LOCAL_RCLEAN rule. # 02p,22mar04,yvp Changed rules for scgen-derived-files to match scgen ver02a. # 02o,13mar04,dlk Support option builds. # 02n,02mar04,yvp Added separate rule to make TGT_DIR/h/syscall.h. # 02m,26feb04,yvp Added copy rules for syscall.h (SPR 93550). # 02l,20feb04,c_c Added BUILD_EXT in ctdt file to allow parallel builds # (SPR 79165). # + merged fix for SPR #93014. # 02k,22jan04,pch SPR 93014: unify build rules for CPUGEN_EXISTS # and remove debug code introduced in 02e. # 02j,16dec03,yvp Ignore error deleting scgen temp files. # 02i,15dec03,yvp Cleanup scgen invocation rules. # 02h,04dec03,yvp Changed options to scgen. # 02g,03dec03,c_c Clean variant directories when invoking rclean. # 02f,07nov03,c_c Unified build rules with WIN32 hosts. # 02e,03nov03,pch don't try to run cpuGen if it does not exist # 02d,10oct03,yvp Added -h (header file only) option to scgen. # 02c,18sep03,yvp Added syscalldeps. # 02b,14feb02,jab use LD_PARTIAL_LAST_FLAGS in last link for .out targets # 02a,14dec01,tam made CPU variant builds automatic # 01z,06dec01,tam added support for building CPU variant archive(s) # 01y,04dec01,sn added BUILD_ALL_OBJS # 01x,12nov01,tam added use of TOOL_COMMON_DIR # 01w,09nov01,tam removed '//' in paths # 01v,08nov01,tam fix x86-win32 build; added build of empty lib$CPU$TOOLvx.a # 01u,01nov01,tam updated rclean rule for new archive directory hierarchy # 01t,19oct01,pch Add rules and dependencies for generation of # target/src/arch/Makefile and target/h/types/vxCpu.h # 01s,01nov01,jab added LIBDIR directory creation # 01r,24oct01,tam updated for repackaging # 01q,23oct01,jab cleaned up # 01p,11oct01,dbs add EXCLUDE_SUBDIRS variable as per AE # 01o,20sep01,dat Moving make files to h/tool/ # 01n,19sep01,mem Prefix $(VX_CPU_FAMILY) to LIBDIRBASE path. # 01m,06aug01,mem Updated for new runtime arrangement. # 01l,25jul01,sn Add per-file CFLAGS capability for C++ files # 01k,24jul01,r_s changing the make 'ifeq' conditional to work with 'gnu', # 'sfgnu', 'sfgnule' etc for TOOL # 01j,24jul01,r_s diab specific rules added # 01j,05jun01,mem Add per-file CFLAGS_AS capability. # 01i,12jan00,dra add per-file CFLAGS capability # 01h,19jan99,dra use LD_PARTIAL_FLAGS for partial links with ctdt.o # 01g,23feb99,sn removed references to $(POST_MUNCH) # -traditional -> -fdollars-in-identifiers # 01f,02feb99,sn added rules to build standalone "munched" C++ modules # (useful for building test programs) # 01e,11dec98,j_w add clean rule to remove lib$(CPU)$(TOOL).a # 01d,11nov98,sn undid 01d # 01c,07nov96,yp made the RM commands in implicit rules windows friendly # 01b,17may96,yp moved clean rule to host specific stubs so Windows will work # 01a,07may96,yp created # # DESCRIPTION # This file is included by every Makefile in the run-time (not BSPs). # This file contains makefile rules that are host independent for creating # vxWorks libraries. It also contains implicit rules for .c .s .cpp and .cxx # files in either the current directory or in $(LIBDIR). # # In each source directory, the list of source files is obtained and matched # against the objects specified to be built in the OBJS macro. In this way # extraneous .c and .s files are ignored and make does not fail if it doesn't # find the source file to an object in OBJS (This is the case with most source # customers). # # The MAKETAIL and CLEANTAIL macros, designed by Sott H. although obsolete # from here on, are still available and known to work only in Unix environments. # # If the macro SUBDIRS is defined with directories we build the subdirectories # before we build the current dir. # # INCLUDES # $(TGT_DIR)/h/make/defs.library # $(TGT_DIR)/h/make/rules-lib.$(WIND_HOST_TYPE) # depend.$(BUILD_EXT) # By default object files are installed in the toolchain independent object # directory if LIB_BASE_NAME is set, that is when LIB_COMMON is not set. include $(TGT_DIR)/h/make/defs.library CPUGEN_EXISTS := $(shell [ -x $(BIN_DIR)/cpuGen ] && echo TRUE) ## implicit rules .s.o : @ $(RM) $@ $(CC) $(CFLAGS_AS) $(CFLAGS_AS_$(<:.s=.o)) $(OPTION_OBJECT_ONLY) $(OPTION_OBJECT_NAME)$@ $< .c.o : @ $(RM) $@ $(CC) $(CFLAGS) $(CFLAGS_$(<:.c=.o)) $(OPTION_OBJECT_ONLY) $< # do not attempt to build dependency on their own. %.d: - @ : # rules to build objects in $(LIBDIR) $(LIBDIR)/%.o : %.c @ $(RM) $@ $(CC) $(CFLAGS) $(OPTION_DEPEND_GEN_D) $(CFLAGS_$(<:.c=.o)) $(OPTION_OBJECT_ONLY) $(OPTION_OBJECT_NAME)$@ $< $(LIBDIR)/%.o : %.s @ $(RM) $@ $(CC) $(CFLAGS_AS) $(OPTION_DEPEND_GEN_D) $(CFLAGS_AS_$(<:.s=.o)) $(OPTION_OBJECT_ONLY) $(OPTION_OBJECT_NAME)$@ $< # rule for munchless C++ compiles $(LIBDIR)/%.o : %.cpp @ $(RM) $@ $(CXX) $(C++FLAGS) $(OPTION_DEPEND_GEN_D) $(CFLAGS_$(<:.cpp=.o)) $(OPTION_OBJECT_ONLY) $(OPTION_OBJECT_NAME)$@ $< ## Rule for standalone "munched" C++ modules. # In general the only library modules that should be munched are # standalone test programs. Certainly nothing in the runtime should be # munched until BSP or Project build time. If you want your # module to be munched, specify a .out target in $(OBJS) instead # of a .o. $(LIBDIR)/%.out : %.cpp @ $(RM) $@ $(CXX) $(C++FLAGS) $(OPTION_OBJECT_ONLY) $(OPTION_OBJECT_NAME) \ $(basename $@).o $< @ $(RM) ctdt_$(BUILD_EXT).c $(NM) $(basename $@).o | $(MUNCH) > ctdt_$(BUILD_EXT).c $(MAKE) CC_COMPILER=$(OPTION_DOLLAR_SYMBOLS) ctdt_$(BUILD_EXT).o $(LD_PARTIAL) $(LD_PARTIAL_LAST_FLAGS) $(OPTION_OBJECT_NAME)$@ $(basename $@).o ctdt_$(BUILD_EXT).o @ $(RM) $(basename $@).o ctdt_$(BUILD_EXT).c ctdt_$(BUILD_EXT).o # rule for munchless C++ compiles .cpp.o : @ $(RM) $@ $(CXX) $(C++FLAGS) $(OPTION_OBJECT_ONLY) $< .cxx.o : @ $(RM) $@ $(CXX) $(C++FLAGS) $(OPTION_OBJECT_ONLY) $< # C++ compile and munch .cpp.out : @ $(RM) $@ $(CXX) $(C++FLAGS) $(OPTION_OBJECT_ONLY) $< @ $(RM) $@ ctdt_$(BUILD_EXT).c $(NM) $*.o | $(MUNCH) > ctdt_$(BUILD_EXT).c $(MAKE) CC_COMPILER=$(OPTION_DOLLAR_SYMBOLS) ctdt_$(BUILD_EXT).o $(LD_PARTIAL) $(LD_PARTIAL_LAST_FLAGS) $(OPTION_OBJECT_NAME)$@ $*.o ctdt_$(BUILD_EXT).o @ $(RM) ctdt_$(BUILD_EXT).c ctdt_$(BUILD_EXT).o .cxx.out : @ $(RM) $@ $(CXX) $(C++FLAGS) $(OPTION_OBJECT_ONLY) $< @ $(RM) $@ ctdt_$(BUILD_EXT).c $(NM) $*.o | $(MUNCH) > ctdt_$(BUILD_EXT).c $(MAKE) CC_COMPILER=$(OPTION_DOLLAR_SYMBOLS) ctdt_$(BUILD_EXT).o $(LD_PARTIAL) $(LD_PARTIAL_LAST_FLAGS) $(OPTION_OBJECT_NAME)$@ $*.o ctdt_$(BUILD_EXT).o @ $(RM) ctdt_$(BUILD_EXT).c ctdt_$(BUILD_EXT).o ## rules to build dependencies in $(LIBDIR) $(LIBDIR)/%.dummy_d : %.c @ $(MKDIR) $(LIBDIR) @ $(RM) $@ $(CC) $(CFLAGS) $(OPTION_DEPEND) $(CFLAGS_$(<:.c=.o)) $(OPTION_OBJECT_ONLY) $(OPTION_DEPEND_TARGET)$(@:.dummy_d=.o) $< >$(@:.dummy_d=.d) $(LIBDIR)/%.dummy_d : %.s @ $(MKDIR) $(LIBDIR) @ $(RM) $@ $(CC) $(CFLAGS_AS) $(OPTION_DEPEND) $(CFLAGS_AS_$(<:.s=.o)) $(OPTION_OBJECT_ONLY) $(OPTION_DEPEND_TARGET)$(@:.dummy_d=.o) $< >$(@:.dummy_d=.d) $(LIBDIR)/%.dummy_d : %.cpp @ $(MKDIR) $(LIBDIR) @ $(RM) $@ $(CXX) $(C++FLAGS) $(OPTION_DEPEND) $(CFLAGS_$(<:.cpp=.o)) $(OPTION_OBJECT_ONLY) $(OPTION_DEPEND_TARGET)$(@:.dummy_d=.o) $< >$(@:.dummy_d=.d) ## rules to construct object lists # vxWorks source distribution do not always have all of the # sources to object files specified in macro OBJS macro. # We use GNU make functions to find what we need to build # get the list of .c, .cpp and .s files FILE_LIST = $(wildcard *.[cs]) $(wildcard *.cpp) $(INDIRECT_SOURCES) # Change .c to .o in FILE_LIST and store in TMP_LIST TMP_LIST = $(FILE_LIST:.c=.o) # Change .cpp to .o in TMP_LIST and store in TMP1_LIST TMP1_LIST = $(TMP_LIST:.cpp=.o) # We can also build .out files from .cpp files TMP2_LIST = $(subst .cpp,.out,(filter %.cpp,$(FILE_LIST))) # Change .s to .o in TMP1_LIST, concat with TMP2_LIST, and store in # OBJ_PRESENT. These are the objects we can build OBJ_PRESENT = $(TMP1_LIST:.s=.o) $(TMP2_LIST) # Find the intersection of the objects we can build and the objects we'd # like to build # Normally we just build objects that can be built from source # files in this directory. However if BUILD_ALL_OBJS is non-empty # then trust the definition of $(OBJS). ifeq ($(BUILD_ALL_OBJS),) OBJS_TO_BUILD = $(filter $(OBJ_PRESENT),$(OBJS)) else OBJS_TO_BUILD = $(OBJS) endif ifneq ($(strip $(OBJS_PRECOMP)),) ifeq ($(OBJS_PRECOMP), $(filter $(OBJ_PRESENT), $(OBJS_PRECOMP))) $(warning sources are available) $(PRECOMPDIR)/%.o : %.c @ $(RM) $@ $(CC) $(CFLAGS) $(CFLAGS_$(<:.c=.o)) $(OPTION_OBJECT_ONLY) $(OPTION_OBJECT_NAME)$@ $< $(PRECOMPDIR)/%.o : %.s @ $(RM) $@ $(CC) $(CFLAGS_AS) $(CFLAGS_AS_$(<:.s=.o)) $(OPTION_OBJECT_ONLY) $(OPTION_OBJECT_NAME)$@ $< # rule for munchless C++ compiles $(PRECOMPDIR)/%.o : %.cpp @ $(RM) $@ $(CXX) $(C++FLAGS) $(CFLAGS_$(<:.cpp=.o)) $(OPTION_OBJECT_ONLY) $(OPTION_OBJECT_NAME)$@ $< endif endif # Now we fix up where they will go once they are built LIBOBJS_FROM_SRC = $(foreach file, $(OBJS_TO_BUILD), $(LIBDIR)/$(file)) LIBOBJS_PRECOMP = $(foreach file, $(OBJS_PRECOMP), $(LIBDIR)/$(file)) LIBOBJS = $(LIBOBJS_FROM_SRC) $(LIBOBJS_PRECOMP) # It is safe to assume that if a subdirectory exists with a Makefile in it # that we want to build it. If this is not the case one needs to over ride # this definition in the Makefile for the directory in concern. # NOTE: to over ride this definition one must define SUBDIRS before the # include directive for this file (rules.library) in the Makefile ifeq ($(SUBDIRS),) ALL_SUBDIRS = $(patsubst %/,%,$(dir $(wildcard */Makefile))) else ALL_SUBDIRS = $(SUBDIRS) endif SUBDIRS_TMP = $(filter-out $(EXCLUDE_SUBDIRS), $(ALL_SUBDIRS)) override SUBDIRS := $(filter-out $(UNSUPPORTED_SUBDIRS), $(SUBDIRS_TMP)) # architecturedb, and files which are generated from it # see the files in $(WIND_BASE)/host/src/cpuGen, # and the comments in architecturedb, for details ARCH_DB = $(WIND_BASE)/host/resource/target/architecturedb ARCH_FILES = $(TGT_DIR)/src/arch/Makefile $(TGT_DIR)/h/types/vxCpu.h ## Default rule: # The default rule builds directories recursively starting from the top level # directory. For every directory, the selected archive is also created and/or # populated with object files. # In addition CPU variant build(s) if enabled for the current CPU/TOOL # combinaison are started at the end of the top level directory build # (target/src/). # An empty lib$(CPU)$(TOOL)vx.a is created by this rule if no # lib$(CPU)$(TOOL)vx.a already exists. VX_LIB = $(wildcard $(LIB_ROOT)/lib$(CPU)$(TOOL)vx.a) ifeq ($(SKIP_LIB), true) LIB_DEP = else LIB_DEP = lib endif ifneq ($(SKIP_DIR), true) Default: archdeps $(SCGEN_DERIVED_FILES) $(LIB_DEP) subdirs ifneq ($(CPU_VARIANT_MAKE_CMD),) ## Check if we are already in a CPU_VARIANT generated build command line, and ## avoid recursion. ifneq ($(NO_RECURSE), TRUE) $(CPU_VARIANT_MAKE_CMD) endif endif ifeq ($(VX_LIB),) $(AR) cru $(LIB_ROOT)/lib$(CPU)$(TOOL)vx.a endif ifneq ($(MAKETAIL),) ($(MAKE) -f Makefile CPU=$(CPU) TOOL=$(TOOL) \ $(MAKETAIL) \ MAKETAIL='') endif else Default: subdirs @echo skipping directory endif ####################################### # # target opath will output a list of object target objects with full path # the rule is implemented so that there is one file per line # and no other blank lines or blank characters. # The output would normally be fed to a linker. The GNU link does not like blanks. # %.opath: @echo $(@:.opath=.o) opath: $(LIBOBJS:.o=.opath) ## recursive clean rule rclean: $(RM) $(LOCAL_RCLEAN) ifneq ($(SUBDIRS),) $(MAKE) CPU=$(CPU) TOOL=$(TOOL) TGT_DIR=$(TGT_DIR) \ TARGET=rclean $(SUBDIRS) endif ifeq ($(SKIP_CLEAN),) ifneq ($(CPU_VARIANT_MAKE_CLEAN),) ## Check if we are already in a CPU_VARIANT generated build command line, and ## avoid recursion. ifneq ($(NO_RECURSE), TRUE) $(CPU_VARIANT_MAKE_CLEAN) endif endif $(MAKE) CPU=$(CPU) TOOL=$(TOOL) TGT_DIR=$(TGT_DIR) clean ifeq ($(CLEANLIBS),YES) $(RM) $(wildcard $(LIB_ROOT)/lib$(CPU)$(TOOL)*.a) $(RM) $(wildcard $(LIB_ROOT)/$(VX_CPU_FAMILY)/$(CPU)/$(TOOL)/lib*$(OPT).a) $(RMDIR) $(wildcard $(LIB_ROOT)/$(VX_CPU_FAMILY)/$(CPU)/$(TOOL)/obj*$(OPT)) $(RM) $(wildcard $(LIB_ROOT)/$(VX_CPU_FAMILY)/$(CPU)/$(TOOL_COMMON_DIR)/lib*$(OPT).a) $(RMDIR) $(wildcard $(LIB_ROOT)/$(VX_CPU_FAMILY)/$(CPU)/$(TOOL_COMMON_DIR)/obj*$(OPT)) $(RMDIR) $(wildcard $(LIB_ROOT)/obj$(CPU)$(TOOL)*) endif endif # ifneq ($(SKIP_CLEAN),) ## recursive depend rule rdepend: ifneq ($(SUBDIRS),) $(MAKE) CPU=$(CPU) TOOL=$(TOOL) TGT_DIR=$(TGT_DIR) \ TARGET=rdepend $(SUBDIRS) endif ifeq ($(SKIP_CLEAN),) ifneq ($(CPU_VARIANT_MAKE_DEPEND),) ## Check if we are already in a CPU_VARIANT generated build command line, and ## avoid recursion. ifneq ($(NO_RECURSE), TRUE) $(CPU_VARIANT_MAKE_DEPEND) endif endif $(MAKE) CPU=$(CPU) TOOL=$(TOOL) TGT_DIR=$(TGT_DIR) depend endif # ifneq ($(SKIP_CLEAN),) # Make sure the object directory exists. ifneq ($(LIBDIR),$(LIB_ROOT)/) MAKE_LIBDIR = make_libdir make_libdir: -$(MKDIR) $(LIBDIR) endif $(LIBDIR) : $(MKDIR) $@ $(PRECOMPDIR) : $(MKDIR) $@ # # This section generates explicit rules to map the precomp objs. # define precompdep $(LIBDIR)/$(1) : $(PRECOMPDIR)/$(1) $(CP) $$? $$@ endef $(eval $(foreach file, $(OBJS_PRECOMP), $(call precompdep,$(file)))) # recursive build of all objects. The hope is that this rule will help # with parallel builds. Calling lib and subdirs with parallel builds # has the adverse effect of trying to create libraries from multiple # subdirectories that tends to destroy the library. all-objs : archdeps $(SCGEN_DERIVED_FILES) objs ifneq ($(SUBDIRS),) $(MAKE) CPU=$(CPU) TOOL=$(TOOL) TGT_DIR=$(TGT_DIR) \ TARGET=all-objs $(SUBDIRS) endif # Just in case you want to build objects and not update the archives objs: archdeps $(SCGEN_DERIVED_FILES) $(MAKE_LIBDIR) $(LIBOBJS) release: archdeps $(SCGEN_DERIVED_FILES) $(MAKE) CPU=$(CPU) TOOL=$(TOOL) TGT_DIR=$(TGT_DIR) \ TARGET=release # Files which are generated from the architecturedb archdeps: $(ARCH_FILES) ifeq ($(CPUGEN_EXISTS),TRUE) $(TGT_DIR)/h/types/vxCpu.h: $(TGT_DIR)/h/types/vxCpu.in $(ARCH_DB) cpuGen -t -i $< -o $@ $(TGT_DIR)/src/arch/Makefile: $(TGT_DIR)/src/arch/Makefile.in $(ARCH_DB) cpuGen -m -i $< -o $@ endif # Files that are generated from syscallNum.def, syscallApi.def etc. # These rules are provided primarily for released products where syscallXP*.def # and syscallUsr*.def may not be shipped by Wind River. These dummy rules will # create a zero-length file so that make should not fail due to missing # dependencies. The intent here is for scgen to parse syscallXPNum.def, # syscallXPApi.def, syscallUsrNum.def and syscallUsrApi.def only if they exist. $(TGT_DIR)/share/h/syscallXPNum.def: touch $@ $(TGT_DIR)/share/h/syscallXPApi.def: touch $@ $(TGT_DIR)/share/h/syscallUsrNum.def: touch $@ $(TGT_DIR)/share/h/syscallUsrApi.def: touch $@ $(TGT_DIR)/h/syscall.h: $(TGT_DIR)/share/h/syscallNum.def \ $(TGT_DIR)/share/h/syscallXPNum.def \ $(TGT_DIR)/share/h/syscallUsrNum.def scgen -h $(TGT_DIR)/h/arch/$(ARCH_DIR)/syscallArgs$(ABI_SPEC).h: \ $(TGT_DIR)/share/h/syscallApi.def \ $(TGT_DIR)/share/h/syscallXPApi.def \ $(TGT_DIR)/share/h/syscallUsrApi.def scgen -A $(ABI_SPEC) $(CPU) $(ARCH_DIR) $(TGT_DIR)/h/syscallTbl.h: $(TGT_DIR)/share/h/syscallNum.def \ $(TGT_DIR)/share/h/syscallXPNum.def \ $(TGT_DIR)/share/h/syscallUsrNum.def \ $(TGT_DIR)/share/h/syscallApi.def \ $(TGT_DIR)/share/h/syscallXPApi.def \ $(TGT_DIR)/share/h/syscallUsrApi.def scgen -t include $(TGT_DIR)/h/make/rules-lib.$(WIND_HOST_TYPE) # we don't need a dependency list if are not building objects # or for "make man" ifeq (, $(findstring clean, $(MAKECMDGOALS))) ifeq (, $(findstring clean, $(TARGET))) ifneq ($(MAKECMDGOALS), man) # We suppress the warning message about non existent file and setting of errno # by prepending - . GNU make allows this. LIBOBJS_NODEP = $(foreach file, $(NODEPENDOBJS), $(LIBDIR)/$(file)) DEP_OBJS = $(filter-out $(LIBOBJS_NODEP), $(LIBOBJS)) EXISTING_OBJS = $(foreach obj, $(DEP_OBJS), $(wildcard $(obj))) DEP_FILES = $(filter %.d , $(EXISTING_OBJS:.o=.d)) EXISTING_DEP_FILES = $(foreach obj, $(DEP_FILES), $(wildcard $(obj))) MISSING_DEP = $(filter-out $(EXISTING_DEP_FILES), $(DEP_FILES)) ifneq ($(strip $(MISSING_DEP)),) $(warning warning: missing dependency files $(MISSING_DEP)) $(warning run make depend to regenerate) endif ifneq ($(strip $(EXISTING_DEP_FILES)),) include $(EXISTING_DEP_FILES) endif endif endif endif