ruby2d 0.9.3 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. checksums.yaml +4 -4
  2. data/assets/README.md +7 -9
  3. data/assets/Rakefile +85 -0
  4. data/assets/include/SDL2/SDL.h +4 -1
  5. data/assets/include/SDL2/SDL_assert.h +3 -1
  6. data/assets/include/SDL2/SDL_atomic.h +20 -2
  7. data/assets/include/SDL2/SDL_audio.h +47 -14
  8. data/assets/include/SDL2/SDL_bits.h +10 -1
  9. data/assets/include/SDL2/SDL_blendmode.h +10 -7
  10. data/assets/include/SDL2/SDL_clipboard.h +1 -1
  11. data/assets/include/SDL2/SDL_config.h +24 -390
  12. data/assets/include/SDL2/SDL_config_android.h +182 -0
  13. data/assets/include/SDL2/SDL_config_iphoneos.h +207 -0
  14. data/assets/include/SDL2/SDL_config_macosx.h +266 -0
  15. data/assets/include/SDL2/SDL_config_minimal.h +85 -0
  16. data/assets/include/SDL2/SDL_config_os2.h +188 -0
  17. data/assets/include/SDL2/SDL_config_pandora.h +135 -0
  18. data/assets/include/SDL2/SDL_config_psp.h +165 -0
  19. data/assets/include/SDL2/SDL_config_windows.h +288 -0
  20. data/assets/include/SDL2/SDL_config_winrt.h +243 -0
  21. data/assets/include/SDL2/SDL_config_wiz.h +149 -0
  22. data/assets/include/SDL2/SDL_copying.h +20 -0
  23. data/assets/include/SDL2/SDL_cpuinfo.h +119 -8
  24. data/assets/include/SDL2/SDL_egl.h +4 -1
  25. data/assets/include/SDL2/SDL_endian.h +6 -3
  26. data/assets/include/SDL2/SDL_error.h +38 -2
  27. data/assets/include/SDL2/SDL_events.h +67 -28
  28. data/assets/include/SDL2/SDL_filesystem.h +1 -1
  29. data/assets/include/SDL2/SDL_gamecontroller.h +160 -9
  30. data/assets/include/SDL2/SDL_gesture.h +1 -1
  31. data/assets/include/SDL2/SDL_haptic.h +10 -1
  32. data/assets/include/SDL2/SDL_hints.h +460 -17
  33. data/assets/include/SDL2/SDL_image.h +2 -2
  34. data/assets/include/SDL2/SDL_joystick.h +115 -24
  35. data/assets/include/SDL2/SDL_keyboard.h +1 -1
  36. data/assets/include/SDL2/SDL_keycode.h +11 -9
  37. data/assets/include/SDL2/SDL_loadso.h +1 -1
  38. data/assets/include/SDL2/SDL_locale.h +101 -0
  39. data/assets/include/SDL2/SDL_log.h +3 -3
  40. data/assets/include/SDL2/SDL_main.h +28 -16
  41. data/assets/include/SDL2/SDL_messagebox.h +6 -4
  42. data/assets/include/SDL2/SDL_metal.h +117 -0
  43. data/assets/include/SDL2/SDL_misc.h +75 -0
  44. data/assets/include/SDL2/SDL_mouse.h +1 -1
  45. data/assets/include/SDL2/SDL_mutex.h +1 -1
  46. data/assets/include/SDL2/SDL_name.h +1 -1
  47. data/assets/include/SDL2/SDL_opengl.h +1 -1
  48. data/assets/include/SDL2/SDL_opengl_glext.h +3 -0
  49. data/assets/include/SDL2/SDL_opengles.h +1 -1
  50. data/assets/include/SDL2/SDL_opengles2.h +1 -1
  51. data/assets/include/SDL2/SDL_pixels.h +27 -18
  52. data/assets/include/SDL2/SDL_platform.h +1 -1
  53. data/assets/include/SDL2/SDL_power.h +1 -1
  54. data/assets/include/SDL2/SDL_quit.h +1 -1
  55. data/assets/include/SDL2/SDL_rect.h +29 -3
  56. data/assets/include/SDL2/SDL_render.h +230 -3
  57. data/assets/include/SDL2/SDL_revision.h +2 -2
  58. data/assets/include/SDL2/SDL_rwops.h +51 -22
  59. data/assets/include/SDL2/SDL_scancode.h +2 -2
  60. data/assets/include/SDL2/SDL_sensor.h +28 -12
  61. data/assets/include/SDL2/SDL_shape.h +1 -1
  62. data/assets/include/SDL2/SDL_stdinc.h +44 -4
  63. data/assets/include/SDL2/SDL_surface.h +12 -2
  64. data/assets/include/SDL2/SDL_system.h +50 -4
  65. data/assets/include/SDL2/SDL_syswm.h +39 -9
  66. data/assets/include/SDL2/SDL_test.h +1 -1
  67. data/assets/include/SDL2/SDL_test_assert.h +1 -1
  68. data/assets/include/SDL2/SDL_test_common.h +32 -2
  69. data/assets/include/SDL2/SDL_test_compare.h +1 -1
  70. data/assets/include/SDL2/SDL_test_crc32.h +1 -1
  71. data/assets/include/SDL2/SDL_test_font.h +1 -1
  72. data/assets/include/SDL2/SDL_test_fuzzer.h +1 -1
  73. data/assets/include/SDL2/SDL_test_harness.h +1 -1
  74. data/assets/include/SDL2/SDL_test_images.h +1 -1
  75. data/assets/include/SDL2/SDL_test_log.h +1 -1
  76. data/assets/include/SDL2/SDL_test_md5.h +1 -1
  77. data/assets/include/SDL2/SDL_test_memory.h +3 -3
  78. data/assets/include/SDL2/SDL_test_random.h +1 -1
  79. data/assets/include/SDL2/SDL_thread.h +34 -11
  80. data/assets/include/SDL2/SDL_timer.h +1 -1
  81. data/assets/include/SDL2/SDL_touch.h +17 -1
  82. data/assets/include/SDL2/SDL_types.h +1 -1
  83. data/assets/include/SDL2/SDL_version.h +2 -2
  84. data/assets/include/SDL2/SDL_video.h +11 -5
  85. data/assets/include/SDL2/SDL_vulkan.h +9 -11
  86. data/assets/include/SDL2/begin_code.h +8 -9
  87. data/assets/include/SDL2/close_code.h +4 -1
  88. data/assets/macos/lib/libFLAC.a +0 -0
  89. data/assets/macos/lib/libSDL2.a +0 -0
  90. data/assets/macos/lib/libSDL2_image.a +0 -0
  91. data/assets/macos/lib/libSDL2_mixer.a +0 -0
  92. data/assets/macos/lib/libSDL2_ttf.a +0 -0
  93. data/assets/macos/lib/libfreetype.a +0 -0
  94. data/assets/macos/lib/libjpeg.a +0 -0
  95. data/assets/macos/lib/libmpg123.a +0 -0
  96. data/assets/macos/lib/libogg.a +0 -0
  97. data/assets/macos/lib/libpng16.a +0 -0
  98. data/assets/macos/lib/libtiff.a +0 -0
  99. data/assets/macos/lib/libvorbis.a +0 -0
  100. data/assets/macos/lib/libvorbisfile.a +0 -0
  101. data/assets/macos/lib/libwebp.a +0 -0
  102. data/assets/mingw/bin/SDL2.dll +0 -0
  103. data/assets/mingw/bin/SDL2_image.dll +0 -0
  104. data/assets/mingw/bin/libpng16-16.dll +0 -0
  105. data/assets/mingw/bin/libtiff-5.dll +0 -0
  106. data/assets/mingw/bin/libwebp-7.dll +0 -0
  107. data/assets/mingw/lib/libSDL2.a +0 -0
  108. data/assets/mingw/lib/libSDL2.dll.a +0 -0
  109. data/assets/mingw/lib/libSDL2_image.a +0 -0
  110. data/assets/mingw/lib/libSDL2_image.dll.a +0 -0
  111. data/assets/mingw/lib/libSDL2_test.a +0 -0
  112. data/assets/mingw/lib/libSDL2main.a +0 -0
  113. data/bin/ruby2d +1 -0
  114. data/{assets/linux/simple2d/src/simple2d.c → ext/ruby2d/common.c} +32 -32
  115. data/{assets/linux/simple2d/src → ext/ruby2d}/controllers.c +17 -17
  116. data/ext/ruby2d/extconf.rb +36 -58
  117. data/ext/ruby2d/font.c +35 -0
  118. data/{assets/linux/simple2d/src → ext/ruby2d}/gl.c +72 -100
  119. data/ext/ruby2d/gl2.c +86 -0
  120. data/ext/ruby2d/gl3.c +305 -0
  121. data/{assets/linux/simple2d/src → ext/ruby2d}/gles.c +22 -81
  122. data/ext/ruby2d/image.c +58 -0
  123. data/{assets/linux/simple2d/src → ext/ruby2d}/input.c +8 -8
  124. data/{assets/linux/simple2d/src → ext/ruby2d}/music.c +30 -17
  125. data/ext/ruby2d/ruby2d.c +449 -439
  126. data/ext/ruby2d/ruby2d.h +652 -0
  127. data/{assets/linux/simple2d/src → ext/ruby2d}/shapes.c +18 -18
  128. data/ext/ruby2d/sound.c +118 -0
  129. data/ext/ruby2d/text.c +22 -0
  130. data/{assets/linux/simple2d/src → ext/ruby2d}/window.c +73 -62
  131. data/lib/ruby2d/circle.rb +21 -3
  132. data/lib/ruby2d/cli/build.rb +4 -7
  133. data/lib/ruby2d/dsl.rb +16 -9
  134. data/lib/ruby2d/entity.rb +17 -0
  135. data/lib/ruby2d/font.rb +23 -3
  136. data/lib/ruby2d/image.rb +35 -7
  137. data/lib/ruby2d/line.rb +23 -1
  138. data/lib/ruby2d/music.rb +5 -0
  139. data/lib/ruby2d/pixel.rb +17 -0
  140. data/lib/ruby2d/quad.rb +21 -1
  141. data/lib/ruby2d/rectangle.rb +12 -3
  142. data/lib/ruby2d/renderable.rb +4 -20
  143. data/lib/ruby2d/sound.rb +30 -0
  144. data/lib/ruby2d/sprite.rb +57 -75
  145. data/lib/ruby2d/square.rb +10 -1
  146. data/lib/ruby2d/text.rb +55 -12
  147. data/lib/ruby2d/texture.rb +28 -0
  148. data/lib/ruby2d/tileset.rb +87 -0
  149. data/lib/ruby2d/triangle.rb +19 -1
  150. data/lib/ruby2d/version.rb +1 -1
  151. data/lib/ruby2d/vertices.rb +84 -0
  152. data/lib/ruby2d/window.rb +259 -22
  153. data/lib/ruby2d.rb +6 -1
  154. metadata +41 -26
  155. data/assets/include/simple2d.h +0 -735
  156. data/assets/linux/simple2d/Makefile +0 -257
  157. data/assets/linux/simple2d/bin/simple2d.sh +0 -1312
  158. data/assets/linux/simple2d/include/simple2d.h +0 -735
  159. data/assets/linux/simple2d/src/gl2.c +0 -146
  160. data/assets/linux/simple2d/src/gl3.c +0 -275
  161. data/assets/linux/simple2d/src/image.c +0 -138
  162. data/assets/linux/simple2d/src/sound.c +0 -56
  163. data/assets/linux/simple2d/src/sprite.c +0 -147
  164. data/assets/linux/simple2d/src/text.c +0 -129
  165. data/assets/macos/lib/libsimple2d.a +0 -0
  166. data/assets/mingw/lib/libsimple2d.a +0 -0
