From dae5346cf87142758832f334305189906faa4c81 Mon Sep 17 00:00:00 2001 From: Tomas Barton Date: Fri, 19 Feb 2021 19:40:34 +0100 Subject: [PATCH 1/4] Update build instructions --- README.md | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6081e8b1..e61d8f11 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,24 @@ 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 +./build.sh +``` + +### 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. From 31f0054ee451198c8c0b8291311b8eeb2f788bd2 Mon Sep 17 00:00:00 2001 From: Tomas Barton Date: Fri, 19 Feb 2021 22:03:09 +0100 Subject: [PATCH 2/4] Add makefile --- Makefile | 45 +++++++++++++++++++++++++++++++++++++++++++++ README.md | 4 ++-- 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..50b45a0d --- /dev/null +++ b/Makefile @@ -0,0 +1,45 @@ +PREFIX ?= /usr/local +TARGET ?= lite + +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)) + +CC := gcc +CFLAGS ?= +LDLAGS ?= + +CFLAGS +=-Wall -O3 -g -std=gnu11 -fno-strict-aliasing -Isrc -fPIC -DLUA_COMPAT_ALL +LDFLAGS +=-lSDL2 -lm + +UNAME := $(shell uname -s) +ifeq ($(UNAME_S),Linux) +CFLAGS +=-DLUA_USE_POSIX +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 $(DESTDIR)$(PREFIX) ... + @mkdir -p $(DESTDIR)$(PREFIX)/bin/ + @cp -fp $(TARGET) $(DESTDIR)$(PREFIX)/bin/ + @echo Complete. diff --git a/README.md b/README.md index e61d8f11..f2b410a6 100644 --- a/README.md +++ b/README.md @@ -35,8 +35,8 @@ You can build the project yourself on Linux with following prerequisites: #### Debian/Ubuntu ``` -sudo apt install libsdl2-dev gcc -./build.sh +sudo apt install libsdl2-dev gcc make +make ``` ### Windows From 7c7dc44ce78c2ffde017ced09327024d3753af23 Mon Sep 17 00:00:00 2001 From: Tomas Barton Date: Sat, 20 Feb 2021 09:01:14 +0100 Subject: [PATCH 3/4] Fix installation --- .gitignore | 2 ++ Makefile | 19 +++++++++++-------- README.md | 1 + 3 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 .gitignore 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 index 50b45a0d..5c5fa192 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -PREFIX ?= /usr/local +PREFIX ?= $(HOME)/.local TARGET ?= lite OBJ_DIR ?= $(shell pwd)/build @@ -16,12 +16,12 @@ CC := gcc CFLAGS ?= LDLAGS ?= -CFLAGS +=-Wall -O3 -g -std=gnu11 -fno-strict-aliasing -Isrc -fPIC -DLUA_COMPAT_ALL -LDFLAGS +=-lSDL2 -lm +CFLAGS +=-Wall -O3 -g -std=gnu11 -fno-strict-aliasing -Isrc +LDFLAGS +=-lSDL2 -lm -ldl UNAME := $(shell uname -s) ifeq ($(UNAME_S),Linux) -CFLAGS +=-DLUA_USE_POSIX +CFLAGS +=-DLUA_USE_POSIX -fPIC -DLUA_COMPAT_ALL endif all: $(TARGET) @@ -30,7 +30,7 @@ $(TARGET): $(OBJECTS) $(CC) $^ -o $@ $(LDFLAGS) $(OBJ_DIR)/%$(OBJ_EXT): $(SRC_DIR)/%$(SRC_EXT) - mkdir -p $(dir $@) + @mkdir -p $(dir $@) $(CC) -c $(CFLAGS) $< -o $@ clean: @@ -39,7 +39,10 @@ clean: .PHONY: clean install: all - @echo Installing to $(DESTDIR)$(PREFIX) ... - @mkdir -p $(DESTDIR)$(PREFIX)/bin/ - @cp -fp $(TARGET) $(DESTDIR)$(PREFIX)/bin/ + @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 f2b410a6..5f4ffc08 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ You can build the project yourself on Linux with following prerequisites: ``` sudo apt install libsdl2-dev gcc make make +sudo make install PREFIX=/usr/local ``` ### Windows From 657cb9677e2162e864b883784afac76e5644c7a5 Mon Sep 17 00:00:00 2001 From: Tomas Barton Date: Sat, 20 Feb 2021 09:29:26 +0100 Subject: [PATCH 4/4] Add windows support --- Makefile | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 5c5fa192..16c4c85d 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,4 @@ PREFIX ?= $(HOME)/.local -TARGET ?= lite OBJ_DIR ?= $(shell pwd)/build SRC_DIR := $(shell pwd)/src @@ -12,16 +11,25 @@ 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)) -CC := gcc CFLAGS ?= LDLAGS ?= CFLAGS +=-Wall -O3 -g -std=gnu11 -fno-strict-aliasing -Isrc LDFLAGS +=-lSDL2 -lm -ldl -UNAME := $(shell uname -s) -ifeq ($(UNAME_S),Linux) -CFLAGS +=-DLUA_USE_POSIX -fPIC -DLUA_COMPAT_ALL +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)