native_support.mk 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. ifeq ($(MPT_PROGRESS_FILE),)
  2. MPT_PROGRESS_FILE:=/dev/null
  3. endif
  4. ifneq ($(words $(MAKECMDGOALS)),1)
  5. .DEFAULT_GOAL = all
  6. %:
  7. @$(MAKE) $@ --no-print-directory -rRf $(firstword $(MAKEFILE_LIST))
  8. else
  9. ifndef PROGRESS
  10. T := $(shell $(MAKE) $(MAKECMDGOALS) --no-print-directory -nrRf $(firstword $(MAKEFILE_LIST)) PROGRESS="COUNTTHIS" | grep -c "COUNTTHIS")
  11. N := x
  12. C = $(words $N)$(eval N := x $N)
  13. D = $(words $N)$(eval N := $N)
  14. PROGRESS = @echo "`expr \( $C '-' 1 \) '*' 100 / $T`" >$(MPT_PROGRESS_FILE)
  15. PROGRESS_ECHO = @echo "[`printf %3s \`expr \( $D '-' 1 \) '*' 100 / $T\``%]"
  16. endif
  17. PROGRESS_ECHO ?= echo
  18. V?=2
  19. INFO ?= @echo
  20. SILENT ?= @
  21. VERYSILENT ?= @
  22. ifeq ($(V),6)
  23. INFO = @true
  24. SILENT =
  25. VERYSILENT =
  26. endif
  27. ifeq ($(V),5)
  28. INFO = @true
  29. SILENT =
  30. VERYSILENT =
  31. endif
  32. ifeq ($(V),4)
  33. INFO = @true
  34. SILENT =
  35. VERYSILENT = @
  36. endif
  37. ifeq ($(V),3)
  38. INFO = @$(PROGRESS_ECHO)
  39. SILENT = @
  40. VERYSILENT = @
  41. endif
  42. ifeq ($(V),2)
  43. INFO = @$(PROGRESS_ECHO)
  44. SILENT = @
  45. VERYSILENT = @
  46. endif
  47. ifeq ($(V),1)
  48. INFO = @true
  49. SILENT = @
  50. VERYSILENT = @
  51. endif
  52. ifeq ($(V),0)
  53. INFO = @true
  54. SILENT = @
  55. VERYSILENT = @
  56. endif
  57. ifeq ($(MPT_ARCH_BITS),)
  58. MPT_ARCH_TARGET:=
  59. else
  60. MPT_ARCH_TARGET:=-m$(MPT_ARCH_BITS)
  61. endif
  62. MPT_TARGET?=
  63. MPT_TRY_DBUS?=1
  64. MPT_TRY_PORTAUDIO?=1
  65. MPT_TRY_PULSEAUDIO?=1
  66. MPT_TRY_RTAUDIO?=1
  67. CPPFLAGS += $(MPT_ARCH_TARGET) -Icommon -Isrc -Iinclude/nlohmann-json/include -Iinclude
  68. CXXFLAGS += $(MPT_ARCH_TARGET) -std=gnu++17 -fpermissive -fPIC -fvisibility=hidden
  69. CFLAGS += $(MPT_ARCH_TARGET) -std=c99 -fPIC -fvisibility=hidden
  70. LDFLAGS += $(MPT_ARCH_TARGET)
  71. LDLIBS += -lm -lpthread
  72. ARFLAGS +=
  73. CXXFLAGS += -Os -ffast-math
  74. CFLAGS += -Os -ffast-math -fno-strict-aliasing
  75. CXXFLAGS += -Wall -Wextra -Wundef -Wcast-qual -Wcast-align
  76. CFLAGS += -Wall -Wextra -Wundef -Wcast-qual -Wcast-align
  77. ifeq ($(shell command -v ccache 2>/dev/null 1>/dev/null && echo yes),yes)
  78. CCACHE=ccache
  79. else
  80. CCACHE=
  81. endif
  82. ifeq ($(MPT_TRY_DBUS),2)
  83. ifeq ($(shell $(MPT_TARGET)pkg-config --exists dbus-1 && echo yes),yes)
  84. CPPFLAGS += $(shell $(MPT_TARGET)pkg-config --cflags-only-I dbus-1 ) -DMPT_WITH_DBUS
  85. LDFLAGS += $(shell $(MPT_TARGET)pkg-config --libs-only-L dbus-1 ) $(shell $(MPT_TARGET)pkg-config --libs-only-other dbus-1 )
  86. LDLIBS += $(shell $(MPT_TARGET)pkg-config --libs-only-l dbus-1 )
  87. CPPFLAGS += -DMPT_WITH_RTKIT
  88. RTKIT_C_SOURCES += include/rtkit/rtkit.c
  89. else
  90. $(error DBus not found.)
  91. endif
  92. else
  93. ifeq ($(MPT_TRY_DBUS),1)
  94. ifeq ($(shell $(MPT_TARGET)pkg-config --exists dbus-1 && echo yes),yes)
  95. CPPFLAGS += $(shell $(MPT_TARGET)pkg-config --cflags-only-I dbus-1 ) -DMPT_WITH_DBUS
  96. LDFLAGS += $(shell $(MPT_TARGET)pkg-config --libs-only-L dbus-1 ) $(shell $(MPT_TARGET)pkg-config --libs-only-other dbus-1 )
  97. LDLIBS += $(shell $(MPT_TARGET)pkg-config --libs-only-l dbus-1 )
  98. CPPFLAGS += -DMPT_WITH_RTKIT
  99. RTKIT_C_SOURCES += include/rtkit/rtkit.c
  100. endif
  101. endif
  102. endif
  103. ifeq ($(MPT_TRY_PORTAUDIO),2)
  104. ifeq ($(shell $(MPT_TARGET)pkg-config --exists portaudio-2.0 && echo yes),yes)
  105. CPPFLAGS += $(shell $(MPT_TARGET)pkg-config --cflags-only-I portaudio-2.0 ) -DMPT_WITH_PORTAUDIO
  106. LDFLAGS += $(shell $(MPT_TARGET)pkg-config --libs-only-L portaudio-2.0 ) $(shell $(MPT_TARGET)pkg-config --libs-only-other portaudio-2.0 )
  107. LDLIBS += $(shell $(MPT_TARGET)pkg-config --libs-only-l portaudio-2.0 )
  108. else
  109. $(error PortAudio not found.)
  110. endif
  111. else
  112. ifeq ($(MPT_TRY_PORTAUDIO),1)
  113. ifeq ($(shell $(MPT_TARGET)pkg-config --exists portaudio-2.0 && echo yes),yes)
  114. CPPFLAGS += $(shell $(MPT_TARGET)pkg-config --cflags-only-I portaudio-2.0 ) -DMPT_WITH_PORTAUDIO
  115. LDFLAGS += $(shell $(MPT_TARGET)pkg-config --libs-only-L portaudio-2.0 ) $(shell $(MPT_TARGET)pkg-config --libs-only-other portaudio-2.0 )
  116. LDLIBS += $(shell $(MPT_TARGET)pkg-config --libs-only-l portaudio-2.0 )
  117. endif
  118. endif
  119. endif
  120. ifeq ($(MPT_TRY_PULSEAUDIO),2)
  121. ifeq ($(shell $(MPT_TARGET)pkg-config --exists libpulse libpulse-simple && echo yes),yes)
  122. CPPFLAGS += $(shell $(MPT_TARGET)pkg-config --cflags-only-I libpulse libpulse-simple ) -DMPT_WITH_PULSEAUDIO -DMPT_WITH_PULSEAUDIOSIMPLE
  123. LDFLAGS += $(shell $(MPT_TARGET)pkg-config --libs-only-L libpulse libpulse-simple ) $(shell $(MPT_TARGET)pkg-config --libs-only-other libpulse libpulse-simple )
  124. LDLIBS += $(shell $(MPT_TARGET)pkg-config --libs-only-l libpulse libpulse-simple )
  125. else
  126. $(error PulseAudio not found.)
  127. endif
  128. else
  129. ifeq ($(MPT_TRY_PULSEAUDIO),1)
  130. ifeq ($(shell $(MPT_TARGET)pkg-config --exists libpulse libpulse-simple && echo yes),yes)
  131. CPPFLAGS += $(shell $(MPT_TARGET)pkg-config --cflags-only-I libpulse libpulse-simple ) -DMPT_WITH_PULSEAUDIO -DMPT_WITH_PULSEAUDIOSIMPLE
  132. LDFLAGS += $(shell $(MPT_TARGET)pkg-config --libs-only-L libpulse libpulse-simple ) $(shell $(MPT_TARGET)pkg-config --libs-only-other libpulse libpulse-simple )
  133. LDLIBS += $(shell $(MPT_TARGET)pkg-config --libs-only-l libpulse libpulse-simple )
  134. else
  135. ifeq ($(shell $(MPT_TARGET)pkg-config --exists libpulse && echo yes),yes)
  136. CPPFLAGS += $(shell $(MPT_TARGET)pkg-config --cflags-only-I libpulse ) -DMPT_WITH_PULSEAUDIO
  137. LDFLAGS += $(shell $(MPT_TARGET)pkg-config --libs-only-L libpulse ) $(shell $(MPT_TARGET)pkg-config --libs-only-other libpulse )
  138. LDLIBS += $(shell $(MPT_TARGET)pkg-config --libs-only-l libpulse )
  139. endif
  140. endif
  141. endif
  142. endif
  143. ifeq ($(MPT_TRY_RTAUDIO),2)
  144. ifeq ($(shell $(MPT_TARGET)pkg-config --exists rtaudio && echo yes),yes)
  145. CPPFLAGS += $(shell $(MPT_TARGET)pkg-config --cflags-only-I rtaudio ) -DMPT_WITH_RTAUDIO
  146. LDFLAGS += $(shell $(MPT_TARGET)pkg-config --libs-only-L rtaudio ) $(shell $(MPT_TARGET)pkg-config --libs-only-other rtaudio )
  147. LDLIBS += $(shell $(MPT_TARGET)pkg-config --libs-only-l rtaudio )
  148. else
  149. $(error RtAudio not found.)
  150. endif
  151. else
  152. ifeq ($(MPT_TRY_RTAUDIO),1)
  153. ifeq ($(shell $(MPT_TARGET)pkg-config --exists rtaudio && echo yes),yes)
  154. CPPFLAGS += $(shell $(MPT_TARGET)pkg-config --cflags-only-I rtaudio ) -DMPT_WITH_RTAUDIO
  155. LDFLAGS += $(shell $(MPT_TARGET)pkg-config --libs-only-L rtaudio ) $(shell $(MPT_TARGET)pkg-config --libs-only-other rtaudio )
  156. LDLIBS += $(shell $(MPT_TARGET)pkg-config --libs-only-l rtaudio )
  157. endif
  158. endif
  159. endif
  160. .PHONY: all
  161. all: libopenmpt_native_support.so
  162. %: %.o
  163. $(PROGRESS)
  164. $(INFO) Linking $@ ...
  165. $(SILENT)$(MPT_TARGET)$(LINK.cc) $^ $(LOADLIBES) $(LDLIBS) -o $@
  166. %.o: %.cpp
  167. $(PROGRESS)
  168. $(INFO) Compiling $< ...
  169. $(SILENT)$(CCACHE) $(MPT_TARGET)$(COMPILE.cc) -DMODPLUG_TRACKER -DMPT_BUILD_WINESUPPORT -DMPT_WITH_NLOHMANNJSON $(OUTPUT_OPTION) $<
  170. %.o: %.c
  171. $(PROGRESS)
  172. $(INFO) Compiling $< ...
  173. $(SILENT)$(CCACHE) $(MPT_TARGET)$(COMPILE.c) -DMODPLUG_TRACKER -DMPT_BUILD_WINESUPPORT -DMPT_WITH_NLOHMANNJSON $(OUTPUT_OPTION) $<
  174. COMMON_CXX_SOURCES += $(wildcard common/*.cpp)
  175. MISC_CXX_SOURCES += $(wildcard misc/*.cpp)
  176. SOUNDDEVICE_CXX_SOURCES += $(wildcard src/openmpt/sounddevice/*.cpp)
  177. WINESUPPORT_CXX_SOURCES += $(wildcard mptrack/wine/*.cpp)
  178. OPENMPT_WINESUPPORT_CXX_SOURCES += \
  179. $(COMMON_CXX_SOURCES) \
  180. $(MISC_CXX_SOURCES) \
  181. $(SOUNDDEVICE_CXX_SOURCES) \
  182. $(WINESUPPORT_CXX_SOURCES) \
  183. OPENMPT_WINESUPPORT_C_SOURCES += \
  184. $(RTKIT_C_SOURCES) \
  185. OPENMPT_WINESUPPORT_OBJECTS = $(OPENMPT_WINESUPPORT_CXX_SOURCES:.cpp=.o) $(OPENMPT_WINESUPPORT_C_SOURCES:.c=.o)
  186. OPENMPT_WINESUPPORT_LDFLAGS = -Wl,-z,defs,--no-undefined
  187. LDLIBS_OPENMPT_WINESUPPORT =
  188. libopenmpt_native_support.so: $(OPENMPT_WINESUPPORT_OBJECTS)
  189. $(PROGRESS)
  190. $(INFO) Linking $@ ...
  191. $(SILENT)$(MPT_TARGET)$(LINK.cc) -shared $(OPENMPT_WINESUPPORT_LDFLAGS) $^ $(LOADLIBS) $(LDLIBS) $(LDLIBS_OPENMPT_WINESUPPORT) -o $@
  192. endif