diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..0e400b35 --- /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 +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 diff --git a/build.sh b/build.sh index 308ebf94..5499492d 100755 --- a/build.sh +++ b/build.sh @@ -1,5 +1,5 @@ #!/bin/bash - +set -x cflags="-Wall -O3 -g -std=gnu11 -fno-strict-aliasing -Isrc" lflags="-lSDL2 -lm"