perf jit: Fix build issue on Ubuntu
[cascardo/linux.git] / tools / perf / jvmti / Makefile
1 ARCH=$(shell uname -m)
2
3 ifeq ($(ARCH), x86_64)
4 JARCH=amd64
5 endif
6 ifeq ($(ARCH), armv7l)
7 JARCH=armhf
8 endif
9 ifeq ($(ARCH), armv6l)
10 JARCH=armhf
11 endif
12 ifeq ($(ARCH), aarch64)
13 JARCH=aarch64
14 endif
15 ifeq ($(ARCH), ppc64)
16 JARCH=powerpc
17 endif
18 ifeq ($(ARCH), ppc64le)
19 JARCH=powerpc
20 endif
21
22 DESTDIR=/usr/local
23
24 VERSION=1
25 REVISION=0
26 AGE=0
27
28 LN=ln -sf
29 RM=rm
30
31 SLIBJVMTI=libjvmti.so.$(VERSION).$(REVISION).$(AGE)
32 VLIBJVMTI=libjvmti.so.$(VERSION)
33 SLDFLAGS=-shared -Wl,-soname -Wl,$(VLIBJVMTI)
34 SOLIBEXT=so
35
36 # The following works at least on fedora 23, you may need the next
37 # line for other distros.
38 ifneq (,$(wildcard /usr/sbin/update-java-alternatives))
39 JDIR=$(shell /usr/sbin/update-java-alternatives -l | head -1 | awk '{print $$3}')
40 else
41   ifneq (,$(wildcard /usr/sbin/alternatives))
42     JDIR=$(shell alternatives --display java | tail -1 | cut -d' ' -f 5 | sed 's%/jre/bin/java.%%g')
43   endif
44 endif
45 ifndef JDIR
46 $(error Could not find alternatives command, you need to set JDIR= to point to the root of your Java directory)
47 else
48   ifeq (,$(wildcard $(JDIR)/include/jvmti.h))
49   $(error the openjdk development package appears to me missing, install and try again)
50   endif
51 endif
52 $(info Using Java from $(JDIR))
53 # -lrt required in 32-bit mode for clock_gettime()
54 LIBS=-lelf -lrt
55 INCDIR=-I $(JDIR)/include -I $(JDIR)/include/linux
56
57 TARGETS=$(SLIBJVMTI)
58
59 SRCS=libjvmti.c jvmti_agent.c
60 OBJS=$(SRCS:.c=.o)
61 SOBJS=$(OBJS:.o=.lo)
62 OPT=-O2 -g -Werror -Wall
63
64 CFLAGS=$(INCDIR) $(OPT)
65
66 all: $(TARGETS)
67
68 .c.o:
69         $(CC) $(CFLAGS) -c $*.c
70 .c.lo:
71         $(CC) -fPIC -DPIC $(CFLAGS) -c $*.c -o $*.lo
72
73 $(OBJS) $(SOBJS): Makefile jvmti_agent.h ../util/jitdump.h
74
75 $(SLIBJVMTI):  $(SOBJS)
76         $(CC) $(CFLAGS) $(SLDFLAGS)  -o $@ $(SOBJS) $(LIBS)
77         $(LN) $@ libjvmti.$(SOLIBEXT)
78
79 clean:
80         $(RM) -f *.o *.so.* *.so *.lo
81
82 install:
83         -mkdir -p $(DESTDIR)/lib
84         install -m 755 $(SLIBJVMTI) $(DESTDIR)/lib/
85         (cd $(DESTDIR)/lib; $(LN) $(SLIBJVMTI) $(VLIBJVMTI))
86         (cd $(DESTDIR)/lib; $(LN) $(SLIBJVMTI) libjvmti.$(SOLIBEXT))
87         ldconfig
88
89 .SUFFIXES: .c .S .o .lo