diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..5fd32e2a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build/* +lite diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..16c4c85d --- /dev/null +++ b/Makefile @@ -0,0 +1,56 @@ +PREFIX ?= $(HOME)/.local + +OBJ_DIR ?= $(shell pwd)/build +SRC_DIR := $(shell pwd)/src + +SRC_EXT := c +OBJ_EXT := o + +SRCS := $(shell find $(SRC_DIR) -name *.$(SRC_EXT)) + +SOURCES := $(foreach sname, $(SRCS), $(abspath $(sname))) +OBJECTS := $(patsubst $(SRC_DIR)/%.$(SRC_EXT), $(OBJ_DIR)/%.$(OBJ_EXT), $(SOURCES)) + +CFLAGS ?= +LDLAGS ?= + +CFLAGS +=-Wall -O3 -g -std=gnu11 -fno-strict-aliasing -Isrc +LDFLAGS +=-lSDL2 -lm -ldl + +ifeq ($(OS),Windows_NT) + TARGET ?= lite.exe + CC := x86_64-w64-mingw32-gcc + CFLAGS += -DLUA_USE_POPEN -Iwinlib/SDL2-2.0.10/x86_64-w64-mingw32/include + LDFLAGS += -Lwinlib/SDL2-2.0.10/x86_64-w64-mingw32/lib -lmingw32 -lSDL2main -mwindows res.res + x86_64-w64-mingw32-windres res.rc -O coff -o res.res +else + TARGET ?= lite + CC := gcc + UNAME := $(shell uname -s) + ifeq ($(UNAME_S),Linux) + CFLAGS +=-DLUA_USE_POSIX -fPIC -DLUA_COMPAT_ALL + endif +endif + +all: $(TARGET) + +$(TARGET): $(OBJECTS) + $(CC) $^ -o $@ $(LDFLAGS) + +$(OBJ_DIR)/%$(OBJ_EXT): $(SRC_DIR)/%$(SRC_EXT) + @mkdir -p $(dir $@) + $(CC) -c $(CFLAGS) $< -o $@ + +clean: + -rm -f $(OBJECTS) $(TARGET) + +.PHONY: clean + +install: all + @echo Installing to $(PREFIX) ... + @mkdir -p $(PREFIX)/bin/ + @cp -fp $(TARGET) $(PREFIX)/bin/ + @mkdir -p $(PREFIX)/bin/data + @echo Copying lua files to $(PREFIX)/bin/data + @cp -r data/* $(PREFIX)/bin/data/ + @echo Complete. diff --git a/README.md b/README.md index 6081e8b1..5f4ffc08 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,25 @@ The editor can be customized by making changes to the [user module](data/user/init.lua). ## Building -You can build the project yourself on Linux using the `build.sh` script -or on Windows using the `build.bat` script *([MinGW](https://nuwen.net/mingw.html) is required)*. + +### Linux + +You can build the project yourself on Linux with following prerequisites: + + * GCC + * Simple DirectMedia Layer development files + +#### Debian/Ubuntu + +``` +sudo apt install libsdl2-dev gcc make +make +sudo make install PREFIX=/usr/local +``` + +### Windows + +Using the `build.bat` script *([MinGW](https://nuwen.net/mingw.html) is required)*. Note that the project does not need to be rebuilt if you are only making changes to the Lua portion of the code.