Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add example with auto detection of SDL2 version #516

Merged
merged 5 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ v install sdl
If you want to use another version of SDL2 you will, currently, have to install
it via `git` or by manual download.

An example of installing the system provided version of SDL2 via `git`:
```bash
git clone https://github.com/vlang/sdl.git ~/.vmodules
v ~/.vmodules/sdl/setup.vsh
```

Should `sdl2-config` be absent on your system you can try the following instead,
by providing the version manually:

An example of installing SDL2 `v2.0.12` via `git`:
```bash
git clone https://github.com/vlang/sdl.git ~/.vmodules
Expand Down
36 changes: 36 additions & 0 deletions setup.vsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os

os.chdir(os.dir(os.executable()))!

res := os.execute('sdl2-config --version')
if res.exit_code != 0 {
println('sdl2-config is missing')
exit(1)
}
system_version := res.output.trim_space()
println('Your version is ${system_version}')

remotes := os.execute('git branch -r --list')
if remotes.exit_code != 0 {
println('git is missing')
exit(1)
}
mut supported_versions := remotes.output.split_into_lines().map(it.trim_space()).filter(it.starts_with('origin/2')).map(it.all_after('origin/'))
supported_versions.insert(0, '2.0.8') // master
println('The SDL module officially supports these versions of SDL:\n ${supported_versions}')

if system_version == '2.0.8' {
println('Setting up the repository to branch master, that exactly matches your system SDL version 2.0.8')
os.system('git checkout master')
exit(0)
}

if system_version in supported_versions {
println('Setting up the repository to branch ${system_version} that exactly matches your system SDL version')
os.system('git checkout ${system_version}')
exit(0)
}

base_version := '${system_version.all_before_last('.')}.0'
println('Setting up the repository to branch ${base_version}, that best matches the system SDL version: ${system_version} ...')
os.system('git checkout ${base_version}')
Loading