@@ -1,257 +0,0 @@
1
- # Makefile for Unix-like systems:
2
- # macOS, Linux, Raspberry Pi, MinGW
3
-
4
- PREFIX?=/usr/local
5
- CFLAGS=-std=c11
6
-
7
- # ARM platforms
8
- ifneq (,$(findstring arm,$(shell uname -m)))
9
- # Raspberry Pi includes
10
- INCLUDES=-I/opt/vc/include/
11
- endif
12
-
13
- # Apple
14
- ifeq ($(shell uname),Darwin)
15
- PLATFORM=apple
16
- XCPRETTY_STATUS=$(shell xcpretty -v &>/dev/null; echo $$?)
17
- ifeq ($(XCPRETTY_STATUS),0)
18
- XCPRETTY=xcpretty
19
- else
20
- XCPRETTY=cat
21
- endif
22
- endif
23
-
24
- # Linux
25
- ifeq ($(shell uname),Linux)
26
- CFLAGS+=-fPIC
27
- endif
28
-
29
- # BSD
30
- ifneq (,$(findstring BSD,$(shell uname)))
31
- CC=cc
32
- INCLUDES=-I/usr/local/include/
33
- CFLAGS+=-fPIC
34
- endif
35
-
36
- # MinGW
37
- ifneq (,$(findstring MINGW,$(shell uname -s)))
38
- PLATFORM=mingw
39
- CC=gcc
40
- INCLUDES=-I/usr/local/include/
41
- endif
42
-
43
- SOURCES=$(notdir $(wildcard src/*.c))
44
- OBJECTS=$(addprefix build/,$(notdir $(SOURCES:.c=.o)))
45
-
46
- VERSION=$(shell bash bin/simple2d.sh -v)
47
-
48
- # Release directories and archive filenames
49
- APPLE_RELEASE=simple2d-apple-frameworks-$(VERSION)
50
- MINGW_RELEASE=simple2d-windows-mingw-$(VERSION)
51
-
52
- # Helper functions
53
-
54
- define task_msg
55
- @printf "\n\033[1;34m==>\033[39m $(1)\033[0m\n\n"
56
- endef
57
-
58
- define info_msg
59
- @printf "\033[1;36mInfo:\e[39m $(1)\033[0m\n"
60
- endef
61
-
62
- define run_test
63
- $(call task_msg,Running $(1).c)
64
- @cd test/; ./$(1)
65
- endef
66
-
67
- # Targets
68
-
69
- all: prereqs install-deps $(SOURCES)
70
- ar -vq build/libsimple2d.a $(OBJECTS)
71
- cp bin/simple2d.sh build/simple2d
72
- chmod 0777 build/simple2d
73
- rm build/*.o
74
-
75
- prereqs:
76
- $(call task_msg,Building)
77
- mkdir -p build
78
-
79
- install-deps:
80
- ifeq ($(PLATFORM),mingw)
81
- $(call task_msg,Installing dependencies for MinGW)
82
- mkdir -p $(PREFIX)/include/
83
- mkdir -p $(PREFIX)/lib/
84
- mkdir -p $(PREFIX)/bin/
85
- cp -R deps/mingw/include/* $(PREFIX)/include
86
- cp -R deps/mingw/lib/* $(PREFIX)/lib
87
- cp -R deps/mingw/bin/* $(PREFIX)/bin
88
- endif
89
-
90
- $(SOURCES):
91
- $(CC) $(CFLAGS) $(INCLUDES) src/$@ -c -o build/$(basename $@).o
92
-
93
- install:
94
- $(call task_msg,Installing Simple 2D)
95
- mkdir -p $(PREFIX)/include/
96
- mkdir -p $(PREFIX)/lib/
97
- mkdir -p $(PREFIX)/bin/
98
- cp include/simple2d.h $(PREFIX)/include/
99
- cp build/libsimple2d.a $(PREFIX)/lib/
100
- cp build/simple2d $(PREFIX)/bin/
101
-
102
- ifeq ($(PLATFORM),apple)
103
- frameworks: all
104
- $(call task_msg,Building iOS and tvOS frameworks)
105
- xcodebuild -version
106
- ifneq ($(XCPRETTY_STATUS),0)
107
- @echo "xcpretty not found: Run \`gem install xcpretty\` for nicer xcodebuild output.\n"
108
- endif
109
- mkdir -p build
110
- cp -R deps/xcode/Simple2D.xcodeproj build
111
- cd build && \
112
- xcodebuild -sdk iphoneos | $(XCPRETTY) && \
113
- xcodebuild -sdk iphonesimulator | $(XCPRETTY) && \
114
- xcodebuild -sdk appletvos | $(XCPRETTY) && \
115
- xcodebuild -sdk appletvsimulator | $(XCPRETTY)
116
- mkdir -p build/Release-ios-universal
117
- mkdir -p build/Release-tvos-universal
118
- lipo build/Release-iphoneos/libsimple2d.a build/Release-iphonesimulator/libsimple2d.a -create -output build/Release-ios-universal/libsimple2d.a
119
- lipo build/Release-appletvos/libsimple2d.a build/Release-appletvsimulator/libsimple2d.a -create -output build/Release-tvos-universal/libsimple2d.a
120
- mkdir -p build/ios build/tvos
121
- libtool -static build/Release-ios-universal/libsimple2d.a deps/ios/SDL2.framework/SDL2 -o build/ios/Simple2D
122
- libtool -static build/Release-tvos-universal/libsimple2d.a deps/tvos/SDL2.framework/SDL2 -o build/tvos/Simple2D
123
- mkdir -p build/ios/Simple2D.framework/Headers
124
- mkdir -p build/tvos/Simple2D.framework/Headers
125
- cp include/simple2d.h build/ios/Simple2D.framework/Headers
126
- cp include/simple2d.h build/tvos/Simple2D.framework/Headers
127
- cp -R deps/ios/include/SDL2 build/ios/Simple2D.framework/Headers
128
- cp -R deps/tvos/include/SDL2 build/tvos/Simple2D.framework/Headers
129
- cp deps/xcode/Info.plist build/ios/Simple2D.framework/Info.plist
130
- cp deps/xcode/Info.plist build/tvos/Simple2D.framework/Info.plist
131
- mv build/ios/Simple2D build/ios/Simple2D.framework
132
- mv build/tvos/Simple2D build/tvos/Simple2D.framework
133
- $(call info_msg,iOS framework built at \`build/ios/Simple2D.framework\`)
134
- $(call info_msg,tvOS framework built at \`build/tvos/Simple2D.framework\`)
135
- endif
136
-
137
- ifeq ($(PLATFORM),apple)
138
- install-frameworks: install
139
- ifeq ($(shell test -d build/ios/Simple2D.framework && test -d build/tvos/Simple2D.framework; echo $$?),1)
140
- $(error Frameworks missing. Run `frameworks` target first)
141
- endif
142
- $(call task_msg,Installing iOS and tvOS frameworks)
143
- mkdir -p $(PREFIX)/Frameworks/Simple2D/iOS/
144
- mkdir -p $(PREFIX)/Frameworks/Simple2D/tvOS/
145
- cp -R build/ios/Simple2D.framework $(PREFIX)/Frameworks/Simple2D/iOS/
146
- cp -R build/tvos/Simple2D.framework $(PREFIX)/Frameworks/Simple2D/tvOS/
147
- endif
148
-
149
- ifeq ($(PLATFORM),apple)
150
- release: clean frameworks
151
- $(call task_msg,Building iOS and tvOS release)
152
- mkdir -p build/$(APPLE_RELEASE)/Simple2D/iOS
153
- mkdir -p build/$(APPLE_RELEASE)/Simple2D/tvOS
154
- cp -R build/ios/* build/$(APPLE_RELEASE)/Simple2D/iOS/
155
- cp -R build/tvos/* build/$(APPLE_RELEASE)/Simple2D/tvOS/
156
- cd build; zip -rq $(APPLE_RELEASE).zip $(APPLE_RELEASE)
157
- $(call info_msg,Frameworks zipped at \`build/$(APPLE_RELEASE).zip\`)
158
- endif
159
-
160
- ifeq ($(PLATFORM),mingw)
161
- release: clean all
162
- mkdir -p build/$(MINGW_RELEASE)/include
163
- mkdir -p build/$(MINGW_RELEASE)/lib
164
- mkdir -p build/$(MINGW_RELEASE)/bin
165
- cp -R deps/mingw/include/* build/$(MINGW_RELEASE)/include
166
- cp -R deps/mingw/lib/* build/$(MINGW_RELEASE)/lib
167
- cp -R deps/mingw/bin/* build/$(MINGW_RELEASE)/bin
168
- cp deps/LICENSES.md build/$(MINGW_RELEASE)
169
- cp include/simple2d.h build/$(MINGW_RELEASE)/include
170
- cp build/libsimple2d.a build/$(MINGW_RELEASE)/lib
171
- cp build/simple2d build/$(MINGW_RELEASE)/bin
172
- cp bin/win-installer-mingw.sh build/$(MINGW_RELEASE)/install.sh
173
- PowerShell -Command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::CreateFromDirectory('build/$(MINGW_RELEASE)', 'build/\$(MINGW_RELEASE).zip'); }"
174
- endif
175
-
176
- clean:
177
- $(call task_msg,Cleaning)
178
- rm -rf build/*
179
- ifeq ($(PLATFORM),mingw)
180
- rm -f test/auto.exe
181
- rm -f test/triangle.exe
182
- rm -f test/testcard.exe
183
- rm -f test/audio.exe
184
- rm -f test/controller.exe
185
- else
186
- rm -f test/auto
187
- rm -f test/triangle
188
- rm -f test/testcard
189
- rm -f test/audio
190
- rm -f test/controller
191
- endif
192
-
193
- uninstall:
194
- $(call task_msg,Uninstalling)
195
- rm -f /usr/local/include/simple2d.h
196
- rm -f /usr/local/lib/libsimple2d.a
197
- rm -f /usr/local/bin/simple2d
198
- ifeq ($(PLATFORM),apple)
199
- rm -rf /usr/local/Frameworks/Simple2D
200
- endif
201
-
202
- test:
203
- $(call task_msg,Building tests)
204
- simple2d build test/auto.c
205
- simple2d build test/triangle.c
206
- simple2d build test/testcard.c
207
- simple2d build test/audio.c
208
- simple2d build test/controller.c
209
-
210
- rebuild: uninstall clean all install test
211
-
212
- auto:
213
- $(call run_test,auto)
214
-
215
- triangle:
216
- $(call run_test,triangle)
217
-
218
- testcard:
219
- $(call run_test,testcard)
220
-
221
- audio:
222
- $(call run_test,audio)
223
-
224
- controller:
225
- $(call run_test,controller)
226
-
227
- ifeq ($(PLATFORM),apple)
228
- ios:
229
- ifeq ($(shell test -d /usr/local/Frameworks/Simple2D/iOS/Simple2D.framework; echo $$?),1)
230
- $(error Simple2D.framework missing for iOS. Run `frameworks` and `install-frameworks` targets first)
231
- endif
232
- $(call task_msg,Running iOS test)
233
- mkdir -p build/ios
234
- cp -R deps/xcode/ios/* build/ios
235
- cp test/triangle-ios-tvos.c build/ios/main.c
236
- simple2d build --ios build/ios/MyApp.xcodeproj
237
- simple2d simulator --open "iPhone X"
238
- simple2d simulator --install "build/ios/build/Release-iphonesimulator/MyApp.app"
239
- simple2d simulator --launch "Simple2D.MyApp"
240
- endif
241
-
242
- ifeq ($(PLATFORM),apple)
243
- tvos:
244
- ifeq ($(shell test -d /usr/local/Frameworks/Simple2D/tvOS/Simple2D.framework; echo $$?),1)
245
- $(error Simple2D.framework missing for tvOS. Run `frameworks` and `install-frameworks` targets first)
246
- endif
247
- $(call task_msg,Running tvOS test)
248
- mkdir -p build/tvos
249
- cp -R deps/xcode/tvos/* build/tvos
250
- cp test/triangle-ios-tvos.c build/tvos/main.c
251
- simple2d build --tvos build/tvos/MyApp.xcodeproj
252
- simple2d simulator --open "Apple TV 4K"
253
- simple2d simulator --install "build/tvos/build/Release-appletvsimulator/MyApp.app"
254
- simple2d simulator --launch "Simple2D.MyApp"
255
- endif
256
-
257
- .PHONY: build test
@@ -1,1312 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- # ------------------------------------------------------------------------------
4
- # The Simple 2D Command-Line Utility for Unix-like Systems
5
- #
6
- # Run from the web using:
7
- # bash <(curl -fsSL https://script_url_here)
8
- # or...
9
- # bash <(wget -qO - https://script_url_here)
10
- # ------------------------------------------------------------------------------
11
-
12
- # Set Constants ################################################################
13
-
14
- # The installed version
15
- VERSION='1.1.0'
16
-
17
- # URL to this script in the repo
18
- SCRIPT_URL="https://raw.githubusercontent.com/simple2d/simple2d/master/bin/simple2d.sh"
19
-
20
- # MinGW Simple 2D installer
21
- s2d_mingw_installer_fname="simple2d-windows-mingw-${VERSION}.zip"
22
- s2d_mingw_installer_url="https://github.com/simple2d/simple2d/releases/download/v${VERSION}/${s2d_mingw_installer_fname}"
23
-
24
- # SDL minimum version
25
- SDL_MIN_VERSION='2.0.4'
26
-
27
- # SDL download paths
28
- libsdl_url="https://www.libsdl.org"
29
-
30
- sdl_fname="SDL2-2.0.9"
31
- sdl_url="${libsdl_url}/release/${sdl_fname}.tar.gz"
32
-
33
- image_fname="SDL2_image-2.0.4"
34
- image_url="${libsdl_url}/projects/SDL_image/release/${image_fname}.tar.gz"
35
-
36
- mixer_fname="SDL2_mixer-2.0.4"
37
- mixer_url="${libsdl_url}/projects/SDL_mixer/release/${mixer_fname}.tar.gz"
38
-
39
- ttf_fname="SDL2_ttf-2.0.14"
40
- ttf_url="${libsdl_url}/projects/SDL_ttf/release/${ttf_fname}.tar.gz"
41
-
42
- # SDL config
43
- sdl_arm_config_flags="\
44
- --disable-video-opengl --disable-video-x11 \
45
- --disable-pulseaudio --disable-esd \
46
- --disable-video-mir --disable-video-wayland"
47
-
48
- # Colors
49
- BOLD='\033[1;39m' # default, bold
50
- UNDERLINE='\033[4m' # underline
51
- TASK='\033[1;34m' # blue, bold
52
- BLUE=$TASK
53
- INFO='\033[1;36m' # cyan, underline
54
- WARN='\033[1;33m' # yellow, underline
55
- ERROR='\033[1;31m' # red, underline
56
- SUCCESS='\033[1;32m' # green, bold
57
- NORMAL='\033[0m' # reset
58
-
59
- # Set Variables ################################################################
60
-
61
- platform='unknown'
62
- platform_display='unknown'
63
- platform_rpi=false
64
- ret='' # for storing function return values
65
- confirmed=false # to skip confirmation prompts
66
-
67
- # Use xcpretty for nicer output: gem install xcpretty
68
- if xcpretty -v &>/dev/null; then
69
- XCPRETTY=xcpretty
70
- else
71
- XCPRETTY=cat
72
- fi
73
-
74
- # Helper Functions #############################################################
75
-
76
-
77
- # Prints an information messages
78
- # params:
79
- # $1 String Message text
80
- info_msg() {
81
- echo -e "${INFO}Info:${NORMAL} $1\n"
82
- }
83
- warning_msg() {
84
- echo -e "${WARN}Warning:${NORMAL} $1\n"
85
- }
86
- error_msg() {
87
- echo -e "${ERROR}Error:${NORMAL} $1\n"
88
- }
89
- success_msg() {
90
- echo -e "${SUCCESS}$1${NORMAL}\n"
91
- }
92
-
93
-
94
- # Prompts to continue, or exits
95
- # params:
96
- # $1 String Message before y/n prompt
97
- prompt_to_continue() {
98
- if ! $confirmed; then
99
- printf "${BOLD}$1${NORMAL} "
100
- read -p "(y/n) " ans
101
- if [[ $ans != "y" ]]; then
102
- echo -e "\nQuitting...\n"
103
- exit
104
- fi
105
- echo
106
- fi
107
- }
108
-
109
-
110
- # Prints the task in progress
111
- # params:
112
- # $1 String Name of task
113
- # $2 String Optional white space, e.g. "\n\n"
114
- print_task() {
115
- printf "${TASK}==>${BOLD} $1${NORMAL}$2"
116
- }
117
-
118
-
119
- # Prints and runs a command
120
- # params:
121
- # $1 String The command
122
- print_and_run() {
123
- echo "==> $1"; $1
124
- }
125
-
126
-
127
- # Checks if a library is installed
128
- # params:
129
- # $1 String Name of the library, e.g. SDL2, without the "-l"
130
- have_lib?() {
131
- print_task "Checking for $1... "
132
-
133
- if $(ld -o /dev/null -l$1 2>&1 | grep -qE '(library not found|ld: cannot find -l)'); then
134
- echo "no"
135
- return 1
136
- else
137
- echo "yes"
138
- return 0
139
- fi
140
- }
141
-
142
-
143
- # Gets the text from a remote resource
144
- # params:
145
- # $1 String URL of the resource
146
- get_remote_str() {
147
- which curl &>/dev/null && cmd='curl -fsSL' || cmd='wget -qO -';
148
- ret=$($cmd $1)
149
- }
150
-
151
-
152
- # Compares version numbers in the form `#.#.#`
153
- # Adapted from:
154
- # stackoverflow.com/questions/4023830/bash-how-compare-two-strings-in-version-format
155
- # params:
156
- # $1 String First version number to compare
157
- # $2 String Second version number to compare
158
- # returns:
159
- # 0 If $1 is equal to $2
160
- # 1 If $1 is newer than $2
161
- # 2 If $1 is older than $2
162
- compare_versions() {
163
- if [[ $1 == $2 ]]
164
- then
165
- return 0
166
- fi
167
- local IFS=.
168
- local i ver1=($1) ver2=($2)
169
- # fill empty fields in ver1 with zeros
170
- for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
171
- do
172
- ver1[i]=0
173
- done
174
- for ((i=0; i<${#ver1[@]}; i++))
175
- do
176
- if [[ -z ${ver2[i]} ]]
177
- then
178
- # fill empty fields in ver2 with zeros
179
- ver2[i]=0
180
- fi
181
- if ((10#${ver1[i]} > 10#${ver2[i]}))
182
- then
183
- return 1
184
- fi
185
- if ((10#${ver1[i]} < 10#${ver2[i]}))
186
- then
187
- return 2
188
- fi
189
- done
190
- return 0
191
- }
192
-
193
-
194
- # Build #######################################################################
195
-
196
-
197
- # Builds a Simple 2D program
198
- # If directory contains an Xcode project, it will call `xcodebuild`.
199
- # If $1 is a C or C++ source file, it will attempt to compile using `gcc`.
200
- build() {
201
-
202
- # If no input, print build usage
203
- if [[ $1 == '' ]]; then print_usage_build; exit; fi
204
-
205
- # If C or C++ source file given, e.g.:
206
- # build app.c; build app.cpp
207
- if [[ ${1: -2} == '.c' || ${1: -4} == '.cpp' ]]; then
208
- # Compile
209
- gcc -std=c11 $1 `simple2d --libs` -o ${1%.*}
210
- exit
211
- fi
212
-
213
- # Check if current directory has an Xcode project
214
- has_xcodeproj?() {
215
- if [[ $(ls *.xcodeproj 2>/dev/null) ]]; then
216
- return 0
217
- else
218
- return 1
219
- fi
220
- }
221
-
222
- # Build an Xcode project
223
- build_with_xcodebuild() {
224
- if [[ $XCPRETTY != 'xcpretty' ]]; then
225
- echo -e "xcpretty not found: Run \`gem install xcpretty\` for nicer xcodebuild output.\n"
226
- fi
227
- case $1 in
228
- --ios)
229
- xcodebuild -sdk iphonesimulator | $XCPRETTY; exit;;
230
- --ios-device)
231
- xcodebuild -sdk iphoneos | $XCPRETTY; exit;;
232
- --tvos)
233
- xcodebuild -sdk appletvsimulator | $XCPRETTY; exit;;
234
- --tvos-device)
235
- xcodebuild -sdk appletvos | $XCPRETTY; exit;;
236
- esac
237
- }
238
-
239
- # If bad SDK flag, print build usage
240
- if ! [[ $1 =~ ^(--ios|--ios-device|--tvos|--tvos-device)$ ]]; then
241
- print_usage_build; exit 1
242
- fi
243
-
244
- # If current directory has an Xcode project, e.g.:
245
- # build --[ios|tvos][-device]
246
- if has_xcodeproj?; then
247
- build_with_xcodebuild $1
248
- fi
249
-
250
- # If an Xcode project path and options are provided, e.g.:
251
- # build --ios[-device] build/ios
252
- # build --tvos[-device] build/tvos
253
- # build --ios[-device] build/ios/MyApp.xcodeproj
254
- # build --tvos[-device] build/tvos/MyApp.xcodeproj
255
- if [[ ${2: -10} == '.xcodeproj' ]]; then
256
- cd $(dirname $2)
257
- elif [[ -d $2 ]]; then
258
- cd $2
259
- else
260
- error_msg "\"$2\" is not a directory or Xcode project"; exit 1
261
- fi
262
-
263
- if ! has_xcodeproj?; then
264
- error_msg "The directory does not contain an Xcode project"; exit 1
265
- fi
266
-
267
- build_with_xcodebuild $1
268
- }
269
-
270
-
271
- # Installation #################################################################
272
-
273
-
274
- # Checks installed versions of SDL
275
- check_sdl_versions() {
276
-
277
- print_task "Checking SDL2 version... "
278
-
279
- # Check SDL version installed
280
- SDL_INSTALLED_VERSION=$(sdl2-config --version)
281
- compare_versions $SDL_MIN_VERSION $SDL_INSTALLED_VERSION
282
-
283
- if [[ $? == 1 ]]; then
284
- echo $SDL_INSTALLED_VERSION
285
- error_msg "Installed version of SDL2 is too old (must be at least $SDL_MIN_VERSION)"
286
- return 1
287
- else
288
- echo "$SDL_INSTALLED_VERSION"
289
- return 0
290
- fi
291
- }
292
-
293
-
294
- # Checks if SDL libraries are installed
295
- have_sdl_libs?() {
296
-
297
- have_all_libs=true
298
- have_sdl2_lib=true
299
- have_image_lib=true
300
- have_mixer_lib=true
301
- have_ttf_lib=true
302
-
303
- if ! have_lib? 'SDL2'; then
304
- have_sdl2_lib=false
305
- have_all_libs=false
306
- else
307
- if ! check_sdl_versions; then
308
- have_sdl2_lib=false
309
- have_all_libs=false
310
- fi
311
- fi
312
-
313
- if ! have_lib? 'SDL2_image'; then
314
- have_image_lib=false
315
- have_all_libs=false
316
- fi
317
-
318
- if ! have_lib? 'SDL2_mixer'; then
319
- have_mixer_lib=false
320
- have_all_libs=false
321
- fi
322
-
323
- if ! have_lib? 'SDL2_ttf'; then
324
- have_ttf_lib=false
325
- have_all_libs=false
326
- fi
327
-
328
- if $have_all_libs; then
329
- return 0
330
- else
331
- return 1
332
- fi
333
- }
334
-
335
-
336
- # Installs SDL on BSD
337
- install_sdl_bsd() {
338
-
339
- echo "The following packages will be installed:"
340
- echo " sdl2"
341
- echo " sdl2_image"
342
- echo " sdl2_mixer"
343
- echo " sdl2_ttf"
344
-
345
- prompt_to_continue "Install SDL now?"
346
-
347
- print_task "Updating packages" "\n\n"
348
- print_and_run "sudo pkg update"
349
-
350
- echo; print_task "Installing packages" "\n\n"
351
- print_and_run "sudo pkg install sdl2 sdl2_image sdl2_mixer sdl2_ttf"
352
- echo
353
-
354
- if ! have_sdl_libs?; then
355
- echo; error_msg "SDL libraries did not install correctly"; exit 1
356
- else
357
- echo; info_msg "SDL was installed successfully"
358
- fi
359
- }
360
-
361
-
362
- # Installs SDL on Linux
363
- install_sdl_linux() {
364
-
365
- echo "The following packages will be installed:"
366
- # Fedora and CentOS
367
- if which yum &>/dev/null; then
368
- echo " SDL2-devel"
369
- echo " SDL2_image-devel"
370
- echo " SDL2_mixer-devel"
371
- echo " SDL2_ttf-devel"
372
- # Arch
373
- elif which pacman &>/dev/null; then
374
- echo " sdl2"
375
- echo " sdl2_image"
376
- echo " sdl2_mixer"
377
- echo " sdl2_ttf"
378
- # openSUSE
379
- elif which zypper &>/dev/null; then
380
- echo " libSDL2-devel"
381
- echo " libSDL2_image-devel"
382
- echo " libSDL2_mixer-devel"
383
- echo " libSDL2_ttf-devel"
384
- # Ubuntu, Debian, and Mint
385
- # `apt` must be last because openSUSE has it aliased to `zypper`
386
- elif which apt &>/dev/null; then
387
- echo " libsdl2-dev"
388
- echo " libsdl2-image-dev"
389
- echo " libsdl2-mixer-dev"
390
- echo " libsdl2-ttf-dev"
391
- else
392
- error_msg "Could not find a package manager to install SDL"; exit 1
393
- fi
394
- echo
395
-
396
- prompt_to_continue "Install SDL now?"
397
-
398
- print_task "Updating packages" "\n\n"
399
-
400
- if which yum &>/dev/null; then
401
- print_and_run "yum check-update"
402
- elif which pacman &>/dev/null; then
403
- print_and_run "sudo pacman -Syy"
404
- elif which zypper &>/dev/null; then
405
- print_and_run "sudo zypper refresh"
406
- elif which apt &>/dev/null; then
407
- print_and_run "sudo apt update"
408
- fi
409
-
410
- echo; print_task "Installing packages" "\n\n"
411
-
412
- if which yum &>/dev/null; then
413
- print_and_run "sudo yum install -y SDL2-devel SDL2_image-devel SDL2_mixer-devel SDL2_ttf-devel"
414
- elif which pacman &>/dev/null; then
415
- print_and_run "sudo pacman -S --noconfirm sdl2 sdl2_image sdl2_mixer sdl2_ttf"
416
- elif which zypper &>/dev/null; then
417
- print_and_run "sudo zypper install -y libSDL2-devel libSDL2_image-devel libSDL2_mixer-devel libSDL2_ttf-devel"
418
- elif which apt &>/dev/null; then
419
- print_and_run "sudo apt install -y libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev"
420
- fi
421
- echo
422
-
423
- if ! have_sdl_libs?; then
424
- echo; error_msg "SDL libraries did not install correctly"; exit 1
425
- else
426
- echo; info_msg "SDL was installed successfully"
427
- fi
428
- }
429
-
430
-
431
- # Installs SDL from source
432
- # Takes about 30 min on RPI 2
433
- install_sdl_source() {
434
-
435
- echo "SDL will be compiled and installed from source."; echo
436
-
437
- prompt_to_continue "Install SDL now?"
438
-
439
- # Install SDL dependencies
440
- print_task "Installing SDL2 dependencies" "\n\n"
441
- sudo apt update
442
-
443
- libs=(
444
- build-essential # This may be missing on some ARM platforms
445
-
446
- # SDL2
447
- libudev-dev
448
- libdbus-1-dev
449
- libasound2-dev
450
-
451
- # SDL2_image
452
- libjpeg9-dev
453
- libpng-dev
454
-
455
- # SDL2_mixer
456
- libmpg123-dev
457
- libvorbis-dev
458
- libflac-dev
459
-
460
- # SDL2_ttf
461
- libgl1-mesa-dev # Solves error missing -lGL
462
- libfreetype6-dev
463
- )
464
-
465
- sudo apt install -y ${libs[*]}
466
-
467
- # Downloads, compiles, and installs an SDL library from source
468
- # params:
469
- # $1 String URL of the tar archive
470
- # $2 String Name of the tar file
471
- # $3 String ./configure flags
472
- install_sdl_lib () {
473
- cd /tmp
474
- wget -N $1
475
- tar -xzf $2.tar.gz
476
- cd $2
477
- print_task "Configuring" "\n\n"
478
- print_and_run "./configure $3"
479
- echo; print_task "Compiling" "\n\n"
480
- make
481
- echo; print_task "Installing" "\n\n"
482
- sudo make install
483
- rm /tmp/$2.tar.gz
484
- rm -rf /tmp/$2
485
- }
486
-
487
- # Note that `$have_*_lib` variables are set by `have_sdl_libs?()`
488
-
489
- if [[ $have_sdl2_lib == 'false' ]]; then
490
- echo; print_task "Downloading SDL2" "\n\n"
491
- if [[ $platform == 'arm' ]]; then
492
- if $platform_rpi; then
493
- config="--host=arm-raspberry-linux-gnueabihf $sdl_arm_config_flags"
494
- else
495
- config=$sdl_arm_config_flags
496
- fi
497
- install_sdl_lib $sdl_url $sdl_fname "$config"
498
- else
499
- install_sdl_lib $sdl_url $sdl_fname
500
- fi
501
- fi
502
-
503
- if [[ $have_image_lib == 'false' ]]; then
504
- echo; print_task "Downloading SDL2_image" "\n\n"
505
- install_sdl_lib $image_url $image_fname
506
- fi
507
-
508
- if [[ $have_mixer_lib == 'false' ]]; then
509
- echo; print_task "Downloading SDL2_mixer" "\n\n"
510
- install_sdl_lib $mixer_url $mixer_fname
511
- fi
512
-
513
- if [[ $have_ttf_lib == 'false' ]]; then
514
- echo; print_task "Downloading SDL2_ttf" "\n\n"
515
- install_sdl_lib $ttf_url $ttf_fname
516
- fi
517
-
518
- echo
519
- if ! have_sdl_libs?; then
520
- error_msg "SDL libraries did not install correctly"; exit 1
521
- else
522
- echo; info_msg "SDL was installed successfully"
523
- fi
524
- }
525
-
526
-
527
- # Installs SDL
528
- install_sdl() {
529
- if [[ $platform == 'linux' ]]; then
530
- install_sdl_linux
531
- elif [[ $platform == 'bsd' ]]; then
532
- install_sdl_bsd
533
- elif [[ $platform == 'arm' ]]; then
534
- install_sdl_source
535
- fi
536
- }
537
-
538
-
539
- # Installs Simple 2D for MinGW environments
540
- install_s2d_mingw() {
541
- tmp_dir="/tmp/simple2d"
542
- mkdir -p $tmp_dir
543
- print_and_run "wget -NP $tmp_dir $s2d_mingw_installer_url"
544
- print_and_run "pacman -S unzip --needed --noconfirm"
545
- print_and_run "unzip -q $tmp_dir/$s2d_mingw_installer_fname -d $tmp_dir"
546
- print_and_run "cd $tmp_dir"
547
- print_and_run "bash install.sh -y"
548
- print_and_run "rm -rf $tmp_dir"
549
- }
550
-
551
-
552
- # Installs Simple 2D
553
- # params:
554
- # $1 String Version to install, either 'master' or $VERSION
555
- install_s2d() {
556
-
557
- tmp_dir="/tmp/simple2d"
558
-
559
- mkdir $tmp_dir
560
-
561
- if [[ $1 == 'master' ]]; then
562
- f_name=$1
563
- else
564
- f_name="v$1"
565
- fi
566
-
567
- url="https://github.com/simple2d/simple2d/archive/$f_name.zip"
568
-
569
- print_task "Downloading Simple 2D" "\n\n"
570
- # Linux and Raspberry Pi may not have curl installed by default
571
- if which curl &>/dev/null; then
572
- print_and_run "curl -L $url -o $tmp_dir/$f_name.zip"
573
- else
574
- print_and_run "wget -NP $tmp_dir $url"
575
- fi
576
-
577
- # Check if archive was downloaded properly
578
- if [[ ! -f "$tmp_dir/$f_name.zip" ]]; then
579
- echo; error_msg "Simple 2D could not be downloaded"; exit 1
580
- fi
581
-
582
- echo; print_task "Unpacking" "\n\n"
583
- print_and_run "unzip -q $tmp_dir/$f_name.zip -d $tmp_dir"
584
-
585
- # Check if archive was unpacked properly
586
- if [[ $? != 0 ]]; then
587
- echo; error_msg "Could not unpack. The downloaded Simple 2D package may be damaged."; exit 1
588
- fi
589
-
590
- print_and_run "cd $tmp_dir/simple2d-$1"
591
-
592
- if [[ $platform == 'bsd' ]]; then
593
- echo; print_and_run "gmake"
594
- echo; print_and_run "sudo gmake install"
595
- else
596
- echo; print_and_run "make"
597
- echo; print_and_run "sudo make install"
598
- fi
599
-
600
- echo; print_task "Cleaning up" "\n"; echo
601
- print_and_run "rm -rf $tmp_dir"; echo
602
-
603
- # Check if S2D installed correctly
604
- if ! have_lib? 'simple2d'; then
605
- echo; error_msg "Simple 2D did not install correctly"; exit 1
606
- fi
607
- echo
608
- }
609
-
610
-
611
- # Main entry point to install Simple 2D and SDL
612
- # params:
613
- # $1 String Flags used, e.g. `--sdl`
614
- install() {
615
-
616
- # If macOS, print message and quit
617
- if [[ $platform == 'macos' ]]; then
618
- macos_homebrew_message $1
619
- fi
620
-
621
- # If SDL flag, install only SDL and quit
622
- if [[ $1 == '--sdl' ]]; then
623
- echo
624
- if have_sdl_libs?; then
625
- echo; info_msg "SDL is already installed"
626
- else
627
- echo; install_sdl
628
- fi
629
- exit
630
- fi
631
-
632
- # Welcome message
633
- echo -e "\n${BOLD}Welcome to Simple 2D!${NORMAL}"
634
- echo -e "${BLUE}---------------------${NORMAL}\n"
635
-
636
- echo -e "Platform detected: ${BOLD}${platform_display}${NORMAL}\n"
637
-
638
- # If MinGW, install Simple 2D release and quit
639
- if [[ $platform == 'mingw' ]]; then
640
- prompt_to_continue "Continue to install?"
641
- install_s2d_mingw
642
- exit
643
- fi
644
-
645
- if have_lib? 'simple2d' > /dev/null; then
646
- warning_msg "Simple 2D is already installed. Proceeding will reinstall."
647
- fi
648
-
649
- echo -e "Simple 2D will be installed to the following locations:
650
- /usr/local/include/simple2d.h
651
- /usr/local/lib/libsimple2d.a
652
- /usr/local/bin/simple2d"
653
- echo
654
-
655
- if [[ $1 == '--HEAD' ]]; then
656
- echo -e "This will install Simple 2D from the \`master\` development branch.\n"
657
- fi
658
-
659
- prompt_to_continue "Continue?"
660
-
661
- if have_sdl_libs?; then
662
- echo
663
- else
664
- echo; install_sdl
665
- fi
666
-
667
- if [[ $1 == '--HEAD' ]]; then
668
- install_s2d 'master'
669
- else
670
- install_s2d $VERSION
671
- fi
672
-
673
- success_msg "Simple 2D installed successfully!"
674
- }
675
-
676
-
677
- # Uninstall ####################################################################
678
-
679
-
680
- # Uninstalls SDL on BSD
681
- uninstall_sdl_bsd() {
682
-
683
- echo "The following packages will be removed:"
684
- echo " sdl2"
685
- echo " sdl2_image"
686
- echo " sdl2_mixer"
687
- echo " sdl2_ttf"
688
-
689
- prompt_to_continue "Uninstall SDL now?"
690
-
691
- echo; print_task "Uninstalling packages" "\n\n"
692
- print_and_run "sudo pkg remove sdl2 sdl2_image sdl2_mixer sdl2_ttf"
693
- echo
694
-
695
- if have_sdl_libs?; then
696
- echo; error_msg "SDL libraries did not uninstall correctly"
697
- else
698
- echo; info_msg "SDL was uninstalled successfully"
699
- fi
700
- }
701
-
702
-
703
- # Uninstalls SDL on Linux
704
- uninstall_sdl_linux() {
705
-
706
- echo "The following packages will be removed:"
707
- # Fedora and CentOS
708
- if which yum &>/dev/null; then
709
- echo " SDL2-devel"
710
- echo " SDL2_image-devel"
711
- echo " SDL2_mixer-devel"
712
- echo " SDL2_ttf-devel"
713
- # Arch
714
- elif which pacman &>/dev/null; then
715
- echo " sdl2"
716
- echo " sdl2_image"
717
- echo " sdl2_mixer"
718
- echo " sdl2_ttf"
719
- # openSUSE
720
- elif which zypper &>/dev/null; then
721
- echo " libSDL2-devel"
722
- echo " libSDL2_image-devel"
723
- echo " libSDL2_mixer-devel"
724
- echo " libSDL2_ttf-devel"
725
- # Ubuntu, Debian, and Mint
726
- # `apt` must be last because openSUSE has it aliased to `zypper`
727
- elif which apt &>/dev/null; then
728
- echo " libsdl2-dev"
729
- echo " libsdl2-image-dev"
730
- echo " libsdl2-mixer-dev"
731
- echo " libsdl2-ttf-dev"
732
- else
733
- error_msg "Could not find a package manager to uninstall SDL"; exit 1
734
- fi
735
- echo
736
-
737
- prompt_to_continue "Uninstall SDL now?"
738
-
739
- print_task "Uninstalling packages" "\n\n"
740
-
741
- if which yum &>/dev/null; then
742
- print_and_run "sudo yum remove -y SDL2-devel SDL2_image-devel SDL2_mixer-devel SDL2_ttf-devel"
743
- elif which pacman &>/dev/null; then
744
- print_and_run "sudo pacman -Rs --noconfirm sdl2 sdl2_image sdl2_mixer sdl2_ttf"
745
- elif which zypper &>/dev/null; then
746
- print_and_run "sudo zypper remove -y libSDL2-devel libSDL2_image-devel libSDL2_mixer-devel libSDL2_ttf-devel"
747
- elif which apt &>/dev/null; then
748
- print_and_run "sudo apt remove -y --purge libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev"
749
- fi
750
- echo
751
-
752
- if have_sdl_libs?; then
753
- echo; error_msg "SDL libraries did not uninstall correctly"
754
- else
755
- echo; info_msg "SDL was uninstalled successfully"
756
- fi
757
- }
758
-
759
-
760
- # Uninstalls SDL from source
761
- uninstall_sdl_source() {
762
-
763
- prompt_to_continue "Uninstall SDL now?"
764
-
765
- # Uninstall packages in case they were used
766
- print_and_run "sudo apt remove -y --purge libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev"
767
-
768
- uninstall_sdl_lib () {
769
- cd /tmp
770
- wget -N $1
771
- tar -xzf $2.tar.gz
772
- cd $2
773
- ./configure $3
774
- sudo make uninstall
775
- rm /tmp/$2.tar.gz
776
- rm -rf /tmp/$2
777
- }
778
-
779
- echo; print_task "Uninstalling SDL2_image" "\n\n"
780
- uninstall_sdl_lib $image_url $image_fname
781
-
782
- echo; print_task "Uninstalling SDL2_mixer" "\n\n"
783
- uninstall_sdl_lib $mixer_url $mixer_fname
784
-
785
- echo; print_task "Uninstalling SDL2_ttf" "\n\n"
786
- uninstall_sdl_lib $ttf_url $ttf_fname
787
-
788
- echo; print_task "Uninstalling SDL2" "\n\n"
789
- if [[ $platform == 'arm' ]]; then
790
- uninstall_sdl_lib $sdl_url $sdl_fname "$sdl_arm_config_flags"
791
- else
792
- uninstall_sdl_lib $sdl_url $sdl_fname
793
- fi
794
-
795
- echo
796
- if have_sdl_libs?; then
797
- echo; error_msg "SDL libraries did not uninstall correctly"; exit 1
798
- else
799
- echo; info_msg "SDL was uninstalled successfully"
800
- fi
801
- }
802
-
803
-
804
- # Uninstalls SDL
805
- uninstall_sdl() {
806
-
807
- if have_sdl_libs?; then
808
- echo
809
- else
810
- echo; info_msg "SDL appears to be already uninstalled"
811
- prompt_to_continue "Try uninstalling SDL anyways?"
812
- fi
813
-
814
- if [[ $platform == 'linux' ]]; then
815
- uninstall_sdl_linux
816
- elif [[ $platform == 'bsd' ]]; then
817
- uninstall_sdl_bsd
818
- elif [[ $platform == 'arm' ]]; then
819
- uninstall_sdl_source
820
- fi
821
- }
822
-
823
-
824
- # Uninstalls Simple 2D
825
- # params:
826
- # $1 String Flags used, e.g. `--sdl`
827
- uninstall() {
828
-
829
- if [[ $platform == 'macos' ]]; then
830
- macos_homebrew_message $1
831
- fi
832
-
833
- # If MinGW, print message and quit
834
- if [[ $platform == 'mingw' ]]; then
835
- mingw_not_implemented_message
836
- fi
837
-
838
- if [[ $1 == '--sdl' ]]; then
839
- echo; uninstall_sdl
840
- exit
841
- fi
842
-
843
- echo; echo -e "The following files will be removed:
844
- /usr/local/include/simple2d.h
845
- /usr/local/lib/libsimple2d.a
846
- /usr/local/bin/simple2d"
847
-
848
- echo; prompt_to_continue "Uninstall Simple 2D?"
849
-
850
- # Use hard-coded, absolute paths for safety
851
- print_and_run "rm -f /usr/local/include/simple2d.h"
852
- print_and_run "rm -f /usr/local/lib/libsimple2d.a"
853
- print_and_run "rm -f /usr/local/bin/simple2d"
854
-
855
- # Check if files were actually deleted
856
- files=(/usr/local/include/simple2d.h
857
- /usr/local/lib/libsimple2d.a
858
- /usr/local/bin/simple2d)
859
-
860
- if [ -f ${files[0]} -o -f ${files[1]} -o -f ${files[2]} ]; then
861
- echo; error_msg "Simple 2D files could not be removed. Try using \`sudo\`?"
862
- else
863
- echo; success_msg "Simple 2D uninstalled!"
864
- fi
865
- }
866
-
867
-
868
- # Update #######################################################################
869
-
870
-
871
- # Updates Simple 2D to latest version or commit
872
- # params:
873
- # $1 String Flags used, e.g. `--HEAD`
874
- update() {
875
-
876
- if [[ $platform == 'macos' ]]; then
877
- macos_homebrew_message
878
- fi
879
-
880
- # If MinGW, print message and quit
881
- if [[ $platform == 'mingw' ]]; then
882
- mingw_not_implemented_message
883
- fi
884
-
885
- # Check if Simple 2D is installed
886
- if ! have_lib? 'simple2d' > /dev/null; then
887
- error_msg "Simple 2D isn't currently installed"
888
- echo -e "Use the \`install\` command to install Simple 2D.\n"
889
- exit 1
890
- fi
891
-
892
- # Check if SDL is installed
893
- update_check_sdl() {
894
- if have_sdl_libs?; then
895
- echo
896
- else
897
- echo; error_msg "SDL libraries missing"
898
- echo -e "Run \`simple2d install --sdl\` to install SDL.\n"
899
- exit 1
900
- fi
901
- }
902
-
903
- # Read this script from repo, get the version number
904
- get_remote_str $SCRIPT_URL
905
- LATEST_VERSION=$(bash -c "$ret" -- -v)
906
-
907
- compare_versions $LATEST_VERSION $VERSION
908
-
909
- # $LATEST_VERSION is newer $VERSION (the version installed)
910
- if [[ $? == 1 ]]; then
911
- echo -e "A new version of Simple 2D is available.\n"
912
- prompt_to_continue "Upgrade from v$VERSION to v$LATEST_VERSION?"
913
- update_check_sdl
914
- install_s2d $LATEST_VERSION
915
- success_msg "Simple 2D has been updated to $LATEST_VERSION!"
916
- echo -e "View the release notes:
917
- ${UNDERLINE}https://github.com/simple2d/simple2d/releases/latest${NORMAL}"; echo
918
-
919
- # $LATEST_VERSION is the same as installed version
920
- else
921
- echo "Simple 2D is already up to date!"
922
- fi
923
- }
924
-
925
-
926
- # Doctor #######################################################################
927
-
928
-
929
- # Runs the diagnostics
930
- doctor() {
931
-
932
- echo; echo -e "Running diagnostics...\n"
933
-
934
- errors=false
935
-
936
- if ! have_sdl_libs?; then
937
- errors=true
938
- echo; error_msg "SDL libraries missing"
939
- fi
940
-
941
- if have_lib? 'simple2d'; then
942
- echo
943
- else
944
- errors=true
945
- echo; error_msg "Simple 2D library missing"
946
- fi
947
-
948
- if $errors; then
949
- echo -e "Issues were found.\n"
950
- else
951
- success_msg "No issues found!"
952
- fi
953
- }
954
-
955
-
956
- # Simulator ####################################################################
957
-
958
-
959
- # Get list of booted iOS or tvOS simulators, store in $booted
960
- # $1 Equals 'cmd' if called from command line
961
- simulator_booted() {
962
- booted=`xcrun simctl list devices | grep Booted`
963
- if [[ $1 == 'cmd' ]]; then
964
- if [[ $booted == '' ]]; then
965
- echo "No devices are booted."
966
- else
967
- echo $booted
968
- fi
969
- fi
970
- }
971
-
972
-
973
- # List all iOS and tvOS simulator devices available
974
- simulator_list() {
975
- xcrun simctl list devices | grep -iv unavailable
976
- }
977
-
978
-
979
- # Open an iOS or tvOS simulator
980
- # $1 The device name, e.g. iPhone X
981
- # See `simulator_list` function for available names
982
- simulator_open() {
983
- device=$1
984
-
985
- # Check if device name exists
986
- if ! xcrun simctl list devices | grep -q "$device"; then
987
- error_msg "\"$device\" does not match any simulator device names"
988
- echo -e "Choose a device name from the following:\n"
989
- simulator_list
990
- exit 1
991
- fi
992
-
993
- # Get the device UDID
994
- device_udid=`xcrun simctl list devices | grep "$device" | head -n1 | egrep -wo '\([-0-9A-F]+\)' | tr -d '\(\)'`
995
- echo "Requested device: $device with UDID $device_udid"
996
- simulator_booted
997
-
998
- # If the current simulator running is not the requested device, then quit
999
- if [[ $booted != '' && $booted != *$device* ]]; then
1000
- echo "Quitting current device simulator..."
1001
- osascript -e 'quit app "Simulator"'
1002
- fi
1003
-
1004
- # Open the requsted simulator
1005
- echo "Opening $device simulator..."
1006
- open -a Simulator --args -CurrentDeviceUDID $device_udid
1007
-
1008
- # Wait for device to boot
1009
- not_booted=true
1010
- while $not_booted; do
1011
- simulator_booted
1012
- if [[ $booted == *$device* ]]; then
1013
- not_booted=false
1014
- else
1015
- sleep 2
1016
- fi
1017
- done
1018
- }
1019
-
1020
-
1021
- # Install an app on the booted iOS or tvOS simulator
1022
- # $1 The path to the `.app` file, e.g. Release-iphonesimulator/MyApp.app
1023
- simulator_install() {
1024
- echo "Installing app..."
1025
- xcrun simctl install booted $1
1026
- }
1027
-
1028
-
1029
- # Launch an installed app on the booted iOS or tvOS simulator
1030
- # $1 The bundle identifier, e.g. "Simple2D.MyApp"
1031
- simulator_launch() {
1032
- echo "Launching app..."
1033
- xcrun simctl launch booted $1
1034
- }
1035
-
1036
-
1037
- # Stream log of currently running iOS or tvOS simulator
1038
- # $1 Optional app name to filter by
1039
- simulator_log() {
1040
- if [[ $1 == '' ]]; then
1041
- xcrun simctl spawn booted log stream --level=debug
1042
- else
1043
- xcrun simctl spawn booted log stream --predicate "processImagePath endswith \"$1\""
1044
- fi
1045
- }
1046
-
1047
-
1048
- # Stream log of currently running iOS or tvOS simulator, error messages only
1049
- simulator_log_errors() {
1050
- xcrun simctl spawn booted log stream --predicate 'eventMessage contains "error" or messageType == error'
1051
- }
1052
-
1053
-
1054
- # Platform Specifics ###########################################################
1055
-
1056
-
1057
- # Prints homebrew message and quit
1058
- # params:
1059
- # $1 String The message to show, e.g. '--sdl'
1060
- macos_homebrew_message() {
1061
-
1062
- if [[ $1 == '--sdl' ]]; then
1063
- echo -e "
1064
- We recommend using ${BOLD}Homebrew${NORMAL} to install, update, and uninstall
1065
- SDL on macOS. If you installed Simple 2D using Homebrew, the
1066
- following SDL packages were installed:
1067
-
1068
- sdl2
1069
- sdl2_image
1070
- sdl2_mixer
1071
- sdl2_ttf
1072
-
1073
- Run \`brew info <formula>\` to see information about each and
1074
- their dependencies, which were also installed.
1075
-
1076
- Learn more at ${UNDERLINE}http://brew.sh${NORMAL}
1077
- "
1078
- elif [[ $1 == '--HEAD' ]]; then
1079
- echo -e "
1080
- Use ${BOLD}Homebrew${NORMAL} to install, update, and uninstall Simple 2D on macOS.
1081
-
1082
- To install the latest changes from the \`master\` development branch, use:
1083
- brew install --HEAD simple2d
1084
-
1085
- Note \`brew update\` will not update formulas installed with \`--HEAD\`,
1086
- but you can use \`brew reinstall --HEAD simple2d\` to manually grab
1087
- the latest changes.
1088
- "
1089
- else
1090
- echo -e "
1091
- Use ${BOLD}Homebrew${NORMAL} to install, update, and uninstall Simple 2D on macOS.
1092
-
1093
- First, use \`brew tap\` to get Simple 2D formulas:
1094
- brew tap simple2d/tap
1095
-
1096
- Then, the following \`brew\` commands will be available:
1097
- brew install simple2d
1098
- brew upgrade simple2d
1099
- brew uninstall simple2d
1100
-
1101
- Learn more at ${UNDERLINE}http://brew.sh${NORMAL}
1102
- "
1103
- fi
1104
-
1105
- exit
1106
- }
1107
-
1108
-
1109
- # Commands only available on macOS
1110
- macos_only_command() {
1111
- echo -e "This command is only available on macOS"; exit 1
1112
- }
1113
-
1114
-
1115
- # For stuff not yet implemented in MinGW
1116
- mingw_not_implemented_message() {
1117
- echo -e "This isn't implemented in MinGW yet :("; exit 1
1118
- }
1119
-
1120
-
1121
- # Detect Platform ##############################################################
1122
-
1123
-
1124
- unamestr=$(uname)
1125
-
1126
- # macOS
1127
- if [[ $unamestr == 'Darwin' ]]; then
1128
- platform_display='macOS'
1129
- platform='macos'
1130
-
1131
- # ARM
1132
- elif [[ $(uname -m) =~ 'arm' && $unamestr == 'Linux' ]]; then
1133
- platform_display='ARM / Linux'
1134
- platform='arm'
1135
-
1136
- # Raspberry Pi
1137
- if [[ $(cat /etc/os-release | grep -i raspbian) ]]; then
1138
- platform_display='ARM / Linux (Raspberry Pi)'
1139
- platform_rpi=true
1140
- fi
1141
-
1142
- # Linux
1143
- elif [[ $unamestr == 'Linux' ]]; then
1144
- platform_display='Linux'
1145
- platform='linux'
1146
-
1147
- # Windows / MinGW
1148
- elif [[ $unamestr =~ 'MINGW' ]]; then
1149
- platform_display='Windows / MinGW'
1150
- platform='mingw'
1151
-
1152
- # BSD
1153
- elif [[ $unamestr =~ 'BSD' ]]; then
1154
- platform_display='BSD'
1155
- platform='bsd'
1156
- fi
1157
-
1158
- # Unsupported platform
1159
- if [[ $platform == 'unknown' ]]; then
1160
- echo; error_msg "Not a supported system (macOS, Linux, or ARM platform)"; exit 1
1161
- fi
1162
-
1163
-
1164
- # Check Command-line Arguments #################################################
1165
-
1166
-
1167
- print_usage() {
1168
- echo -e "${BOLD}Simple 2D is a simple, open-source 2D graphics engine for everyone.${NORMAL}
1169
-
1170
- Usage: simple2d [--libs] [-v|--version]
1171
- <command> <options>
1172
-
1173
- Summary of commands and options:
1174
- build Build a C/C++ source file or Xcode project; run for options
1175
- install Installs the latest release
1176
- --HEAD Installs from the development branch
1177
- --sdl Installs SDL only
1178
- uninstall Removes Simple 2D files
1179
- --sdl Removes SDL only
1180
- update Updates to latest release
1181
- doctor Runs diagnostics, checks installation, reports issues
1182
- simulator Interact with iOS and tvOS simulators; run for options
1183
- --libs Outputs libraries needed to compile Simple 2D apps
1184
- -v|--version Prints the installed version
1185
- "
1186
- }
1187
-
1188
-
1189
- print_usage_build() {
1190
- echo -e "
1191
- Use the ${BOLD}build${NORMAL} command to compile or build Simple 2D apps.
1192
-
1193
- For compiling C/C++ source files, use:
1194
- build <c_or_cpp_file>
1195
-
1196
- To build an Xcode project, use:
1197
- build <sdk_option> <optional_path_to_xcode_project>
1198
-
1199
- For <sdk_option> above, use one of the following:
1200
- --ios iOS simulator SDK
1201
- --ios-device iOS device SDK (requires signing)
1202
- --tvos tvOS simulator SDK
1203
- --tvos-device tvOS device SDK (requires signing)
1204
- "
1205
- }
1206
-
1207
-
1208
- print_usage_simulator() {
1209
- echo -e "
1210
- Choose an option with the ${BOLD}simulator${NORMAL} command:
1211
-
1212
- --list List available devices
1213
- --booted Show currently booted devices
1214
-
1215
- --open <device_name> Open a simulator device with a given device name
1216
-
1217
- --install <app_file> Install an app on the booted simulator given the path
1218
- to the app e.g. \"Release-iphonesimulator/MyApp.app\"
1219
-
1220
- --launch <bundle_id> Launch an app given the app bundle's identifier,
1221
- e.g. \"Simple2D.MyApp\"
1222
-
1223
- --log Stream log of the booted simulator
1224
- --log <app> Stream log for the app only, given the app name
1225
- --log-errors Stream log containing only error messages
1226
- "
1227
- }
1228
-
1229
-
1230
- case $1 in
1231
- build)
1232
- build $2 $3;;
1233
- install)
1234
- case $2 in
1235
- '')
1236
- install;;
1237
- -y)
1238
- confirmed=true
1239
- install;;
1240
- --HEAD)
1241
- install '--HEAD';;
1242
- --sdl)
1243
- install '--sdl';;
1244
- *)
1245
- print_usage;;
1246
- esac;;
1247
- uninstall)
1248
- case $2 in
1249
- '')
1250
- uninstall;;
1251
- --sdl)
1252
- uninstall '--sdl';;
1253
- *)
1254
- print_usage;;
1255
- esac;;
1256
- update)
1257
- case $2 in
1258
- '')
1259
- update;;
1260
- --HEAD)
1261
- update '--HEAD';;
1262
- *)
1263
- print_usage;;
1264
- esac;;
1265
- doctor)
1266
- doctor;;
1267
- simulator)
1268
- if [[ $platform != 'macos' ]]; then macos_only_command; fi
1269
- case $2 in
1270
- '')
1271
- print_usage_simulator;;
1272
- --list)
1273
- simulator_list;;
1274
- --booted)
1275
- simulator_booted 'cmd';;
1276
- --open)
1277
- simulator_open "$3";;
1278
- --install)
1279
- simulator_install "$3";;
1280
- --launch)
1281
- simulator_launch "$3";;
1282
- --log)
1283
- simulator_log "$3";;
1284
- --log-errors)
1285
- simulator_log_errors;;
1286
- *)
1287
- print_usage_simulator;;
1288
- esac;;
1289
- --libs)
1290
- if [[ $platform == 'macos' ]]; then
1291
- FLAGS='-Wl,-framework,OpenGL'
1292
- elif [[ $platform == 'linux' || $platform == 'bsd' ]]; then
1293
- FLAGS='-lGL -lm'
1294
- elif [[ $platform == 'arm' ]]; then
1295
- FLAGS='-lm -I/opt/vc/include/ -L/opt/vc/lib'
1296
- if $platform_rpi; then
1297
- FLAGS+=' -lbrcmGLESv2'
1298
- else
1299
- FLAGS+=' -lGLESv2'
1300
- fi
1301
- fi
1302
- if [[ $platform == 'mingw' ]]; then
1303
- echo "-I/usr/local/include/ -L/usr/local/lib -lmingw32 -lsimple2d -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lopengl32 -lglew32"
1304
- else
1305
- echo "-lsimple2d `sdl2-config --cflags --libs`"\
1306
- "${FLAGS} -lSDL2_image -lSDL2_mixer -lSDL2_ttf"
1307
- fi;;
1308
- -v|--version)
1309
- echo $VERSION;;
1310
- *)
1311
- print_usage;;
1312
- esac