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