1# SPDX-License-Identifier: GPL-2.0 2 3# taken from perf which was based on Linux Kbuild 4# try-cc 5# Usage: option = $(call try-cc, source-to-build, cc-options) 6try-cc = $(shell sh -c \ 7 'TMP="$(BUILD_OUTPUT)$(TMPOUT).$$$$"; \ 8 echo "$(1)" | \ 9 $(CC) -x c - $(2) -o "$$TMP" > /dev/null 2>&1 && echo y; \ 10 rm -f "$$TMP"') 11 12define SOURCE_PTRACE 13#include <stdio.h> 14#include <sys/ptrace.h> 15 16int main (void) 17{ 18 int ret; 19 ret = ptrace(PTRACE_ATTACH, 0, NULL, 0); 20 ptrace(PTRACE_TRACEME, 0, NULL, 0); 21 ptrace(PTRACE_GETSIGINFO, 0, NULL, NULL); 22 ptrace(PTRACE_GETEVENTMSG, 0, NULL, NULL); 23 ptrace(PTRACE_SETOPTIONS, NULL, NULL, 24 PTRACE_O_TRACEFORK | 25 PTRACE_O_TRACEVFORK | 26 PTRACE_O_TRACECLONE | 27 PTRACE_O_TRACEEXIT); 28 ptrace(PTRACE_CONT, NULL, NULL, 0); 29 ptrace(PTRACE_DETACH, 0, NULL, NULL); 30 ptrace(PTRACE_SETOPTIONS, 0, NULL, 31 PTRACE_O_TRACEFORK | 32 PTRACE_O_TRACEVFORK | 33 PTRACE_O_TRACECLONE | 34 PTRACE_O_TRACEEXIT); 35 return ret; 36} 37endef 38 39define SOURCE_AUDIT 40#include <stdio.h> 41#include <libaudit.h> 42 43int main (void) 44{ 45 char *name; 46 int ret; 47 ret = audit_detect_machine(); 48 if (ret < 0) 49 return ret; 50 name = audit_syscall_to_name(1, ret); 51 if (!name) 52 return -1; 53 return ret; 54} 55endef 56