From c943fb2a023bb5de0466a2354a11fec5fecd1052 Mon Sep 17 00:00:00 2001 From: Tony Aldridge Date: Sat, 17 Aug 2013 10:43:55 +0100 Subject: [PATCH] Started adding the bare basics in documentation --- LICENSE | 2 +- Makefile.in | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 39 +++++++++++++++++++++++++++++++++++--- configure | 19 +++++++++++++++++++ 4 files changed, 110 insertions(+), 4 deletions(-) create mode 100644 Makefile.in create mode 100755 configure diff --git a/LICENSE b/LICENSE index cc685ad6e1a..5e611b20f10 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2013 Tony Aldridge +Copyright (c) 2013 Mozilla Foundation Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/Makefile.in b/Makefile.in new file mode 100644 index 00000000000..9de30621a41 --- /dev/null +++ b/Makefile.in @@ -0,0 +1,54 @@ +VPATH=%VPATH% + +RUSTC ?= rustc +RUSTFLAGS ?= --cfg image --cfg mixer +SDL_PREFIX ?= /usr/local/lib +AR ?= ar +CHMOD ?= chmod +CP ?= cp +LD ?= ld +MV ?= mv +RM ?= rm + +RUST_SRC = $(shell find $(VPATH)/src/. -type f -name '*.rs') + +.PHONY: all +all: libsdl.dummy + +UNAME=$(shell uname) + +ifeq ($(UNAME),Darwin) +SDLXMAIN=libSDLXmain.a + +ifeq (%SDL_MODE%,framework) +RUSTFLAGS+=--cfg mac_framework +else +RUSTFLAGS+=--cfg mac_dylib +endif + +else +SDLXMAIN= +endif + +libsdl.dummy: src/sdl.rc $(RUST_SRC) $(SDLXMAIN) + $(RUSTC) $(RUSTFLAGS) $< -o $@ + touch $@ + +demos: demo/demo.rc libsdl.dummy + $(RUSTC) -L . $< -o $@ + +# Darwin-specific hack to change the name of `main` to `SDLX_main` +$(SDLXMAIN): $(SDL_PREFIX)/libSDLmain.a + $(CP) $< $@ + $(AR) -x $@ SDLMain.o || $(RM) -f $@ + $(LD) -r SDLMain.o -o SDLXMain.o -alias _main _SDLX_main -unexported_symbol main || $(RM) -f $@ + $(MV) SDLXMain.o SDLMain.o || $(RM) -f $@ + $(CHMOD) u+w $@ || $(RM) -f $@ + $(AR) -r $@ SDLMain.o || $(RM) -f $@ + +demo: demos + ./demos + +.PHONY: clean +clean: + rm -f sdl-test *.so *.dylib *.dll *.dummy demos diff --git a/README.md b/README.md index 4500be75dc7..497ccb3e765 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,37 @@ -rust-sdl2 -========= +# Rust-SDL2 +Bindings for SDL2 in Rust +# Overview -SDL2 bindings for Rust +Rust-SDL2 is a library for talking to the new SDL2.0 libraries from Rust. Low-level C components are wrapped in Rust code to make them more idiomatic and abstract away inappropriate manual memory management. + +In addition, it provides optional APIs to a number of common SDL extension libraries. + +Rust-SDL2 uses the MIT license. + +If you want a library compatible with earlier versions of SDL, please see https://github.com/brson/rust-sdl + +# Requirements + +* *Rust* - we currently compile against the *Master* branch. The releases on http://www.rust-lang.org tend to not work. +* *SDL2.0 development libraries* - install through your favourite package management tool, or via http://www.libsdl.org/ + +# Installation +Clone this repo, run `./configure`, and then `make`. To see an example of the code in use, *make demos*. + +# Demo + +To compile the demo: + +> rustc -L$PWD/src demo/demo.rc + + +Then run: + +> ./demo/demo + +Or you could instead just use + +> make demo + +# When things go wrong +Rust, and Rust-SDL2, are both still heavily in development, and you may run into teething issues when using this. Before panicking, check that you're using the latest Master branch of Rust, check that you've updated Rust-SDL2 to the latest version, and run `make clean` and `./configure`. If that fails, please let us know on the issue tracker. diff --git a/configure b/configure new file mode 100755 index 00000000000..8c00276f1be --- /dev/null +++ b/configure @@ -0,0 +1,19 @@ +#!/bin/bash + +SRCDIR="$(cd $(dirname $0) && pwd)" + +if test `uname` = 'Darwin'; then + if test "x${SDL_MODE}" == "x"; then + if test -e /usr/local/lib/libSDL.dylib -o -e /usr/lib/libSDL.dylib; then + SDL_MODE=dylib + else + SDL_MODE=framework + fi + fi + PLATFORM_COMMANDS="-e s#%SDL_MODE%#${SDL_MODE}#" +else + PLATFORM_COMMANDS="" +fi + +sed -e "s#%VPATH%#${SRCDIR}#" $PLATFORM_COMMANDS ${SRCDIR}/Makefile.in > Makefile +