Makefile 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. TARGET=demo
  2. # MacOS
  3. ifneq ("$(wildcard /Library/Frameworks/GLFW*)","")
  4. PACKAGE=MacOS
  5. CFLAGS=-I/Library/Frameworks/GLFW.framework/Headers -I/Library/Frameworks/GLFW.framework/Versions/A/Headers -D_MACOS_=1 -x objective-c -fobjc-exceptions
  6. LIBS=-F/Library/Frameworks -framework GLFW -framework GL -framework AppKit
  7. EXE=
  8. else
  9. ifneq ("$(wildcard glfw3/*)","")
  10. CFLAGS+=-I./glfw3/include
  11. EXTRA+=./glfw3/build/src/libglfw3.a
  12. LIBS+=-lGL
  13. else
  14. ifneq ("$(wildcard SDL3/*)","")
  15. CFLAGS+=-I./SDL3/include/SDL3 -I./SDL3/include
  16. EXTRA+=./SDL3/build/libSDL3.a
  17. ifneq ("$(wildcard /bin/*.exe)","")
  18. LIBS+=-lole32 -loleaut32 -lws2_32 -limm32 -lshlwapi -lwinmm -lsetupapi -lversion
  19. else
  20. LIBS+=-ldl -lpthread
  21. endif
  22. else
  23. ifneq ("$(wildcard SDL2/*)","")
  24. CFLAGS+=-I./SDL2/include
  25. EXTRA+=./SDL2/build/.libs/libSDL2.a
  26. ifneq ("$(wildcard /bin/*.exe)","")
  27. LIBS+=-lole32 -loleaut32 -lws2_32 -limm32 -lshlwapi -lwinmm -lsetupapi -lversion
  28. else
  29. LIBS+=-ldl -lpthread
  30. endif
  31. else
  32. ifeq ("$(wildcard /bin/*.exe)","")
  33. LIBS+=-lglfw
  34. endif
  35. endif
  36. endif
  37. endif
  38. # Windows MinGW
  39. ifneq ("$(wildcard /bin/*.exe)","")
  40. PACKAGE=Win
  41. LDFLAGS+=-mwindows -static-libgcc
  42. LIBS+=-Wl,--nxcompat -Wl,-Bstatic,--whole-archive -lwinpthread -lglfw3 -lglew32.dll -lopengl32 -Wl,--no-whole-archive
  43. LIBS+=-luser32 -lm
  44. EXE=.exe
  45. else
  46. # Linux
  47. PACKAGE=Linux
  48. LIBS+=-lGL -lm
  49. endif
  50. endif
  51. SRCS = $(filter-out ssfn.c,$(wildcard *.c))
  52. ifneq ($(wildcard ssfn.h),)
  53. SRCS+=ssfn.c
  54. endif
  55. OBJS = $(SRCS:.c=)
  56. ifneq ($(wildcard stb_image.h),)
  57. OBJS+=skin
  58. endif
  59. ifneq ($(wildcard /usr/include/SDL2/SDL.h),)
  60. OBJS+=sdldemo
  61. endif
  62. ifneq ($(wildcard /usr/include/X11/Xlib.h),)
  63. OBJS+=x11demo
  64. endif
  65. CFLAGS+=-ansi -Wall -Wextra -Wno-pragmas -ffunction-sections -I.. -I. -I../mods
  66. ifeq ($(DEBUG),)
  67. CFLAGS+=-O3 -ffast-math
  68. else
  69. CFLAGS+=-g -DDEBUG=1
  70. endif
  71. all: $(OBJS)
  72. ifneq ("$(wildcard glfw3/*)","")
  73. glfw3/build/src/libglfw3.a:
  74. ifeq ($(wildcard glfw3/build/Makefile),)
  75. @cd glfw3 && cmake -S . -B build -D GLFW_BUILD_EXAMPLES=OFF -D GLFW_BUILD_TESTS=OFF -D GLFW_BUILD_DOCS=0FF
  76. endif
  77. @make --no-print-directory -s -C glfw3/build all
  78. endif
  79. static-glfw3:
  80. git clone https://github.com/glfw/glfw.git
  81. mv glfw glfw3
  82. ifneq ("$(wildcard SDL2/*)","")
  83. SDL2/build/.libs/libSDL2.a:
  84. ifeq ($(wildcard SDL2/configure),)
  85. @cd SDL2 && ./autogen.sh
  86. endif
  87. ifeq ($(wildcard SDL2/Makefile),)
  88. @cd SDL2 && ./configure --disable-shared --enable-static --disable-dbus
  89. endif
  90. @make --no-print-directory -s -C SDL2 all
  91. endif
  92. static-sdl2:
  93. git clone --branch SDL2 https://github.com/libsdl-org/SDL.git
  94. mv SDL SDL2
  95. printf "#ifndef SDL_dynapi_h_\n#define SDL_dynapi_h_\n#define SDL_DYNAMIC_API 0\n#endif" >SDL2/src/dynapi/SDL_dynapi.h
  96. ifneq ("$(wildcard SDL3/*)","")
  97. SDL3/build/libSDL3.a:
  98. ifeq ($(wildcard SDL3/build/Makefile),)
  99. @cd SDL3 && mkdir build && cd build && cmake -S .. -B ../build && cmake . -DCMAKE_BUILD_TYPE=Release -DSDL_SHARED=false -DSDL_STATIC=true -DSDL_DBUS=false -DSDL_IBUS=false
  100. endif
  101. @make --no-print-directory -s -C SDL3/build all
  102. endif
  103. static-sdl3:
  104. git clone https://github.com/libsdl-org/SDL.git
  105. mv SDL SDL3
  106. %: %.c
  107. $(CC) $(CFLAGS) $< -c -o $@.o
  108. $(CC) $(LDFLAGS) $@.o -o $@ $(EXTRA) $(LIBS) -Wl,--gc-sections
  109. @rm $@.o
  110. skin: widgets.c
  111. $(CC) $(CFLAGS) -std=c99 -DSKIN=1 $< -c -o $@.o
  112. $(CC) $(LDFLAGS) $@.o -o $@ $(EXTRA) $(LIBS) -Wl,--gc-sections
  113. @rm $@.o
  114. sdldemo: demo.c
  115. $(CC) $(CFLAGS) -I/usr/include/SDL2 -include ui_sdl.h $< -c -o $@.o
  116. $(CC) $(LDFLAGS) $@.o -o $@ $(EXTRA) -lSDL2 -ldl -lpthread -lm -Wl,--gc-sections
  117. @rm $@.o
  118. x11demo: demo.c
  119. $(CC) $(CFLAGS) -I/usr/include/X11 -include ui_x11.h $< -c -o $@.o
  120. $(CC) $(LDFLAGS) $@.o -o $@ $(EXTRA) -lX11 -lXmu -lm -Wl,--gc-sections
  121. @rm $@.o
  122. clean:
  123. @rm $(OBJS) 2>/dev/null || true
  124. distclean: clean
  125. ifneq ("$(wildcard glfw3/*)","")
  126. @make --no-print-directory -s -C glfw3/build clean 2>/dev/null || true
  127. endif
  128. ifneq ("$(wildcard SDL2/*)","")
  129. @make --no-print-directory -s -C SDL2/build clean 2>/dev/null || true
  130. endif
  131. ifneq ("$(wildcard SDL3/*)","")
  132. @make --no-print-directory -s -C SDL3/build clean 2>/dev/null || true
  133. endif