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

Add Makefile, update build instructions #257

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/*
lite
56 changes: 56 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down