1# Copyright (C) 1995-2022 Free Software Foundation, Inc.
2# This file is part of the GNU C Library.
3
4# The GNU C Library is free software; you can redistribute it and/or
5# modify it under the terms of the GNU Lesser General Public
6# License as published by the Free Software Foundation; either
7# version 2.1 of the License, or (at your option) any later version.
8
9# The GNU C Library is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12# Lesser General Public License for more details.
13
14# You should have received a copy of the GNU Lesser General Public
15# License along with the GNU C Library; if not, see
16# <https://www.gnu.org/licenses/>.
17
18#
19#	Sub-makefile for gmon portion of the library.
20#
21subdir	:= gmon
22
23include ../Makeconfig
24
25headers	:= sys/gmon.h sys/gmon_out.h sys/profil.h
26routines := gmon mcount profil sprofil prof-freq
27
28tests	= tst-sprofil tst-gmon
29ifeq ($(build-profile),yes)
30tests	+= tst-profile-static
31tests-static	+= tst-profile-static
32
33LDFLAGS-tst-profile-static = -profile
34endif
35
36tests += tst-gmon-static
37tests-static += tst-gmon-static
38
39ifeq (yesyes,$(have-fpie)$(build-shared))
40tests += tst-gmon-pie
41tests-pie += tst-gmon-pie
42ifeq (yes,$(enable-static-pie))
43tests += tst-gmon-static-pie
44tests-static += tst-gmon-static-pie
45endif
46endif
47
48# The mcount code won't work without a frame pointer.
49CFLAGS-mcount.c := -fno-omit-frame-pointer
50
51CFLAGS-tst-gmon.c := -fno-omit-frame-pointer -pg
52tst-gmon-no-pie = yes
53CRT-tst-gmon := $(csu-objpfx)g$(start-installed-name)
54tst-gmon-ENV := GMON_OUT_PREFIX=$(objpfx)tst-gmon.data
55ifeq ($(run-built-tests),yes)
56tests-special += $(objpfx)tst-gmon-gprof.out
57endif
58
59CFLAGS-tst-gmon-static.c := $(PIE-ccflag) -fno-omit-frame-pointer -pg
60CRT-tst-gmon-static := $(csu-objpfx)g$(static-start-installed-name)
61tst-gmon-static-no-pie = yes
62tst-gmon-static-ENV := GMON_OUT_PREFIX=$(objpfx)tst-gmon-static.data
63ifeq ($(run-built-tests),yes)
64tests-special += $(objpfx)tst-gmon-static-gprof.out
65endif
66
67CFLAGS-tst-gmon-pie.c := $(PIE-ccflag) -fno-omit-frame-pointer -pg
68CRT-tst-gmon-pie := $(csu-objpfx)g$(start-installed-name)
69tst-gmon-pie-ENV := GMON_OUT_PREFIX=$(objpfx)tst-gmon-pie.data
70ifeq ($(run-built-tests),yes)
71tests-special += $(objpfx)tst-gmon-pie-gprof.out
72endif
73
74ifeq (yes,$(enable-static-pie))
75CFLAGS-tst-gmon-static-pie.c := $(PIE-ccflag) -fno-omit-frame-pointer -pg
76CRT-tst-gmon-static-pie := $(csu-objpfx)gr$(static-start-installed-name)
77tst-gmon-static-pie-ENV := GMON_OUT_PREFIX=$(objpfx)tst-gmon-static-pie.data
78ifeq ($(run-built-tests),yes)
79tests-special += $(objpfx)tst-gmon-static-pie-gprof.out
80endif
81endif
82
83
84include ../Rules
85
86# We cannot compile mcount.c with -pg because that would
87# create recursive calls.  Just copy the normal static object.
88# On systems where `profil' is not a system call, the same
89# problem exists for the internal functions in profil.c.
90
91noprof := mcount $(sysdep_noprof)
92ifeq (,$(filter profil,$(unix-syscalls)))
93noprof += profil sprofil
94endif
95
96$(noprof:%=$(objpfx)%.op): %.op: %.o
97	rm -f $@
98	ln $< $@
99
100# GMON_OUTPUT_PREFIX only sets the output prefix.  The actual file
101# name contains the PID as well.
102$(objpfx)tst-gmon.out: clean-tst-gmon-data
103clean-tst-gmon-data:
104	rm -f $(objpfx)tst-gmon.data.*
105
106$(objpfx)tst-gmon-gprof.out: tst-gmon-gprof.sh $(objpfx)tst-gmon.out
107	$(SHELL) $< $(GPROF) $(objpfx)tst-gmon $(objpfx)tst-gmon.data.* > $@; \
108	$(evaluate-test)
109
110$(objpfx)tst-gmon-static.out: clean-tst-gmon-static-data
111clean-tst-gmon-static-data:
112	rm -f $(objpfx)tst-gmon-static.data.*
113
114$(objpfx)tst-gmon-static-gprof.out: tst-gmon-static-gprof.sh \
115				    $(objpfx)tst-gmon-static.out
116	$(SHELL) $< $(GPROF) $(objpfx)tst-gmon-static \
117		$(objpfx)tst-gmon-static.data.* > $@; \
118	$(evaluate-test)
119
120$(objpfx)tst-gmon-pie.out: clean-tst-gmon-pie-data
121clean-tst-gmon-pie-data:
122	rm -f $(objpfx)tst-gmon-pie.data.*
123
124$(objpfx)tst-gmon-pie-gprof.out: tst-gmon-gprof.sh $(objpfx)tst-gmon-pie.out
125	$(SHELL) $< $(GPROF) $(objpfx)tst-gmon-pie $(objpfx)tst-gmon-pie.data.* > $@; \
126	$(evaluate-test)
127
128$(objpfx)tst-gmon-static-pie.out: clean-tst-gmon-static-pie-data
129clean-tst-gmon-static-pie-data:
130	rm -f $(objpfx)tst-gmon-static-pie.data.*
131
132$(objpfx)tst-gmon-static-pie-gprof.out: tst-gmon-static-gprof.sh \
133					$(objpfx)tst-gmon-static-pie.out
134	$(SHELL) $< $(GPROF) $(objpfx)tst-gmon-static-pie \
135		$(objpfx)tst-gmon-static-pie.data.* > $@; \
136	$(evaluate-test)
137