p≡p for Java
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.8 KiB

  1. # Copyright 2018, pEp Foundation
  2. # This file is part of pEp JNI Adapter
  3. # This file may be used under the terms of the GNU General Public License version 3
  4. # see LICENSE.txt
  5. HERE:=$(dir $(lastword $(MAKEFILE_LIST)))
  6. PLATFORM:=$(shell uname | tr A-Z a-z)
  7. JAVAC_CMD=javac -encoding UTF-8
  8. JAVAH_CMD=javah -encoding UTF-8
  9. # DEV ENV PATHS & CFG
  10. # The build settings are set to a default value which can be overridden by using ./local.conf
  11. ######### DEFAULTS #########
  12. DEBUG=0
  13. PREFIX=$(HOME)
  14. YML2_PATH=$(PREFIX)/src/yml2
  15. YML2_PROC=$(YML2_PATH)/yml2proc $(YML2_OPTS)
  16. YML2_OPTS=--encoding=utf8
  17. ENGINE_LIB_PATH=$(PREFIX)/lib
  18. ENGINE_INC_PATH=$(PREFIX)/include
  19. AD_LIB_PATH=$(PREFIX)/lib
  20. AD_INC_PATH=$(PREFIX)/include
  21. ### Guessing JAVA_HOME
  22. ifeq ($(PLATFORM),linux)
  23. JAVA_HOME=$(subst /bin,,$(dir $(realpath /usr/bin/javac)))
  24. endif
  25. ######### Overrides from the config file(s) #########
  26. ifneq ("$(wildcard $(HERE)local.conf)","")
  27. $(info including: $(HERE)local.conf)
  28. -include $(HERE)local.conf
  29. else
  30. $(info Optional build config not found: $(HERE)local.conf)
  31. endif
  32. ### Apply config
  33. ENGINE_LIB=-L$(ENGINE_LIB_PATH)
  34. ENGINE_INC=-I$(ENGINE_INC_PATH)
  35. AD_LIB=-L$(AD_LIB_PATH)
  36. AD_INC=-I$(AD_INC_PATH)
  37. ifndef JAVA_HOME
  38. $(error JAVA_HOME is not set!)
  39. endif
  40. # Guessing USE_JAVAH
  41. # cant be guessed earlier, because it depends on JAVA_HOME which can be set in the local.conf
  42. # Old versions of a Java distribution have a `javah` binary, new version do not and the replacement is "javac -h"
  43. # TODO: dont check for presence of javah, but check if javac -h is supported, because some java (RHEL) has javah but supports javac -h (and javac -h is preferred)
  44. ifndef USE_JAVAH
  45. DUMMY:=$(shell which $(JAVA_HOME)/bin/javah)
  46. ifeq ($(.SHELLSTATUS),0)
  47. USE_JAVAH=1
  48. endif
  49. endif
  50. JAVA_BIN_DIR=$(JAVA_HOME)/bin
  51. ######### C and C++ #########
  52. CXXFLAGS+=-O0 -std=c++11 -fpermissive -fPIC -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/$(PLATFORM) $(AD_INC) $(ENGINE_INC)
  53. LDFLAGS+=-shared $(ENGINE_LIB) $(AD_LIB)
  54. LDLIBS=-lstdc++ -lpEpEngine -lpEpAdapter
  55. ifneq (,$(findstring g++,$(CXX)))
  56. CXXFLAGS+=-fdiagnostics-color=always
  57. else ifneq (,$(findstring clang,$(CXX)))
  58. CXXFLAGS+=-fcolor-diagnostics
  59. endif
  60. ### Debug or Release build
  61. ifeq ($(DEBUG),1)
  62. $(info Debug build (set DEBUG=0 for release build))
  63. CXXFLAGS+=-g
  64. else
  65. $(info Release Build (set DEBUG=1 for debug build))
  66. CXXFLAGS+=-DNDEBUG=1 -O3
  67. endif
  68. ### YML_PATH is needed in the environment of every call to a program of the YML2 distribution
  69. export YML_PATH=$(YML2_PATH)
  70. # BEGIN // kryptic hack to to replace a space with a newline
  71. # $(subst ${ },${space}, whatever)
  72. # maybe not well known: define/endef is custom makefile function definition
  73. null :=
  74. space := ${null} ${null}
  75. ${space} := ${space}
  76. define \n
  77. endef
  78. # END // kryptic hack to to replace a space with a newline