ruby2d 0.9.4 → 0.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -96,7 +96,7 @@ def build_native(rb_file)
96
96
  end
97
97
 
98
98
  # Compile to a native executable
99
- `cc build/app.c -lmruby \`simple2d --libs\` -o build/app`
99
+ `cc build/app.c -lmruby -o build/app`
100
100
 
101
101
  # Clean up
102
102
  clean_up unless @debug
@@ -162,12 +162,6 @@ end
162
162
  def build_ios_tvos(rb_file, device)
163
163
  check_build_src_file(rb_file)
164
164
 
165
- # Check for Simple 2D framework,
166
- unless File.exist?('/usr/local/Frameworks/Simple2D/iOS/Simple2D.framework') && File.exist?('/usr/local/Frameworks/Simple2D/tvOS/Simple2D.framework')
167
- puts "#{'Error:'.error} Simple 2D iOS and tvOS frameworks not found. Install them and try again.\n"
168
- exit
169
- end
170
-
171
165
  # Check if MRuby exists; if not, quit
172
166
  if `which mruby`.empty?
173
167
  puts "#{'Error:'.error} Can't find MRuby, which is needed to build native Ruby 2D applications.\n"
@@ -197,6 +191,7 @@ def build_ios_tvos(rb_file, device)
197
191
  f << File.read("#{@gem_dir}/ext/ruby2d/ruby2d.c")
198
192
  end
199
193
 
194
+ # TODO: Need add this functionality to the gem
200
195
  # Build the Xcode project
201
196
  `simple2d build --#{device} build/#{device}/MyApp.xcodeproj`
202
197
 
@@ -1,5 +1,5 @@
1
1
  # Ruby2D::VERSION
2
2
 
3
3
  module Ruby2D
4
- VERSION = '0.9.4'
4
+ VERSION = '0.9.5'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby2d
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Black
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-16 00:00:00.000000000 Z
11
+ date: 2021-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -123,7 +123,6 @@ files:
123
123
  - assets/include/SDL2/begin_code.h
124
124
  - assets/include/SDL2/close_code.h
125
125
  - assets/include/glew.h
126
- - assets/include/simple2d.h
127
126
  - assets/ios/Assets.xcassets/AppIcon.appiconset/Contents.json
128
127
  - assets/ios/Assets.xcassets/Contents.json
129
128
  - assets/ios/Base.lproj/LaunchScreen.storyboard
@@ -165,23 +164,6 @@ files:
165
164
  - assets/ios/MyApp.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
166
165
  - assets/ios/MyApp.xcodeproj/project.xcworkspace/xcshareddata/MyApp.xcscmblueprint
167
166
  - assets/ios/main.c
168
- - assets/linux/simple2d/Makefile
169
- - assets/linux/simple2d/bin/simple2d.sh
170
- - assets/linux/simple2d/include/simple2d.h
171
- - assets/linux/simple2d/src/controllers.c
172
- - assets/linux/simple2d/src/gl.c
173
- - assets/linux/simple2d/src/gl2.c
174
- - assets/linux/simple2d/src/gl3.c
175
- - assets/linux/simple2d/src/gles.c
176
- - assets/linux/simple2d/src/image.c
177
- - assets/linux/simple2d/src/input.c
178
- - assets/linux/simple2d/src/music.c
179
- - assets/linux/simple2d/src/shapes.c
180
- - assets/linux/simple2d/src/simple2d.c
181
- - assets/linux/simple2d/src/sound.c
182
- - assets/linux/simple2d/src/sprite.c
183
- - assets/linux/simple2d/src/text.c
184
- - assets/linux/simple2d/src/window.c
185
167
  - assets/macos/lib/libFLAC.a
186
168
  - assets/macos/lib/libSDL2.a
187
169
  - assets/macos/lib/libSDL2_image.a
@@ -192,7 +174,6 @@ files:
192
174
  - assets/macos/lib/libmpg123.a
193
175
  - assets/macos/lib/libogg.a
194
176
  - assets/macos/lib/libpng16.a
195
- - assets/macos/lib/libsimple2d.a
196
177
  - assets/macos/lib/libtiff.a
197
178
  - assets/macos/lib/libvorbis.a
198
179
  - assets/macos/lib/libvorbisfile.a
@@ -228,7 +209,6 @@ files:
228
209
  - assets/mingw/lib/libSDL2main.a
229
210
  - assets/mingw/lib/libglew32.a
230
211
  - assets/mingw/lib/libglew32.dll.a
231
- - assets/mingw/lib/libsimple2d.a
232
212
  - assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Content.imageset/Contents.json
233
213
  - assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Contents.json
234
214
  - assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Contents.json
@@ -288,8 +268,23 @@ files:
288
268
  - assets/tvos/MyApp.xcodeproj/project.xcworkspace/xcshareddata/MyApp.xcscmblueprint
289
269
  - assets/tvos/main.c
290
270
  - bin/ruby2d
271
+ - ext/ruby2d/common.c
272
+ - ext/ruby2d/controllers.c
291
273
  - ext/ruby2d/extconf.rb
274
+ - ext/ruby2d/gl.c
275
+ - ext/ruby2d/gl2.c
276
+ - ext/ruby2d/gl3.c
277
+ - ext/ruby2d/gles.c
278
+ - ext/ruby2d/image.c
279
+ - ext/ruby2d/input.c
280
+ - ext/ruby2d/music.c
292
281
  - ext/ruby2d/ruby2d.c
282
+ - ext/ruby2d/ruby2d.h
283
+ - ext/ruby2d/shapes.c
284
+ - ext/ruby2d/sound.c
285
+ - ext/ruby2d/sprite.c
286
+ - ext/ruby2d/text.c
287
+ - ext/ruby2d/window.c
293
288
  - lib/ruby2d.rb
294
289
  - lib/ruby2d/circle.rb
295
290
  - lib/ruby2d/cli/build.rb
@@ -318,7 +313,7 @@ homepage: http://www.ruby2d.com
318
313
  licenses:
319
314
  - MIT
320
315
  metadata: {}
321
- post_install_message:
316
+ post_install_message:
322
317
  rdoc_options: []
323
318
  require_paths:
324
319
  - lib
@@ -333,8 +328,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
333
328
  - !ruby/object:Gem::Version
334
329
  version: '0'
335
330
  requirements: []
336
- rubygems_version: 3.1.2
337
- signing_key:
331
+ rubygems_version: 3.2.9
332
+ signing_key:
338
333
  specification_version: 4
339
334
  summary: Ruby 2D
