Makefile 1.57 KB
Newer Older
1 2 3 4 5
# if there is Makefile.local file then include it
ifneq (, $(wildcard Makefile.local))
include Makefile.local
endif

6 7
BUILDDIR=../build

8
# Source lists
9
LIBNAME=dislagent
10 11 12 13 14

SOURCES=bytecode.c common.c jvmtiutil.c connection.c \
	connpool.c msgchannel.c network.c dislagent.c

HEADERS=$(wildcard *.h) codeflags.h
15 16 17

# Object files needed to create library
OBJECTS=$(SOURCES:%.c=%.o)
18

19 20
# Library name and options needed to build it
UNAME := $(shell uname)
21

22 23 24
ifeq ($(UNAME), Linux)
LIBRARY=lib$(LIBNAME).so
endif
25

26 27 28 29 30 31 32 33 34
ifeq ($(UNAME), Darwin)
LIBRARY=lib$(LIBNAME).jnilib
endif


# Building a shared library
LINK_SHARED=$(LINK.c) -shared -o $@

# GNU Compiler options needed to build it
35 36
COMMON_FLAGS=-fPIC -std=gnu99

37
# Options that help find errors
38
COMMON_FLAGS+= -W -Wall -Wextra -Wno-unused-parameter
39 40 41 42 43

CFLAGS += $(COMMON_FLAGS)

CFLAGS += -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux

44

45
# add debugging output
46
ifneq ($(DEBUG),)
47
CFLAGS += -DDEBUG
48 49
else
CFLAGS += -DNDEBUG -O3
50 51
endif

52 53
build: $(LIBRARY)
	cp $(LIBRARY) $(BUILDDIR)
54 55

# Build native library
56 57 58 59 60
ifneq ($(WHOLE),)
$(LIBRARY): $(HEADERS) $(SOURCES)
	gcc $(CFLAGS) -DWHOLE -fwhole-program -flto -shared -o $@ $(SOURCES)
else
$(LIBRARY): $(HEADERS) $(OBJECTS)
61
	$(LINK_SHARED) $(OBJECTS) $(LIBRARIES)
62 63 64 65 66 67 68 69 70 71 72 73 74
endif


BPC_CLASSES := $(wildcard bypass/*/*.class)

bytecode.c: $(BPC_CLASSES) bin2class
	./bin2class \
		$(foreach BPC,$(BPC_CLASSES),$(BPC) $(subst bypass/,bpc_,$(BPC:/BypassCheck.class=))) \
		> $@

codeflags.h: codeflags
	./codeflags

75 76 77 78

# Cleanup the built bits
clean:
	rm -f $(LIBRARY) $(OBJECTS)
79 80

debug:
81 82 83 84
	$(MAKE) DEBUG=1

whole:
	$(MAKE) WHOLE=1
85

86
all: build