summaryrefslogtreecommitdiff
path: root/Makefile
blob: 24c88a50bf52f1dc6b576562a0bbf0f17866b968 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
CC = gcc

SOURCE =  src
SOURCE += lib
SOURCE += command

MAJOR = 0
MINOR = 0
PATCH = 1

INCFLAGS  = $(shell echo $(SOURCE) | xargs printf -- '-I%s ')

CCFLAGS  = -std=c89 -Wall -Wextra -pedantic -O2 
CCFLAGS += -DMAJOR=$(MAJOR) -DMINOR=$(MINOR) -DPATCH=$(PATCH) -DCHECK_LINK
CCFLAGS += $(INCFLAGS)

LDFLAGS = -s
LDFLAGS += $(INCFLAGS)

UNAME := $(shell uname)

ifeq ($(UNAME), Linux)
CCFLAGS += -D_GNU_SOURCE
else 
CCFLAGS += -D_DEFAULT_SOURCE
endif

BIN = bin
APP = $(BIN)/app
SRC = $(shell find $(SOURCE) -name "*.c")
DIR = $(shell find $(SOURCE) -type d)
OBJ = $(SRC:%.c=$(BIN)/%.o)

.PHONY: empty dirs run clean build install uninstall

empty: clean build

dirs:
	echo $(DIR) | xargs printf -- '$(BIN)/%s\n' | xargs mkdir -p

run: build
	$(APP)

build: dirs ${OBJ}
	${CC} -o $(APP) $(filter %.o,$^) $(LDFLAGS)

$(BIN)/%.o: %.c
	$(CC) -o $@ -c $< $(CCFLAGS)

clean:
	rm -rf $(APP)
	rm -rf $(BIN)

install:
	cp $(APP) /usr/local/bin/lazysphere

uninstall:
	rm /usr/local/bin/lazysphere