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