1rule SetupKernel 2{ 3 # Usage SetupKernel <sources_or_objects> : <extra_cc_flags> : <include_private_headers> ; 4 # 5 # <sources_or_objects> - Ideally sources, otherwise HDRSEARCH can not be 6 # set for the sources and the sources some header 7 # dependencies might be missing. 8 9 local sources = [ FGristFiles $(1) ] ; 10 local objects = $(sources:S=$(SUFOBJ)) ; 11 12 # add private kernel headers 13 if $(3) != false { 14 SourceSysHdrs $(sources) : $(TARGET_PRIVATE_KERNEL_HEADERS) ; 15 } 16 17 local object ; 18 for object in $(objects) { 19 # add kernel flags for the object 20 ObjectCcFlags $(object) : $(TARGET_KERNEL_CCFLAGS) $(2) ; 21 ObjectC++Flags $(object) : $(TARGET_KERNEL_C++FLAGS) $(2) ; 22 ObjectDefines $(object) : $(TARGET_KERNEL_DEFINES) ; 23 24 # override regular CCFLAGS/C++FLAGS, as we don't want them 25 TARGET_CCFLAGS_$(TARGET_PACKAGING_ARCH) on $(object) = ; 26 TARGET_C++FLAGS_$(TARGET_PACKAGING_ARCH) on $(object) = ; 27 28 # override warning flags 29 TARGET_WARNING_CCFLAGS_$(TARGET_PACKAGING_ARCH) on $(object) 30 = $(TARGET_KERNEL_WARNING_CCFLAGS) ; 31 TARGET_WARNING_C++FLAGS_$(TARGET_PACKAGING_ARCH) on $(object) 32 = $(TARGET_KERNEL_WARNING_C++FLAGS) ; 33 } 34} 35 36rule KernelObjects 37{ 38 SetupKernel $(1) : $(2) ; 39 Objects $(1) ; 40} 41 42rule KernelLd 43{ 44 # KernelLd <name> : <objs> : <linkerscript> : <args> ; 45 46 LINK on $(1) = $(TARGET_LD_$(TARGET_PACKAGING_ARCH)) ; 47 48 LINKFLAGS on $(1) = $(4) ; 49 if $(3) { LINKFLAGS on $(1) += --script=$(3) ; } 50 51 # Remove any preset LINKLIBS, but link against libgcc.a. Linking against 52 # libsupc++ is opt-out. 53 local libs ; 54 if ! [ on $(1) return $(HAIKU_NO_LIBSUPC++) ] { 55 libs += [ TargetKernelLibsupc++ true ] ; 56 Depends $(1) : [ TargetKernelLibsupc++ ] ; 57 } 58 LINKLIBS on $(1) = $(libs) [ TargetKernelLibgcc true ] ; 59 Depends $(1) : [ TargetKernelLibgcc ] ; 60 61 HAIKU_TARGET_IS_EXECUTABLE on $(1) = 1 ; 62 63 # TODO: Do we really want to invoke SetupKernel here? The objects should 64 # have been compiled with KernelObjects anyway, so we're doing that twice. 65 SetupKernel $(2) ; 66 67 # Show that we depend on the libraries we need 68 LocalClean clean : $(1) ; 69 LocalDepends all : $(1) ; 70 Depends $(1) : $(2) ; 71 72 MakeLocateDebug $(1) ; 73 74 on $(1) XRes $(1) : $(RESFILES) ; 75 if ! [ on $(1) return $(DONT_USE_BEOS_RULES) ] { 76 SetType $(1) ; 77 MimeSet $(1) ; 78 SetVersion $(1) ; 79 } 80} 81 82actions KernelLd bind VERSION_SCRIPT 83{ 84 $(LINK) $(LINKFLAGS) -o "$(1)" "$(2)" $(LINKLIBS) \ 85 --version-script=$(VERSION_SCRIPT) 86} 87 88rule KernelSo target : source 89{ 90 # KernelSo <target> : <source> 91 92 Depends $(target) : <build>copyattr $(source) ; 93 94 MakeLocateDebug $(1) ; 95 KernelSo1 $(target) : <build>copyattr $(source) ; 96} 97 98actions KernelSo1 99{ 100 export $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) 101 102 $(2[1]) --data $(2[2]) $(1) && 103 $(HAIKU_ELFEDIT_$(TARGET_PACKAGING_ARCH)) --output-type dyn $(1) 104} 105 106rule KernelAddon 107{ 108 # KernelAddon <name> : <sources> : <static-libraries> : <res> ; 109 # 110 local target = $(1) ; 111 local sources = $(2) ; 112 local libs = $(3) ; 113 AddResources $(1) : $(4) ; 114 115 local kernel ; 116 local beginGlue ; 117 local endGlue ; 118 on $(target) { 119 # platform supported? 120 if ! $(PLATFORM) in $(SUPPORTED_PLATFORMS) { 121 return ; 122 } 123 124 # determine which kernel and glue code to link against 125 if $(PLATFORM) = haiku { 126 kernel = <nogrist>kernel.so ; 127 beginGlue = $(HAIKU_KERNEL_ADDON_BEGIN_GLUE_CODE) ; 128 endGlue 129 = [ TargetKernelLibgcc ] $(HAIKU_KERNEL_ADDON_END_GLUE_CODE) ; 130 } else if $(PLATFORM) = haiku_host { 131 kernel = /boot/develop/lib/x86/kernel.so ; 132 beginGlue = $(HAIKU_KERNEL_ADDON_BEGIN_GLUE_CODE) ; 133 endGlue = $(HAIKU_KERNEL_ADDON_END_GLUE_CODE) ; 134 } else { 135 kernel = /boot/develop/lib/x86/_KERNEL_ ; 136 } 137 } 138 139 # add glue code 140 LINK_BEGIN_GLUE on $(target) = $(beginGlue) ; 141 LINK_END_GLUE on $(target) = $(endGlue) ; 142 Depends $(target) : $(beginGlue) $(endGlue) ; 143 144 # compile and link 145 SetupKernel $(sources) : : false ; 146 local linkFlags = -shared -nostdlib -Xlinker --no-undefined 147 -Xlinker -soname=\"$(target:G=)\" $(TARGET_KERNEL_ADDON_LINKFLAGS) ; 148 LINKFLAGS on $(target) = [ on $(target) return $(LINKFLAGS) ] $(linkFlags) ; 149 Main $(target) : $(sources) ; 150 LinkAgainst $(target) : $(libs) $(kernel) ; 151} 152 153rule KernelMergeObject 154{ 155 # KernelMergeObject <name> : <sources> : <extra CFLAGS> : <other objects> ; 156 # Compiles source files and merges the object files to an object file. 157 # <name>: Name of the object file to create. No grist will be added. 158 # <sources>: Sources to be compiled. Grist will be added. 159 # <extra CFLAGS>: Additional flags for compilation. 160 # <other objects>: Object files or static libraries to be merged. No grist 161 # will be added. 162 # 163 164 SetupKernel $(2) : $(3) ; 165 Objects $(2) ; 166 MergeObjectFromObjects $(1) : $(2:S=$(SUFOBJ)) : $(4) ; 167} 168 169rule KernelStaticLibrary 170{ 171 # Usage KernelStaticLibrary <name> : <sources> : <extra cc flags> ; 172 # This is designed to take a set of sources and libraries and create 173 # a static library. 174 175 SetupKernel $(2) : $(3) : false ; 176 Library $(1) : $(2) ; 177} 178 179rule KernelStaticLibraryObjects 180{ 181 # Usage KernelStaticLibrary <name> : <sources> ; 182 # This is designed to take a set of sources and libraries and create 183 # a file called <name> 184 185 # Show that we depend on the libraries we need 186 SetupKernel $(2) ; 187 LocalClean clean : $(1) ; 188 LocalDepends all : $(1) ; 189 Depends $(1) : $(2) ; 190 191 MakeLocateDebug $(1) ; 192} 193 194actions KernelStaticLibraryObjects 195{ 196 # Force recreation of the archive to avoid build errors caused by 197 # stale dependencies after renaming or deleting object files. 198 $(RM) "$(1)" 199 $(HAIKU_AR_$(TARGET_PACKAGING_ARCH)) -r "$(1)" "$(2)" ; 200} 201