340
335
  test_files: []
@@ -1,260 +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-$(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/headers/SDL2 build/ios/Simple2D.framework/Headers
128
- cp -R deps/headers/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 macOS release)
152
- mkdir -p build/$(APPLE_RELEASE)/macOS
153
- cp build/libsimple2d.a build/$(APPLE_RELEASE)/macOS
154
- $(call task_msg,Building iOS and tvOS release)
155
- mkdir -p build/$(APPLE_RELEASE)/iOS
156
- mkdir -p build/$(APPLE_RELEASE)/tvOS
157
- cp -R build/ios/* build/$(APPLE_RELEASE)/iOS/
158
- cp -R build/tvos/* build/$(APPLE_RELEASE)/tvOS/
159
- cd build; zip -rq $(APPLE_RELEASE).zip $(APPLE_RELEASE)
160
- $(call info_msg,Apple release zipped at \`build/$(APPLE_RELEASE).zip\`)
161
- endif
162
-
163
- ifeq ($(PLATFORM),mingw)
164
- release: clean all
165
- mkdir -p build/$(MINGW_RELEASE)/include
166
- mkdir -p build/$(MINGW_RELEASE)/lib
167
- mkdir -p build/$(MINGW_RELEASE)/bin
168
- cp -R deps/mingw/include/* build/$(MINGW_RELEASE)/include
169
- cp -R deps/mingw/lib/* build/$(MINGW_RELEASE)/lib
170
- cp -R deps/mingw/bin/* build/$(MINGW_RELEASE)/bin
171
- cp deps/LICENSES.md build/$(MINGW_RELEASE)
172
- cp include/simple2d.h build/$(MINGW_RELEASE)/include
173
- cp build/libsimple2d.a build/$(MINGW_RELEASE)/lib
174
- cp build/simple2d build/$(MINGW_RELEASE)/bin
175
- cp bin/win-installer-mingw.sh build/$(MINGW_RELEASE)/install.sh
176
- PowerShell -Command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::CreateFromDirectory('build/$(MINGW_RELEASE)', 'build/\$(MINGW_RELEASE).zip'); }"
177
- endif
178
-
179
- clean:
180
- $(call task_msg,Cleaning)
181
- rm -rf build/*
182
- ifeq ($(PLATFORM),mingw)
183
- rm -f test/auto.exe
184
- rm -f test/triangle.exe
185
- rm -f test/testcard.exe
186
- rm -f test/audio.exe
187
- rm -f test/controller.exe
188
- else
189
- rm -f test/auto
190
- rm -f test/triangle
191
- rm -f test/testcard
192
- rm -f test/audio
193
- rm -f test/controller
194
- endif
195
-
196
- uninstall:
197
- $(call task_msg,Uninstalling)
198
- rm -f /usr/local/include/simple2d.h
199
- rm -f /usr/local/lib/libsimple2d.a
200
- rm -f /usr/local/bin/simple2d
201
- ifeq ($(PLATFORM),apple)
202
- rm -rf /usr/local/Frameworks/Simple2D
203
- endif
204
-
205
- test:
206
- $(call task_msg,Building tests)
207
- simple2d build test/auto.c
208
- simple2d build test/triangle.c
209
- simple2d build test/testcard.c
210
- simple2d build test/audio.c
211
- simple2d build test/controller.c
212
-
213
- rebuild: uninstall clean all install test
214
-
215
- auto:
216
- $(call run_test,auto)
217
-
218
- triangle:
219
- $(call run_test,triangle)
220
-
221
- testcard:
222
- $(call run_test,testcard)
223
-
224
- audio:
225
- $(call run_test,audio)
226
-
227
- controller:
228
- $(call run_test,controller)
229
-
230
- ifeq ($(PLATFORM),apple)
231
- ios:
232
- ifeq ($(shell test -d /usr/local/Frameworks/Simple2D/iOS/Simple2D.framework; echo $$?),1)
233
- $(error Simple2D.framework missing for iOS. Run `frameworks` and `install-frameworks` targets first)
234
- endif
235
- $(call task_msg,Running iOS test)
236
- mkdir -p build/ios
237
- cp -R deps/xcode/ios/* build/ios
238
- cp test/triangle-ios-tvos.c build/ios/main.c
239
- simple2d build --ios build/ios/MyApp.xcodeproj
240
- simple2d simulator --open "iPhone X"
241
- simple2d simulator --install "build/ios/build/Release-iphonesimulator/MyApp.app"
242
- simple2d simulator --launch "Simple2D.MyApp"
243
- endif
244
-
245
- ifeq ($(PLATFORM),apple)
246
- tvos:
247
- ifeq ($(shell test -d /usr/local/Frameworks/Simple2D/tvOS/Simple2D.framework; echo $$?),1)
248
- $(error Simple2D.framework missing for tvOS. Run `frameworks` and `install-frameworks` targets first)
249
- endif
250
- $(call task_msg,Running tvOS test)
251
- mkdir -p build/tvos
252
- cp -R deps/xcode/tvos/* build/tvos
253
- cp test/triangle-ios-tvos.c build/tvos/main.c
254
- simple2d build --tvos build/tvos/MyApp.xcodeproj
255
- simple2d simulator --open "Apple TV 4K"
256
- simple2d simulator --install "build/tvos/build/Release-appletvsimulator/MyApp.app"
257
- simple2d simulator --launch "Simple2D.MyApp"
258
- endif
259
-
260
- .PHONY: build test
@@ -1,1318 +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.2.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.10"
31
- sdl_url="${libsdl_url}/release/${sdl_fname}.tar.gz"
32
-
33
- image_fname="SDL2_image-2.0.5"
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.15"
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 source file given, e.g.: build app.c
206
- if [[ ${1: -2} == '.c' ]]; then
207
- # Compile
208
- gcc -std=c11 $1 `simple2d --libs` -o ${1%.*}
209
- exit
210
- fi
211
-
212
- # If C++ source file given, e.g.: build app.cpp
213
- if [[ ${1: -4} == '.cpp' ]]; then
214
- # Compile
215
- g++ -std=c++11 $1 `simple2d --libs` -o ${1%.*}
216
- exit
217
- fi
218
-
219
- # Check if current directory has an Xcode project
220
- has_xcodeproj?() {
221
- if [[ $(ls *.xcodeproj 2>/dev/null) ]]; then
222
- return 0
223
- else
224
- return 1
225
- fi
226
- }
227
-
228
- # Build an Xcode project
229
- build_with_xcodebuild() {
230
- if [[ $XCPRETTY != 'xcpretty' ]]; then
231
- echo -e "xcpretty not found: Run \`gem install xcpretty\` for nicer xcodebuild output.\n"
232
- fi
233
- case $1 in
234
- --ios)
235
- xcodebuild -sdk iphonesimulator | $XCPRETTY; exit;;
236
- --ios-device)
237
- xcodebuild -sdk iphoneos | $XCPRETTY; exit;;
238
- --tvos)
239
- xcodebuild -sdk appletvsimulator | $XCPRETTY; exit;;
240
- --tvos-device)
241
- xcodebuild -sdk appletvos | $XCPRETTY; exit;;
242
- esac
243
- }
244
-
245
- # If bad SDK flag, print build usage
246
- if ! [[ $1 =~ ^(--ios|--ios-device|--tvos|--tvos-device)$ ]]; then
247
- print_usage_build; exit 1
248
- fi
249
-
250
- # If current directory has an Xcode project, e.g.:
251
- # build --[ios|tvos][-device]
252
- if has_xcodeproj?; then
253
- build_with_xcodebuild $1
254
- fi
255
-
256
- # If an Xcode project path and options are provided, e.g.:
257
- # build --ios[-device] build/ios
258
- # build --tvos[-device] build/tvos
259
- # build --ios[-device] build/ios/MyApp.xcodeproj
260
- # build --tvos[-device] build/tvos/MyApp.xcodeproj
261
- if [[ ${2: -10} == '.xcodeproj' ]]; then
262
- cd $(dirname $2)
263
- elif [[ -d $2 ]]; then
264
- cd $2
265
- else
266
- error_msg "\"$2\" is not a directory or Xcode project"; exit 1
267
- fi
268
-
269
- if ! has_xcodeproj?; then
270
- error_msg "The directory does not contain an Xcode project"; exit 1
271
- fi
272
-
273
- build_with_xcodebuild $1
274
- }
275
-
276
-
277
- # Installation #################################################################
278
-
279
-
280
- # Checks installed versions of SDL
281
- check_sdl_versions() {
282
-
283
- print_task "Checking SDL2 version... "
284
-
285
- # Check SDL version installed
286
- SDL_INSTALLED_VERSION=$(sdl2-config --version)
287
- compare_versions $SDL_MIN_VERSION $SDL_INSTALLED_VERSION
288
-
289
- if [[ $? == 1 ]]; then
290
- echo $SDL_INSTALLED_VERSION
291
- error_msg "Installed version of SDL2 is too old (must be at least $SDL_MIN_VERSION)"
292
- return 1
293
- else
294
- echo "$SDL_INSTALLED_VERSION"
295
- return 0
296
- fi
297
- }
298
-
299
-
300
- # Checks if SDL libraries are installed
301
- have_sdl_libs?() {
302
-
303
- have_all_libs=true
304
- have_sdl2_lib=true
305
- have_image_lib=true
306
- have_mixer_lib=true
307
- have_ttf_lib=true
308
-
309
- if ! have_lib? 'SDL2'; then
310
- have_sdl2_lib=false
311
- have_all_libs=false
312
- else
313
- if ! check_sdl_versions; then
314
- have_sdl2_lib=false
315
- have_all_libs=false
316
- fi
317
- fi
318
-
319
- if ! have_lib? 'SDL2_image'; then
320
- have_image_lib=false
321
- have_all_libs=false
322
- fi
323
-
324
- if ! have_lib? 'SDL2_mixer'; then
325
- have_mixer_lib=false
326
- have_all_libs=false
327
- fi
328
-
329
- if ! have_lib? 'SDL2_ttf'; then
330
- have_ttf_lib=false
331
- have_all_libs=false
332
- fi
333
-
334
- if $have_all_libs; then
335
- return 0
336
- else
337
- return 1
338
- fi
339
- }
340
-
341
-
342
- # Installs SDL on BSD
343
- install_sdl_bsd() {
344
-
345
- echo "The following packages will be installed:"
346
- echo " sdl2"
347
- echo " sdl2_image"
348
- echo " sdl2_mixer"
349
- echo " sdl2_ttf"
350
-
351
- prompt_to_continue "Install SDL now?"
352
-
353
- print_task "Updating packages" "\n\n"
354
- print_and_run "sudo pkg update"
355
-
356
- echo; print_task "Installing packages" "\n\n"
357
- print_and_run "sudo pkg install sdl2 sdl2_image sdl2_mixer sdl2_ttf"
358
- echo
359
-
360
- if ! have_sdl_libs?; then
361
- echo; error_msg "SDL libraries did not install correctly"; exit 1
362
- else
363
- echo; info_msg "SDL was installed successfully"
364
- fi
365
- }
366
-
367
-
368
- # Installs SDL on Linux
369
- install_sdl_linux() {
370
-
371
- echo "The following packages will be installed:"
372
- # Fedora and CentOS
373
- if which yum &>/dev/null; then
374
- echo " SDL2-devel"
375
- echo " SDL2_image-devel"
376
- echo " SDL2_mixer-devel"
377
- echo " SDL2_ttf-devel"
378
- # Arch
379
- elif which pacman &>/dev/null; then
380
- echo " sdl2"
381
- echo " sdl2_image"
382
- echo " sdl2_mixer"
383
- echo " sdl2_ttf"
384
- # openSUSE
385
- elif which zypper &>/dev/null; then
386
- echo " libSDL2-devel"
387
- echo " libSDL2_image-devel"
388
- echo " libSDL2_mixer-devel"
389
- echo " libSDL2_ttf-devel"
390
- # Ubuntu, Debian, and Mint
391
- # `apt` must be last because openSUSE has it aliased to `zypper`
392
- elif which apt &>/dev/null; then
393
- echo " libsdl2-dev"
394
- echo " libsdl2-image-dev"
395
- echo " libsdl2-mixer-dev"
396
- echo " libsdl2-ttf-dev"
397
- else
398
- error_msg "Could not find a package manager to install SDL"; exit 1
399
- fi
400
- echo
401
-
402
- prompt_to_continue "Install SDL now?"
403
-
404
- print_task "Updating packages" "\n\n"
405
-
406
- if which yum &>/dev/null; then
407
- print_and_run "yum check-update"
408
- elif which pacman &>/dev/null; then
409
- print_and_run "sudo pacman -Syy"
410
- elif which zypper &>/dev/null; then
411
- print_and_run "sudo zypper refresh"
412
- elif which apt &>/dev/null; then
413
- print_and_run "sudo apt update"
414
- fi
415
-
416
- echo; print_task "Installing packages" "\n\n"
417
-
418
- if which yum &>/dev/null; then
419
- print_and_run "sudo yum install -y SDL2-devel SDL2_image-devel SDL2_mixer-devel SDL2_ttf-devel"
420
- elif which pacman &>/dev/null; then
421
- print_and_run "sudo pacman -S --noconfirm sdl2 sdl2_image sdl2_mixer sdl2_ttf"
422
- elif which zypper &>/dev/null; then
423
- print_and_run "sudo zypper install -y libSDL2-devel libSDL2_image-devel libSDL2_mixer-devel libSDL2_ttf-devel"
424
- elif which apt &>/dev/null; then
425
- print_and_run "sudo apt install -y libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev"
426
- fi
427
- echo
428
-
429
- if ! have_sdl_libs?; then
430
- echo; error_msg "SDL libraries did not install correctly"; exit 1
431
- else
432
- echo; info_msg "SDL was installed successfully"
433
- fi
434
- }
435
-
436
-
437
- # Installs SDL from source
438
- # Takes about 30 min on RPI 2
439
- install_sdl_source() {
440
-
441
- echo "SDL will be compiled and installed from source."; echo
442
-
443
- prompt_to_continue "Install SDL now?"
444
-
445
- # Install SDL dependencies
446
- print_task "Installing SDL2 dependencies" "\n\n"
447
- sudo apt update
448
-
449
- libs=(
450
- build-essential # This may be missing on some ARM platforms
451
-
452
- # SDL2
453
- libudev-dev
454
- libdbus-1-dev
455
- libasound2-dev
456
-
457
- # SDL2_image
458
- libjpeg9-dev
459
- libpng-dev
460
-
461
- # SDL2_mixer
462
- libmpg123-dev
463
- libvorbis-dev
464
- libflac-dev
465
-
466
- # SDL2_ttf
467
- libgl1-mesa-dev # Solves error missing -lGL
468
- libfreetype6-dev
469
- )
470
-
471
- sudo apt install -y ${libs[*]}
472
-
473
- # Downloads, compiles, and installs an SDL library from source
474
- # params:
475
- # $1 String URL of the tar archive
476
- # $2 String Name of the tar file
477
- # $3 String ./configure flags
478
- install_sdl_lib () {
479
- cd /tmp
480
- wget -N $1
481
- tar -xzf $2.tar.gz
482
- cd $2
483
- print_task "Configuring" "\n\n"
484
- print_and_run "./configure $3"
485
- echo; print_task "Compiling" "\n\n"
486
- make
487
- echo; print_task "Installing" "\n\n"
488
- sudo make install
489
- rm /tmp/$2.tar.gz
490
- rm -rf /tmp/$2
491
- }
492
-
493
- # Note that `$have_*_lib` variables are set by `have_sdl_libs?()`
494
-
495
- if [[ $have_sdl2_lib == 'false' ]]; then
496
- echo; print_task "Downloading SDL2" "\n\n"
497
- if [[ $platform == 'arm' ]]; then
498
- if $platform_rpi; then
499
- config="--host=arm-raspberry-linux-gnueabihf $sdl_arm_config_flags"
500
- else
501
- config=$sdl_arm_config_flags
502
- fi
503
- install_sdl_lib $sdl_url $sdl_fname "$config"
504
- else
505
- install_sdl_lib $sdl_url $sdl_fname
506
- fi
507
- fi
508
-
509
- if [[ $have_image_lib == 'false' ]]; then
510
- echo; print_task "Downloading SDL2_image" "\n\n"
511
- install_sdl_lib $image_url $image_fname
512
- fi
513
-
514
- if [[ $have_mixer_lib == 'false' ]]; then
515
- echo; print_task "Downloading SDL2_mixer" "\n\n"
516
- install_sdl_lib $mixer_url $mixer_fname
517
- fi
518
-
519
- if [[ $have_ttf_lib == 'false' ]]; then
520
- echo; print_task "Downloading SDL2_ttf" "\n\n"
521
- install_sdl_lib $ttf_url $ttf_fname
522
- fi
523
-
524
- echo
525
- if ! have_sdl_libs?; then
526
- error_msg "SDL libraries did not install correctly"; exit 1
527
- else
528
- echo; info_msg "SDL was installed successfully"
529
- fi
530
- }
531
-
532
-
533
- # Installs SDL
534
- install_sdl() {
535
- if [[ $platform == 'linux' ]]; then
536
- install_sdl_linux
537
- elif [[ $platform == 'bsd' ]]; then
538
- install_sdl_bsd
539
- elif [[ $platform == 'arm' ]]; then
540
- install_sdl_source
541
- fi
542
- }
543
-
544
-
545
- # Installs Simple 2D for MinGW environments
546
- install_s2d_mingw() {
547
- tmp_dir="/tmp/simple2d"
548
- mkdir -p $tmp_dir
549
- print_and_run "wget -NP $tmp_dir $s2d_mingw_installer_url"
550
- print_and_run "pacman -S unzip --needed --noconfirm"
551
- print_and_run "unzip -q $tmp_dir/$s2d_mingw_installer_fname -d $tmp_dir"
552
- print_and_run "cd $tmp_dir"
553
- print_and_run "bash install.sh -y"
554
- print_and_run "rm -rf $tmp_dir"
555
- }
556
-
557
-
558
- # Installs Simple 2D
559
- # params:
560
- # $1 String Version to install, either 'master' or $VERSION
561
- install_s2d() {
562
-
563
- tmp_dir="/tmp/simple2d"
564
-
565
- mkdir $tmp_dir
566
-
567
- if [[ $1 == 'master' ]]; then
568
- f_name=$1
569
- else
570
- f_name="v$1"
571
- fi
572
-
573
- url="https://github.com/simple2d/simple2d/archive/$f_name.zip"
574
-
575
- print_task "Downloading Simple 2D" "\n\n"
576
- # Linux and Raspberry Pi may not have curl installed by default
577
- if which curl &>/dev/null; then
578
- print_and_run "curl -L $url -o $tmp_dir/$f_name.zip"
579
- else
580
- print_and_run "wget -NP $tmp_dir $url"
581
- fi
582
-
583
- # Check if archive was downloaded properly
584
- if [[ ! -f "$tmp_dir/$f_name.zip" ]]; then
585
- echo; error_msg "Simple 2D could not be downloaded"; exit 1
586
- fi
587
-
588
- echo; print_task "Unpacking" "\n\n"
589
- print_and_run "unzip -q $tmp_dir/$f_name.zip -d $tmp_dir"
590
-
591
- # Check if archive was unpacked properly
592
- if [[ $? != 0 ]]; then
593
- echo; error_msg "Could not unpack. The downloaded Simple 2D package may be damaged."; exit 1
594
- fi
595
-
596
- print_and_run "cd $tmp_dir/simple2d-$1"
597
-
598
- if [[ $platform == 'bsd' ]]; then
599
- echo; print_and_run "gmake"
600
- echo; print_and_run "sudo gmake install"
601
- else
602
- echo; print_and_run "make"
603
- echo; print_and_run "sudo make install"
604
- fi
605
-
606
- echo; print_task "Cleaning up" "\n"; echo
607
- print_and_run "rm -rf $tmp_dir"; echo
608
-
609
- # Check if S2D installed correctly
610
- if ! have_lib? 'simple2d'; then
611
- echo; error_msg "Simple 2D did not install correctly"; exit 1
612
- fi
613
- echo
614
- }
615
-
616
-
617
- # Main entry point to install Simple 2D and SDL
618
- # params:
619
- # $1 String Flags used, e.g. `--sdl`
620
- install() {
621
-
622
- # If macOS, print message and quit
623
- if [[ $platform == 'macos' ]]; then
624
- macos_homebrew_message $1
625
- fi
626
-
627
- # If SDL flag, install only SDL and quit
628
- if [[ $1 == '--sdl' ]]; then
629
- echo
630
- if have_sdl_libs?; then
631
- echo; info_msg "SDL is already installed"
632
- else
633
- echo; install_sdl
634
- fi
635
- exit
636
- fi
637
-
638
- # Welcome message
639
- echo -e "\n${BOLD}Welcome to Simple 2D!${NORMAL}"
640
- echo -e "${BLUE}---------------------${NORMAL}\n"
641
-
642
- echo -e "Platform detected: ${BOLD}${platform_display}${NORMAL}\n"
643
-
644
- # If MinGW, install Simple 2D release and quit
645
- if [[ $platform == 'mingw' ]]; then
646
- prompt_to_continue "Continue to install?"
647
- install_s2d_mingw
648
- exit
649
- fi
650
-
651
- if have_lib? 'simple2d' > /dev/null; then
652
- warning_msg "Simple 2D is already installed. Proceeding will reinstall."
653
- fi
654
-
655
- echo -e "Simple 2D will be installed to the following locations:
656
- /usr/local/include/simple2d.h
657
- /usr/local/lib/libsimple2d.a
658
- /usr/local/bin/simple2d"
659
- echo
660
-
661
- if [[ $1 == '--HEAD' ]]; then
662
- echo -e "This will install Simple 2D from the \`master\` development branch.\n"
663
- fi
664
-
665
- prompt_to_continue "Continue?"
666
-
667
- if have_sdl_libs?; then
668
- echo
669
- else
670
- echo; install_sdl
671
- fi
672
-
673
- if [[ $1 == '--HEAD' ]]; then
674
- install_s2d 'master'
675
- else
676
- install_s2d $VERSION
677
- fi
678
-
679
- success_msg "Simple 2D installed successfully!"
680
- }
681
-
682
-
683
- # Uninstall ####################################################################
684
-
685
-
686
- # Uninstalls SDL on BSD
687
- uninstall_sdl_bsd() {
688
-
689
- echo "The following packages will be removed:"
690
- echo " sdl2"
691
- echo " sdl2_image"
692
- echo " sdl2_mixer"
693
- echo " sdl2_ttf"
694
-
695
- prompt_to_continue "Uninstall SDL now?"
696
-
697
- echo; print_task "Uninstalling packages" "\n\n"
698
- print_and_run "sudo pkg remove sdl2 sdl2_image sdl2_mixer sdl2_ttf"
699
- echo
700
-
701
- if have_sdl_libs?; then
702
- echo; error_msg "SDL libraries did not uninstall correctly"
703
- else
704
- echo; info_msg "SDL was uninstalled successfully"
705
- fi
706
- }
707
-
708
-
709
- # Uninstalls SDL on Linux
710
- uninstall_sdl_linux() {
711
-
712
- echo "The following packages will be removed:"
713
- # Fedora and CentOS
714
- if which yum &>/dev/null; then
715
- echo " SDL2-devel"
716
- echo " SDL2_image-devel"
717
- echo " SDL2_mixer-devel"
718
- echo " SDL2_ttf-devel"
719
- # Arch
720
- elif which pacman &>/dev/null; then
721
- echo " sdl2"
722
- echo " sdl2_image"
723
- echo " sdl2_mixer"
724
- echo " sdl2_ttf"
725
- # openSUSE
726
- elif which zypper &>/dev/null; then
727
- echo " libSDL2-devel"
728
- echo " libSDL2_image-devel"
729
- echo " libSDL2_mixer-devel"
730
- echo " libSDL2_ttf-devel"
731
- # Ubuntu, Debian, and Mint
732
- # `apt` must be last because openSUSE has it aliased to `zypper`
733
- elif which apt &>/dev/null; then
734
- echo " libsdl2-dev"
735
- echo " libsdl2-image-dev"
736
- echo " libsdl2-mixer-dev"
737
- echo " libsdl2-ttf-dev"
738
- else
739
- error_msg "Could not find a package manager to uninstall SDL"; exit 1
740
- fi
741
- echo
742
-
743
- prompt_to_continue "Uninstall SDL now?"
744
-
745
- print_task "Uninstalling packages" "\n\n"
746
-
747
- if which yum &>/dev/null; then
748
- print_and_run "sudo yum remove -y SDL2-devel SDL2_image-devel SDL2_mixer-devel SDL2_ttf-devel"
749
- elif which pacman &>/dev/null; then
750
- print_and_run "sudo pacman -Rs --noconfirm sdl2 sdl2_image sdl2_mixer sdl2_ttf"
751
- elif which zypper &>/dev/null; then
752
- print_and_run "sudo zypper remove -y libSDL2-devel libSDL2_image-devel libSDL2_mixer-devel libSDL2_ttf-devel"
753
- elif which apt &>/dev/null; then
754
- print_and_run "sudo apt remove -y --purge libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev"
755
- fi
756
- echo
757
-
758
- if have_sdl_libs?; then
759
- echo; error_msg "SDL libraries did not uninstall correctly"
760
- else
761
- echo; info_msg "SDL was uninstalled successfully"
762
- fi
763
- }
764
-
765
-
766
- # Uninstalls SDL from source
767
- uninstall_sdl_source() {
768
-
769
- prompt_to_continue "Uninstall SDL now?"
770
-
771
- # Uninstall packages in case they were used
772
- print_and_run "sudo apt remove -y --purge libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev"
773
-
774
- uninstall_sdl_lib () {
775
- cd /tmp
776
- wget -N $1
777
- tar -xzf $2.tar.gz
778
- cd $2
779
- ./configure $3
780
- sudo make uninstall
781
- rm /tmp/$2.tar.gz
782
- rm -rf /tmp/$2
783
- }
784
-
785
- echo; print_task "Uninstalling SDL2_image" "\n\n"
786
- uninstall_sdl_lib $image_url $image_fname
787
-
788
- echo; print_task "Uninstalling SDL2_mixer" "\n\n"
789
- uninstall_sdl_lib $mixer_url $mixer_fname
790
-
791
- echo; print_task "Uninstalling SDL2_ttf" "\n\n"
792
- uninstall_sdl_lib $ttf_url $ttf_fname
793
-
794
- echo; print_task "Uninstalling SDL2" "\n\n"
795
- if [[ $platform == 'arm' ]]; then
796
- uninstall_sdl_lib $sdl_url $sdl_fname "$sdl_arm_config_flags"
797
- else
798
- uninstall_sdl_lib $sdl_url $sdl_fname
799
- fi
800
-
801
- echo
802
- if have_sdl_libs?; then
803
- echo; error_msg "SDL libraries did not uninstall correctly"; exit 1
804
- else
805
- echo; info_msg "SDL was uninstalled successfully"
806
- fi
807
- }
808
-
809
-
810
- # Uninstalls SDL
811
- uninstall_sdl() {
812
-
813
- if have_sdl_libs?; then
814
- echo
815
- else
816
- echo; info_msg "SDL appears to be already uninstalled"
817
- prompt_to_continue "Try uninstalling SDL anyways?"
818
- fi
819
-
820
- if [[ $platform == 'linux' ]]; then
821
- uninstall_sdl_linux
822
- elif [[ $platform == 'bsd' ]]; then
823
- uninstall_sdl_bsd
824
- elif [[ $platform == 'arm' ]]; then
825
- uninstall_sdl_source
826
- fi
827
- }
828
-
829
-
830
- # Uninstalls Simple 2D
831
- # params:
832
- # $1 String Flags used, e.g. `--sdl`
833
- uninstall() {
834
-
835
- if [[ $platform == 'macos' ]]; then
836
- macos_homebrew_message $1
837
- fi
838
-
839
- # If MinGW, print message and quit
840
- if [[ $platform == 'mingw' ]]; then
841
- mingw_not_implemented_message
842
- fi
843
-
844
- if [[ $1 == '--sdl' ]]; then
845
- echo; uninstall_sdl
846
- exit
847
- fi
848
-
849
- echo; echo -e "The following files will be removed:
850
- /usr/local/include/simple2d.h
851
- /usr/local/lib/libsimple2d.a
852
- /usr/local/bin/simple2d"
853
-
854
- echo; prompt_to_continue "Uninstall Simple 2D?"
855
-
856
- # Use hard-coded, absolute paths for safety
857
- print_and_run "rm -f /usr/local/include/simple2d.h"
858
- print_and_run "rm -f /usr/local/lib/libsimple2d.a"
859
- print_and_run "rm -f /usr/local/bin/simple2d"
860
-
861
- # Check if files were actually deleted
862
- files=(/usr/local/include/simple2d.h
863
- /usr/local/lib/libsimple2d.a
864
- /usr/local/bin/simple2d)
865
-
866
- if [ -f ${files[0]} -o -f ${files[1]} -o -f ${files[2]} ]; then
867
- echo; error_msg "Simple 2D files could not be removed. Try using \`sudo\`?"
868
- else
869
- echo; success_msg "Simple 2D uninstalled!"
870
- fi
871
- }
872
-
873
-
874
- # Update #######################################################################
875
-
876
-
877
- # Updates Simple 2D to latest version or commit
878
- # params:
879
- # $1 String Flags used, e.g. `--HEAD`
880
- update() {
881
-
882
- if [[ $platform == 'macos' ]]; then
883
- macos_homebrew_message
884
- fi
885
-
886
- # If MinGW, print message and quit
887
- if [[ $platform == 'mingw' ]]; then
888
- mingw_not_implemented_message
889
- fi
890
-
891
- # Check if Simple 2D is installed
892
- if ! have_lib? 'simple2d' > /dev/null; then
893
- error_msg "Simple 2D isn't currently installed"
894
- echo -e "Use the \`install\` command to install Simple 2D.\n"
895
- exit 1
896
- fi
897
-
898
- # Check if SDL is installed
899
- update_check_sdl() {
900
- if have_sdl_libs?; then
901
- echo
902
- else
903
- echo; error_msg "SDL libraries missing"
904
- echo -e "Run \`simple2d install --sdl\` to install SDL.\n"
905
- exit 1
906
- fi
907
- }
908
-
909
- # Read this script from repo, get the version number
910
- get_remote_str $SCRIPT_URL
911
- LATEST_VERSION=$(bash -c "$ret" -- -v)
912
-
913
- compare_versions $LATEST_VERSION $VERSION
914
-
915
- # $LATEST_VERSION is newer $VERSION (the version installed)
916
- if [[ $? == 1 ]]; then
917
- echo -e "A new version of Simple 2D is available.\n"
918
- prompt_to_continue "Upgrade from v$VERSION to v$LATEST_VERSION?"
919
- update_check_sdl
920
- install_s2d $LATEST_VERSION
921
- success_msg "Simple 2D has been updated to $LATEST_VERSION!"
922
- echo -e "View the release notes:
923
- ${UNDERLINE}https://github.com/simple2d/simple2d/releases/latest${NORMAL}"; echo
924
-
925
- # $LATEST_VERSION is the same as installed version
926
- else
927
- echo "Simple 2D is already up to date!"
928
- fi
929
- }
930
-
931
-
932
- # Doctor #######################################################################
933
-
934
-
935
- # Runs the diagnostics
936
- doctor() {
937
-
938
- echo; echo -e "Running diagnostics...\n"
939
-
940
- errors=false
941
-
942
- if ! have_sdl_libs?; then
943
- errors=true
944
- echo; error_msg "SDL libraries missing"
945
- fi
946
-
947
- if have_lib? 'simple2d'; then
948
- echo
949
- else
950
- errors=true
951
- echo; error_msg "Simple 2D library missing"
952
- fi
953
-
954
- if $errors; then
955
- echo -e "Issues were found.\n"
956
- else
957
- success_msg "No issues found!"
958
- fi
959
- }
960
-
961
-
962
- # Simulator ####################################################################
963
-
964
-
965
- # Get list of booted iOS or tvOS simulators, store in $booted
966
- # $1 Equals 'cmd' if called from command line
967
- simulator_booted() {
968
- booted=`xcrun simctl list devices | grep Booted`
969
- if [[ $1 == 'cmd' ]]; then
970
- if [[ $booted == '' ]]; then
971
- echo "No devices are booted."
972
- else
973
- echo $booted
974
- fi
975
- fi
976
- }
977
-
978
-
979
- # List all iOS and tvOS simulator devices available
980
- simulator_list() {
981
- xcrun simctl list devices | grep -iv unavailable
982
- }
983
-
984
-
985
- # Open an iOS or tvOS simulator
986
- # $1 The device name, e.g. iPhone X
987
- # See `simulator_list` function for available names
988
- simulator_open() {
989
- device=$1
990
-
991
- # Check if device name exists
992
- if ! xcrun simctl list devices | grep -q "$device"; then
993
- error_msg "\"$device\" does not match any simulator device names"
994
- echo -e "Choose a device name from the following:\n"
995
- simulator_list
996
- exit 1
997
- fi
998
-
999
- # Get the device UDID
1000
- device_udid=`xcrun simctl list devices | grep "$device" | head -n1 | egrep -wo '\([-0-9A-F]+\)' | tr -d '\(\)'`
1001
- echo "Requested device: $device with UDID $device_udid"
1002
- simulator_booted
1003
-
1004
- # If the current simulator running is not the requested device, then quit
1005
- if [[ $booted != '' && $booted != *$device* ]]; then
1006
- echo "Quitting current device simulator..."
1007
- osascript -e 'quit app "Simulator"'
1008
- fi
1009
-
1010
- # Open the requsted simulator
1011
- echo "Opening $device simulator..."
1012
- open -a Simulator --args -CurrentDeviceUDID $device_udid
1013
-
1014
- # Wait for device to boot
1015
- not_booted=true
1016
- while $not_booted; do
1017
- simulator_booted
1018
- if [[ $booted == *$device* ]]; then
1019
- not_booted=false
1020
- else
1021
- sleep 2
1022
- fi
1023
- done
1024
- }
1025
-
1026
-
1027
- # Install an app on the booted iOS or tvOS simulator
1028
- # $1 The path to the `.app` file, e.g. Release-iphonesimulator/MyApp.app
1029
- simulator_install() {
1030
- echo "Installing app..."
1031
- xcrun simctl install booted $1
1032
- }
1033
-
1034
-
1035
- # Launch an installed app on the booted iOS or tvOS simulator
1036
- # $1 The bundle identifier, e.g. "Simple2D.MyApp"
1037
- simulator_launch() {
1038
- echo "Launching app..."
1039
- xcrun simctl launch booted $1
1040
- }
1041
-
1042
-
1043
- # Stream log of currently running iOS or tvOS simulator
1044
- # $1 Optional app name to filter by
1045
- simulator_log() {
1046
- if [[ $1 == '' ]]; then
1047
- xcrun simctl spawn booted log stream --level=debug
1048
- else
1049
- xcrun simctl spawn booted log stream --predicate "processImagePath endswith \"$1\""
1050
- fi
1051
- }
1052
-
1053
-
1054
- # Stream log of currently running iOS or tvOS simulator, error messages only
1055
- simulator_log_errors() {
1056
- xcrun simctl spawn booted log stream --predicate 'eventMessage contains "error" or messageType == error'
1057
- }
1058
-
1059
-
1060
- # Platform Specifics ###########################################################
1061
-
1062
-
1063
- # Prints homebrew message and quit
1064
- # params:
1065
- # $1 String The message to show, e.g. '--sdl'
1066
- macos_homebrew_message() {
1067
-
1068
- if [[ $1 == '--sdl' ]]; then
1069
- echo -e "
1070
- We recommend using ${BOLD}Homebrew${NORMAL} to install, update, and uninstall
1071
- SDL on macOS. If you installed Simple 2D using Homebrew, the
1072
- following SDL packages were installed:
1073
-
1074
- sdl2
1075
- sdl2_image
1076
- sdl2_mixer
1077
- sdl2_ttf
1078
-
1079
- Run \`brew info <formula>\` to see information about each and
1080
- their dependencies, which were also installed.
1081
-
1082
- Learn more at ${UNDERLINE}http://brew.sh${NORMAL}
1083
- "
1084
- elif [[ $1 == '--HEAD' ]]; then
1085
- echo -e "
1086
- Use ${BOLD}Homebrew${NORMAL} to install, update, and uninstall Simple 2D on macOS.
1087
-
1088
- To install the latest changes from the \`master\` development branch, use:
1089
- brew install --HEAD simple2d
1090
-
1091
- Note \`brew update\` will not update formulas installed with \`--HEAD\`,
1092
- but you can use \`brew reinstall --HEAD simple2d\` to manually grab
1093
- the latest changes.
1094
- "
1095
- else
1096
- echo -e "
1097
- Use ${BOLD}Homebrew${NORMAL} to install, update, and uninstall Simple 2D on macOS.
1098
-
1099
- First, use \`brew tap\` to get Simple 2D formulas:
1100
- brew tap simple2d/tap
1101
-
1102
- Then, the following \`brew\` commands will be available:
1103
- brew install simple2d
1104
- brew upgrade simple2d
1105
- brew uninstall simple2d
1106
-
1107
- Learn more at ${UNDERLINE}http://brew.sh${NORMAL}
1108
- "
1109
- fi
1110
-
1111
- exit
1112
- }
1113
-
1114
-
1115
- # Commands only available on macOS
1116
- macos_only_command() {
1117
- echo -e "This command is only available on macOS"; exit 1
1118
- }
1119
-
1120
-
1121
- # For stuff not yet implemented in MinGW
1122
- mingw_not_implemented_message() {
1123
- echo -e "This isn't implemented in MinGW yet :("; exit 1
1124
- }
1125
-
1126
-
1127
- # Detect Platform ##############################################################
1128
-
1129
-
1130
- unamestr=$(uname)
1131
-
1132
- # macOS
1133
- if [[ $unamestr == 'Darwin' ]]; then
1134
- platform_display='macOS'
1135
- platform='macos'
1136
-
1137
- # ARM
1138
- elif [[ $(uname -m) =~ 'arm' && $unamestr == 'Linux' ]]; then
1139
- platform_display='ARM / Linux'
1140
- platform='arm'
1141
-
1142
- # Raspberry Pi
1143
- if [[ $(cat /etc/os-release | grep -i raspbian) ]]; then
1144
- platform_display='ARM / Linux (Raspberry Pi)'
1145
- platform_rpi=true
1146
- fi
1147
-
1148
- # Linux
1149
- elif [[ $unamestr == 'Linux' ]]; then
1150
- platform_display='Linux'
1151
- platform='linux'
1152
-
1153
- # Windows / MinGW
1154
- elif [[ $unamestr =~ 'MINGW' ]]; then
1155
- platform_display='Windows / MinGW'
1156
- platform='mingw'
1157
-
1158
- # BSD
1159
- elif [[ $unamestr =~ 'BSD' ]]; then
1160
- platform_display='BSD'
1161
- platform='bsd'
1162
- fi
1163
-
1164
- # Unsupported platform
1165
- if [[ $platform == 'unknown' ]]; then
1166
- echo; error_msg "Not a supported system (macOS, Linux, or ARM platform)"; exit 1
1167
- fi
1168
-
1169
-
1170
- # Check Command-line Arguments #################################################
1171
-
1172
-
1173
- print_usage() {
1174
- echo -e "${BOLD}Simple 2D is a simple, open-source 2D graphics engine for everyone.${NORMAL}
1175
-
1176
- Usage: simple2d [--libs] [-v|--version]
1177
- <command> <options>
1178
-
1179
- Summary of commands and options:
1180
- build Build a C/C++ source file or Xcode project; run for options
1181
- install Installs the latest release
1182
- --HEAD Installs from the development branch
1183
- --sdl Installs SDL only
1184
- uninstall Removes Simple 2D files
1185
- --sdl Removes SDL only
1186
- update Updates to latest release
1187
- doctor Runs diagnostics, checks installation, reports issues
1188
- simulator Interact with iOS and tvOS simulators; run for options
1189
- --libs Outputs libraries needed to compile Simple 2D apps
1190
- -v|--version Prints the installed version
1191
- "
1192
- }
1193
-
1194
-
1195
- print_usage_build() {
1196
- echo -e "
1197
- Use the ${BOLD}build${NORMAL} command to compile or build Simple 2D apps.
1198
-
1199
- For compiling C/C++ source files, use:
1200
- build <c_or_cpp_file>
1201
-
1202
- To build an Xcode project, use:
1203
- build <sdk_option> <optional_path_to_xcode_project>
1204
-
1205
- For <sdk_option> above, use one of the following:
1206
- --ios iOS simulator SDK
1207
- --ios-device iOS device SDK (requires signing)
1208
- --tvos tvOS simulator SDK
1209
- --tvos-device tvOS device SDK (requires signing)
1210
- "
1211
- }
1212
-
1213
-
1214
- print_usage_simulator() {
1215
- echo -e "
1216
- Choose an option with the ${BOLD}simulator${NORMAL} command:
1217
-
1218
- --list List available devices
1219
- --booted Show currently booted devices
1220
-
1221
- --open <device_name> Open a simulator device with a given device name
1222
-
1223
- --install <app_file> Install an app on the booted simulator given the path
1224
- to the app e.g. \"Release-iphonesimulator/MyApp.app\"
1225
-
1226
- --launch <bundle_id> Launch an app given the app bundle's identifier,
1227
- e.g. \"Simple2D.MyApp\"
1228
-
1229
- --log Stream log of the booted simulator
1230
- --log <app> Stream log for the app only, given the app name
1231
- --log-errors Stream log containing only error messages
1232
- "
1233
- }
1234
-
1235
-
1236
- case $1 in
1237
- build)
1238
- build $2 $3;;
1239
- install)
1240
- case $2 in
1241
- '')
1242
- install;;
1243
- -y)
1244
- confirmed=true
1245
- install;;
1246
- --HEAD)
1247
- install '--HEAD';;
1248
- --sdl)
1249
- install '--sdl';;
1250
- *)
1251
- print_usage;;
1252
- esac;;
1253
- uninstall)
1254
- case $2 in
1255
- '')
1256
- uninstall;;
1257
- --sdl)
1258
- uninstall '--sdl';;
1259
- *)
1260
- print_usage;;
1261
- esac;;
1262
- update)
1263
- case $2 in
1264
- '')
1265
- update;;
1266
- --HEAD)
1267
- update '--HEAD';;
1268
- *)
1269
- print_usage;;
1270
- esac;;
1271
- doctor)
1272
- doctor;;
1273
- simulator)
1274
- if [[ $platform != 'macos' ]]; then macos_only_command; fi
1275
- case $2 in
1276
- '')
1277
- print_usage_simulator;;
1278
- --list)
1279
- simulator_list;;
1280
- --booted)
1281
- simulator_booted 'cmd';;
1282
- --open)
1283
- simulator_open "$3";;
1284
- --install)
1285
- simulator_install "$3";;
1286
- --launch)
1287
- simulator_launch "$3";;
1288
- --log)
1289
- simulator_log "$3";;
1290
- --log-errors)
1291
- simulator_log_errors;;
1292
- *)
1293
- print_usage_simulator;;
1294
- esac;;
1295
- --libs)
1296
- if [[ $platform == 'macos' ]]; then
1297
- FLAGS='-Wl,-framework,OpenGL'
1298
- elif [[ $platform == 'linux' || $platform == 'bsd' ]]; then
1299
- FLAGS='-lGL -lm'
1300
- elif [[ $platform == 'arm' ]]; then
1301
- FLAGS='-lm -I/opt/vc/include/ -L/opt/vc/lib'
1302
- if $platform_rpi; then
1303
- FLAGS+=' -lbrcmGLESv2'
1304
- else
1305
- FLAGS+=' -lGLESv2'
1306
- fi
1307
- fi
1308
- if [[ $platform == 'mingw' ]]; then
1309
- echo "-I/usr/local/include/ -L/usr/local/lib -lmingw32 -lsimple2d -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lopengl32 -lglew32"
1310
- else
1311
- echo "-lsimple2d `sdl2-config --cflags --libs`"\
1312
- "${FLAGS} -lSDL2_image -lSDL2_mixer -lSDL2_ttf"
1313
- fi;;
1314
- -v|--version)
1315
- echo $VERSION;;
1316
- *)
1317
- print_usage;;
1318
- esac