@@ -516,14 +516,18 @@ tasks.whenTaskAdded { task ->
516516 onlyIf {
517517 config. active
518518 }
519+
519520 group = ' build'
520521 description = " Link the ${ config.name} build of the library"
521522 source = fileTree(" $buildDir /obj/main/${ config.name} " )
523+ source. from(file(" ${ projectDir} /build/obj/main/asm/assembly.o" ))
524+
522525 linkedFile = file(" $buildDir /lib/main/${ config.name} /${ osIdentifier()} /${ archIdentifier()} /libjavaProfiler.${ os().isLinux() ? 'so' : 'dylib'} " )
523526 def compileTask = tasks. findByName(" compileLib${ config.name.capitalize()} " . toString())
524527 if (compileTask != null ) {
525528 dependsOn compileTask
526529 }
530+ def asmTask = tasks. findByName(" asm" )
527531 dependsOn asmTask
528532 linkerArgs. addAll(config. linkerArgs)
529533 toolChain = task. toolChain
@@ -605,22 +609,43 @@ tasks.register('javadocJar', Jar) {
605609 from javadoc. destinationDir
606610}
607611
608- tasks. register(' asmTask' , Exec ) {
609- String reportedArch = System . getProperty(' os.arch' )
610- String arch
611- if (reportedArch == ' x86_64' ) {
612+ tasks. register(' asm' , Exec ) {
613+ group = ' build'
614+
615+ def arch
616+ if (archIdentifier() == ' x64' ) {
612617 arch = ' -D__x86_64__'
613618 } else {
614619 arch = ' -D__aarch64__'
615620 }
616621
617- String os
622+ def os
618623 if (osIdentifier() == ' macos' ) {
619624 os = ' -D__APPLE__'
620625 } else {
621626 os = ' -D__LINUX__'
622627 }
623- commandLine ' gcc' , arch, os, ' src/main/assembler/safefetch.S' , ' -c' , ' safefetch.o'
628+ def asmDir = file(" ${ projectDir} /src/main/assembler" )
629+ if (! asmDir. exists()) {
630+ // no assembler files found, skipping
631+ return ;
632+ }
633+
634+ doLast {
635+ // Ensure the output directory exists
636+ file(" ${ projectDir} /build/obj/main/asm" ). mkdirs()
637+ }
638+
639+ // collect all assembler files and compile them
640+ workingDir asmDir
641+ inputs. files fileTree(" ${ projectDir} /src/main/assembler" ) {
642+ include ' **/*.S'
643+ }
644+ def asmFiles = inputs. files. collect { it. absolutePath }
645+ outputs. dir " ${ projectDir} /build/obj/main/asm"
646+ // use gcc to compile assembler files
647+ commandLine ' gcc' , arch, os, ' -c' , ' -x' , ' assembler-with-cpp' ,
648+ * asmFiles, ' -o' , " ${ projectDir} /build/obj/main/asm/assembly.o"
624649}
625650
626651tasks. register(' scanBuild' , Exec ) {
0 commit comments