Makefile 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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` -g -Wall -O2 -fno-strict-aliasing -I. -I../ -I../liboggvorbis/include -I../liboggvorbis/src -DPAL_HAS_PLATFORM_SPECIFIC_UTILS $(TEST_CCFLAGS) $(GENERATED)
  40. CXXFLAGS = $(CCFLAGS) -std=c++11 $(FLTK_CXXFLAGS)
  41. CFLAGS = $(CCFLAGS) -std=gnu99 $(FLTK_CFLAGS)
  42. LDFLAGS = `$(SDL_CONFIG) --libs` $(FLTK_LDFLAGS) $(MIDI_LDFLAGS) -lstdc++ -lm -pthread
  43. TEST_CXXFLAGS += -isystem $(GTEST_DIR)/include -I $(GTEST_DIR) -g -Wall -Wextra -pthread
  44. POSTCOMPILE = @mv -f $*$(INTER).Td $*$(INTER).d && touch $@
  45. .PHONY : all clean check
  46. all: $(TARGET)
  47. $(TARGET): $(OBJFILES)
  48. @echo [LD] $@
  49. @$(CXX) $^ -o $@ $(LDFLAGS)
  50. gtest-all.o : $(GTEST_DIR)/src/gtest-all.cc %.d
  51. @echo [CC] $<
  52. @$(CXX) $(DEPFLAGS) $(TEST_CXXFLAGS) -c $< -o $@
  53. $(POSTCOMPILE)
  54. %$(INTER).o: %.c %$(INTER).d
  55. @echo [CC] $<
  56. @$(CC) $(DEPFLAGS) $(CFLAGS) -c $< -o $@
  57. $(POSTCOMPILE)
  58. %$(INTER).o: %.cpp %$(INTER).d
  59. @echo [CC] $<
  60. @$(CXX) $(DEPFLAGS) $(CXXFLAGS) -c $< -o $@
  61. $(POSTCOMPILE)
  62. $(TEST_TARGET): $(OBJFILES) $(TEST_OBJFILES) gtest-all.o
  63. @echo [LD] $@
  64. @$(CXX) $^ -o $@ $(LDFLAGS) -lpthread
  65. clean:
  66. -rm -f $(TARGET) $(TEST_TARGET) $(OBJFILES) $(TEST_OBJFILES) $(DEPFILES)
  67. %.d: ;
  68. .PRECIOUS: %.d
  69. -include $(DEPFILES)
  70. check: TEST_CCFLAGS = -DUNIT_TEST=1 -isystem $(GTEST_DIR)/include
  71. check: $(TEST_TARGET)
  72. @echo [EXEC] $(TEST_TARGET)
  73. @chmod +x $(TEST_TARGET)
  74. @exec $(TEST_TARGET)