Makefile 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # General makefile for generic unix & linux platforms
  2. TARGET = sdlpal
  3. TEST_TARGET = ./sdlpal-tests
  4. INTER=.unix
  5. HOST =
  6. TEST_CCFLAGS =
  7. GENERATED = -DPAL_HAS_GIT_REVISION $(shell ../scripts/gengitrev)
  8. DEPFLAGS = -MT $@ -MMD -MP -MF $*$(INTER).Td
  9. GTEST_DIR = ../3rd/googletest/googletest
  10. ALSA_INSTALLED := $(shell echo "int main(){}" | gcc -o /dev/null -x c - -lasound 2>/dev/null && echo found)
  11. ifdef ALSA_INSTALLED
  12. MIDI_CFILES = $(wildcard ../native_midi/*.c) native_midi_alsa.c
  13. MIDI_CPPFILES =
  14. MIDI_LDFLAGS = -lasound
  15. else
  16. MIDI_CFILES =
  17. MIDI_CPPFILES = native_midi.cpp
  18. MIDI_LDFLAGS =
  19. endif
  20. CFILES = $(wildcard ../adplug/*.c) $(wildcard ../libmad/*.c) $(wildcard ../liboggvorbis/src/*.c) $(wildcard ../*.c) $(MIDI_CFILES)
  21. CPPFILES = $(wildcard ../adplug/*.cpp) $(wildcard ../*.cpp) unix.cpp $(MIDI_CPPFILES)
  22. OBJFILES = $(CFILES:.c=$(INTER).o) $(CPPFILES:.cpp=$(INTER).o)
  23. DEPFILES = $(OBJFILES:.o=.d)
  24. TEST_CPPFILES = $(wildcard ../tests/*.cpp)
  25. TEST_OBJFILES = $(TEST_CPPFILES:.cpp=.o)
  26. SDL_CONFIG = sdl2-config
  27. FLTK_INSTALLED := $(shell command -v fltk-config 2> /dev/null)
  28. ifdef FLTK_INSTALLED
  29. FLTK_CXXFLAGS = `fltk-config --cxxflags`
  30. FLTK_CFLAGS = `fltk-config --cflags`
  31. FLTK_LDFLAGS = `fltk-config --ldflags`
  32. else
  33. FLTK_CXXFLAGS = -DPAL_NO_LAUNCH_UI
  34. FLTK_CFLAGS =
  35. FLTK_LDFLAGS =
  36. endif
  37. CC = $(HOST)gcc
  38. CXX = $(HOST)g++
  39. CCFLAGS = `$(SDL_CONFIG) --cflags` -D_GNU_SOURCE -g -Wall -O2 -fno-strict-aliasing -I. -I../ -I../liboggvorbis/include \
  40. -I../liboggvorbis/src -DPAL_HAS_PLATFORM_SPECIFIC_UTILS $(TEST_CCFLAGS) $(GENERATED)
  41. CXXFLAGS = $(CCFLAGS) -std=c++11 $(FLTK_CXXFLAGS)
  42. CFLAGS = $(CCFLAGS) -std=gnu99 $(FLTK_CFLAGS)
  43. LDFLAGS = `$(SDL_CONFIG) --libs` $(FLTK_LDFLAGS) $(MIDI_LDFLAGS) -lstdc++ -lm -pthread
  44. TEST_CXXFLAGS += -isystem $(GTEST_DIR)/include -I $(GTEST_DIR) -g -Wall -Wextra -pthread
  45. POSTCOMPILE = @mv -f $*$(INTER).Td $*$(INTER).d && touch $@
  46. .PHONY : all clean check
  47. all: $(TARGET)
  48. $(TARGET): $(OBJFILES)
  49. @echo [LD] $@
  50. @$(CXX) $^ -o $@ $(LDFLAGS)
  51. gtest-all.o : $(GTEST_DIR)/src/gtest-all.cc %.d
  52. @echo [CC] $<
  53. @$(CXX) $(DEPFLAGS) $(TEST_CXXFLAGS) -c $< -o $@
  54. $(POSTCOMPILE)
  55. %$(INTER).o: %.c %$(INTER).d
  56. @echo [CC] $<
  57. @$(CC) $(DEPFLAGS) $(CFLAGS) -c $< -o $@
  58. $(POSTCOMPILE)
  59. %$(INTER).o: %.cpp %$(INTER).d
  60. @echo [CC] $<
  61. @$(CXX) $(DEPFLAGS) $(CXXFLAGS) -c $< -o $@
  62. $(POSTCOMPILE)
  63. $(TEST_TARGET): $(OBJFILES) $(TEST_OBJFILES) gtest-all.o
  64. @echo [LD] $@
  65. @$(CXX) $^ -o $@ $(LDFLAGS) -lpthread
  66. clean:
  67. -rm -f $(TARGET) $(TEST_TARGET) $(OBJFILES) $(TEST_OBJFILES) $(DEPFILES)
  68. %.d: ;
  69. .PRECIOUS: %.d
  70. -include $(DEPFILES)
  71. check: TEST_CCFLAGS = -DUNIT_TEST=1 -isystem $(GTEST_DIR)/include
  72. check: $(TEST_TARGET)
  73. @echo [EXEC] $(TEST_TARGET)
  74. @chmod +x $(TEST_TARGET)
  75. @exec $(TEST_TARGET)