1338b8dc3SIngo Weinholdrule SetupKernel 2338b8dc3SIngo Weinhold{ 344d56753SJérôme Duval # Usage SetupKernel <sources_or_objects> : <extra_cc_flags> : <include_private_headers> ; 4338b8dc3SIngo Weinhold # 5338b8dc3SIngo Weinhold # <sources_or_objects> - Ideally sources, otherwise HDRSEARCH can not be 6338b8dc3SIngo Weinhold # set for the sources and the sources some header 7338b8dc3SIngo Weinhold # dependencies might be missing. 8338b8dc3SIngo Weinhold 9338b8dc3SIngo Weinhold local sources = [ FGristFiles $(1) ] ; 10338b8dc3SIngo Weinhold local objects = $(sources:S=$(SUFOBJ)) ; 11338b8dc3SIngo Weinhold 12338b8dc3SIngo Weinhold # add private kernel headers 1344d56753SJérôme Duval if $(3) != false { 14338b8dc3SIngo Weinhold SourceSysHdrs $(sources) : $(TARGET_PRIVATE_KERNEL_HEADERS) ; 1544d56753SJérôme Duval } 16338b8dc3SIngo Weinhold 17338b8dc3SIngo Weinhold local object ; 18338b8dc3SIngo Weinhold for object in $(objects) { 197aa55747SAugustin Cavalier TARGET_PACKAGING_ARCH on $(object) = $(TARGET_KERNEL_ARCH) ; 207aa55747SAugustin Cavalier 21338b8dc3SIngo Weinhold # add kernel flags for the object 22338b8dc3SIngo Weinhold ObjectCcFlags $(object) : $(TARGET_KERNEL_CCFLAGS) $(2) ; 23338b8dc3SIngo Weinhold ObjectC++Flags $(object) : $(TARGET_KERNEL_C++FLAGS) $(2) ; 2434b3b26bSIngo Weinhold ObjectDefines $(object) : $(TARGET_KERNEL_DEFINES) ; 25338b8dc3SIngo Weinhold 26df34a271SAugustin Cavalier # override regular CCFLAGS/C++FLAGS, as we don't want them 277aa55747SAugustin Cavalier TARGET_CCFLAGS_$(TARGET_KERNEL_ARCH) on $(object) = ; 287aa55747SAugustin Cavalier TARGET_C++FLAGS_$(TARGET_KERNEL_ARCH) on $(object) = ; 29df34a271SAugustin Cavalier 30338b8dc3SIngo Weinhold # override warning flags 31b0944c78SIngo Weinhold TARGET_WARNING_CCFLAGS_$(TARGET_PACKAGING_ARCH) on $(object) 32b0944c78SIngo Weinhold = $(TARGET_KERNEL_WARNING_CCFLAGS) ; 33b0944c78SIngo Weinhold TARGET_WARNING_C++FLAGS_$(TARGET_PACKAGING_ARCH) on $(object) 34338b8dc3SIngo Weinhold = $(TARGET_KERNEL_WARNING_C++FLAGS) ; 35338b8dc3SIngo Weinhold } 36338b8dc3SIngo Weinhold} 37338b8dc3SIngo Weinhold 38338b8dc3SIngo Weinholdrule KernelObjects 39338b8dc3SIngo Weinhold{ 40338b8dc3SIngo Weinhold SetupKernel $(1) : $(2) ; 41338b8dc3SIngo Weinhold Objects $(1) ; 42338b8dc3SIngo Weinhold} 43338b8dc3SIngo Weinhold 44338b8dc3SIngo Weinholdrule KernelLd 45338b8dc3SIngo Weinhold{ 46338b8dc3SIngo Weinhold # KernelLd <name> : <objs> : <linkerscript> : <args> ; 47338b8dc3SIngo Weinhold 487aa55747SAugustin Cavalier LINK on $(1) = $(TARGET_LD_$(HAIKU_KERNEL_ARCH)) ; 49338b8dc3SIngo Weinhold 50338b8dc3SIngo Weinhold LINKFLAGS on $(1) = $(4) ; 51cc6b376cSPulkoMandy if $(3) { 52cc6b376cSPulkoMandy LINKFLAGS on $(1) += --script=$(3) ; 53cc6b376cSPulkoMandy Depends $(1) : $(3) ; 54cc6b376cSPulkoMandy } 55338b8dc3SIngo Weinhold 56e89f127bSIngo Weinhold # Remove any preset LINKLIBS, but link against libgcc.a. Linking against 57e89f127bSIngo Weinhold # libsupc++ is opt-out. 58e89f127bSIngo Weinhold local libs ; 59bd04aa37SOliver Tappe if ! [ on $(1) return $(HAIKU_NO_LIBSUPC++) ] { 60220d0402SOliver Tappe libs += [ TargetKernelLibsupc++ true ] ; 61220d0402SOliver Tappe Depends $(1) : [ TargetKernelLibsupc++ ] ; 62e89f127bSIngo Weinhold } 63220d0402SOliver Tappe LINKLIBS on $(1) = $(libs) [ TargetKernelLibgcc true ] ; 64220d0402SOliver Tappe Depends $(1) : [ TargetKernelLibgcc ] ; 65338b8dc3SIngo Weinhold 6639d26e3cSFrançois Revol HAIKU_TARGET_IS_EXECUTABLE on $(1) = 1 ; 6739d26e3cSFrançois Revol 68338b8dc3SIngo Weinhold # TODO: Do we really want to invoke SetupKernel here? The objects should 69338b8dc3SIngo Weinhold # have been compiled with KernelObjects anyway, so we're doing that twice. 70338b8dc3SIngo Weinhold SetupKernel $(2) ; 71338b8dc3SIngo Weinhold 72338b8dc3SIngo Weinhold # Show that we depend on the libraries we need 73338b8dc3SIngo Weinhold LocalClean clean : $(1) ; 74338b8dc3SIngo Weinhold LocalDepends all : $(1) ; 75338b8dc3SIngo Weinhold Depends $(1) : $(2) ; 76338b8dc3SIngo Weinhold 77338b8dc3SIngo Weinhold MakeLocateDebug $(1) ; 78cce6f8d0SAxel Dörfler 79cce6f8d0SAxel Dörfler on $(1) XRes $(1) : $(RESFILES) ; 80cce6f8d0SAxel Dörfler if ! [ on $(1) return $(DONT_USE_BEOS_RULES) ] { 81cce6f8d0SAxel Dörfler SetType $(1) ; 82cce6f8d0SAxel Dörfler MimeSet $(1) ; 83cce6f8d0SAxel Dörfler SetVersion $(1) ; 84cce6f8d0SAxel Dörfler } 85338b8dc3SIngo Weinhold} 86338b8dc3SIngo Weinhold 8729782747SIngo Weinholdactions KernelLd bind VERSION_SCRIPT 88338b8dc3SIngo Weinhold{ 8929782747SIngo Weinhold $(LINK) $(LINKFLAGS) -o "$(1)" "$(2)" $(LINKLIBS) \ 9029782747SIngo Weinhold --version-script=$(VERSION_SCRIPT) 91338b8dc3SIngo Weinhold} 92338b8dc3SIngo Weinhold 93385d69fcSAlex Smithrule KernelSo target : source 94385d69fcSAlex Smith{ 95385d69fcSAlex Smith # KernelSo <target> : <source> 96385d69fcSAlex Smith 97385d69fcSAlex Smith Depends $(target) : <build>copyattr $(source) ; 98385d69fcSAlex Smith 99385d69fcSAlex Smith MakeLocateDebug $(1) ; 100385d69fcSAlex Smith KernelSo1 $(target) : <build>copyattr $(source) ; 101385d69fcSAlex Smith} 102385d69fcSAlex Smith 103385d69fcSAlex Smithactions KernelSo1 104385d69fcSAlex Smith{ 105128781e7SAugustin Cavalier export $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) 106385d69fcSAlex Smith 107385d69fcSAlex Smith $(2[1]) --data $(2[2]) $(1) && 1087aa55747SAugustin Cavalier $(HAIKU_ELFEDIT_$(HAIKU_KERNEL_ARCH)) --output-type dyn $(1) 109385d69fcSAlex Smith} 110385d69fcSAlex Smith 111338b8dc3SIngo Weinholdrule KernelAddon 112338b8dc3SIngo Weinhold{ 113c49e0c68SJérôme Duval # KernelAddon <name> : <sources> : <static-libraries> : <res> ; 1142a1f9fe0SIngo Weinhold # 1152a1f9fe0SIngo Weinhold local target = $(1) ; 116c49e0c68SJérôme Duval local sources = $(2) ; 117c49e0c68SJérôme Duval local libs = $(3) ; 118c49e0c68SJérôme Duval AddResources $(1) : $(4) ; 119338b8dc3SIngo Weinhold 1207aa55747SAugustin Cavalier TARGET_PACKAGING_ARCH on $(target) = $(TARGET_KERNEL_ARCH) ; 1217aa55747SAugustin Cavalier 1222a1f9fe0SIngo Weinhold local kernel ; 1232a1f9fe0SIngo Weinhold local beginGlue ; 1242a1f9fe0SIngo Weinhold local endGlue ; 1252a1f9fe0SIngo Weinhold on $(target) { 126338b8dc3SIngo Weinhold # platform supported? 127338b8dc3SIngo Weinhold if ! $(PLATFORM) in $(SUPPORTED_PLATFORMS) { 128338b8dc3SIngo Weinhold return ; 129338b8dc3SIngo Weinhold } 130338b8dc3SIngo Weinhold 1312a1f9fe0SIngo Weinhold # determine which kernel and glue code to link against 1322a1f9fe0SIngo Weinhold if $(PLATFORM) = haiku { 133338b8dc3SIngo Weinhold kernel = <nogrist>kernel.so ; 1342a1f9fe0SIngo Weinhold beginGlue = $(HAIKU_KERNEL_ADDON_BEGIN_GLUE_CODE) ; 135220d0402SOliver Tappe endGlue 136220d0402SOliver Tappe = [ TargetKernelLibgcc ] $(HAIKU_KERNEL_ADDON_END_GLUE_CODE) ; 137da0f9ae0SIngo Weinhold } else if $(PLATFORM) = haiku_host { 138da0f9ae0SIngo Weinhold kernel = /boot/develop/lib/x86/kernel.so ; 139da0f9ae0SIngo Weinhold beginGlue = $(HAIKU_KERNEL_ADDON_BEGIN_GLUE_CODE) ; 140da0f9ae0SIngo Weinhold endGlue = $(HAIKU_KERNEL_ADDON_END_GLUE_CODE) ; 141338b8dc3SIngo Weinhold } else { 142338b8dc3SIngo Weinhold kernel = /boot/develop/lib/x86/_KERNEL_ ; 143338b8dc3SIngo Weinhold } 1442a1f9fe0SIngo Weinhold } 145338b8dc3SIngo Weinhold 1462a1f9fe0SIngo Weinhold # add glue code 1472a1f9fe0SIngo Weinhold LINK_BEGIN_GLUE on $(target) = $(beginGlue) ; 1482a1f9fe0SIngo Weinhold LINK_END_GLUE on $(target) = $(endGlue) ; 1492a1f9fe0SIngo Weinhold Depends $(target) : $(beginGlue) $(endGlue) ; 1502a1f9fe0SIngo Weinhold 1512a1f9fe0SIngo Weinhold # compile and link 152d1246f33SOliver Tappe SetupKernel $(sources) : : false ; 1539e5091d7SSimon South local linkFlags = -shared -nostdlib -Xlinker --no-undefined 154385d69fcSAlex Smith -Xlinker -soname=\"$(target:G=)\" $(TARGET_KERNEL_ADDON_LINKFLAGS) ; 1552a1f9fe0SIngo Weinhold LINKFLAGS on $(target) = [ on $(target) return $(LINKFLAGS) ] $(linkFlags) ; 1562a1f9fe0SIngo Weinhold Main $(target) : $(sources) ; 1572a1f9fe0SIngo Weinhold LinkAgainst $(target) : $(libs) $(kernel) ; 158338b8dc3SIngo Weinhold} 159338b8dc3SIngo Weinhold 160338b8dc3SIngo Weinholdrule KernelMergeObject 161338b8dc3SIngo Weinhold{ 162338b8dc3SIngo Weinhold # KernelMergeObject <name> : <sources> : <extra CFLAGS> : <other objects> ; 163338b8dc3SIngo Weinhold # Compiles source files and merges the object files to an object file. 164338b8dc3SIngo Weinhold # <name>: Name of the object file to create. No grist will be added. 165338b8dc3SIngo Weinhold # <sources>: Sources to be compiled. Grist will be added. 166338b8dc3SIngo Weinhold # <extra CFLAGS>: Additional flags for compilation. 167338b8dc3SIngo Weinhold # <other objects>: Object files or static libraries to be merged. No grist 168338b8dc3SIngo Weinhold # will be added. 169338b8dc3SIngo Weinhold # 170338b8dc3SIngo Weinhold 1717aa55747SAugustin Cavalier TARGET_PACKAGING_ARCH on $(1) = $(TARGET_KERNEL_ARCH) ; 1727aa55747SAugustin Cavalier 173338b8dc3SIngo Weinhold SetupKernel $(2) : $(3) ; 174338b8dc3SIngo Weinhold Objects $(2) ; 175338b8dc3SIngo Weinhold MergeObjectFromObjects $(1) : $(2:S=$(SUFOBJ)) : $(4) ; 176338b8dc3SIngo Weinhold} 177338b8dc3SIngo Weinhold 178338b8dc3SIngo Weinholdrule KernelStaticLibrary 179338b8dc3SIngo Weinhold{ 180*a4d27987SAugustin Cavalier # KernelStaticLibrary <name> : <sources> : <extra cc flags> ; 181338b8dc3SIngo Weinhold # This is designed to take a set of sources and libraries and create 182d0e6e174SIngo Weinhold # a static library. 183*a4d27987SAugustin Cavalier local extraFlags = $(3) ; 184338b8dc3SIngo Weinhold 1857aa55747SAugustin Cavalier TARGET_PACKAGING_ARCH on $(1) = $(TARGET_KERNEL_ARCH) ; 1867aa55747SAugustin Cavalier 187*a4d27987SAugustin Cavalier if $(TARGET_CC_IS_LEGACY_GCC_$(TARGET_KERNEL_ARCH)) = 0 188*a4d27987SAugustin Cavalier && [ on $(1) return $(NO_HIDDEN_VISIBILITY) ] != 1 { 189*a4d27987SAugustin Cavalier extraFlags += -fvisibility=hidden ; 190*a4d27987SAugustin Cavalier } 191*a4d27987SAugustin Cavalier 192*a4d27987SAugustin Cavalier SetupKernel $(2) : $(extraFlags) : false ; 193338b8dc3SIngo Weinhold Library $(1) : $(2) ; 194338b8dc3SIngo Weinhold} 195338b8dc3SIngo Weinhold 196338b8dc3SIngo Weinholdrule KernelStaticLibraryObjects 197338b8dc3SIngo Weinhold{ 198338b8dc3SIngo Weinhold # Usage KernelStaticLibrary <name> : <sources> ; 199338b8dc3SIngo Weinhold # This is designed to take a set of sources and libraries and create 200338b8dc3SIngo Weinhold # a file called <name> 201338b8dc3SIngo Weinhold 2027aa55747SAugustin Cavalier TARGET_PACKAGING_ARCH on $(1) = $(TARGET_KERNEL_ARCH) ; 2037aa55747SAugustin Cavalier 204338b8dc3SIngo Weinhold # Show that we depend on the libraries we need 205338b8dc3SIngo Weinhold SetupKernel $(2) ; 206338b8dc3SIngo Weinhold LocalClean clean : $(1) ; 207338b8dc3SIngo Weinhold LocalDepends all : $(1) ; 208338b8dc3SIngo Weinhold Depends $(1) : $(2) ; 209338b8dc3SIngo Weinhold 210338b8dc3SIngo Weinhold MakeLocateDebug $(1) ; 211338b8dc3SIngo Weinhold} 212338b8dc3SIngo Weinhold 213338b8dc3SIngo Weinholdactions KernelStaticLibraryObjects 214338b8dc3SIngo Weinhold{ 2153f493ef6SMarcus Overhagen # Force recreation of the archive to avoid build errors caused by 2163f493ef6SMarcus Overhagen # stale dependencies after renaming or deleting object files. 2173f493ef6SMarcus Overhagen $(RM) "$(1)" 2187aa55747SAugustin Cavalier $(HAIKU_AR_$(HAIKU_KERNEL_ARCH)) -r "$(1)" "$(2)" ; 219338b8dc3SIngo Weinhold} 220