Skip to content

Commit

Permalink
Add makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
deric committed Feb 19, 2021
1 parent dae5346 commit 3d90450
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
45 changes: 45 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

set -x
cflags="-Wall -O3 -g -std=gnu11 -fno-strict-aliasing -Isrc"
lflags="-lSDL2 -lm"

Expand Down

0 comments on commit 3d90450

Please sign in to comment.