-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
64 lines (47 loc) · 1.24 KB
/
Makefile
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
59
60
61
62
63
64
# Elegant makefile
# Name of the project
PROJ_NAME=ustellara
# PREFIX is enviroment variable, but if its not set, then set default value
ifeq ($(PREFIX),)
PREFIX := /usr/local
endif
# .c files
C_SOURCE=$(wildcard ./src/*.c)
# .h files
H_SOURCE=$(wildcard ./src/*.h)
# Object files
OBJ=$(subst .c,.o,$(subst src,build/objects,$(C_SOURCE)))
# Compiler and linker
CC=gcc
# Flags for compiler
CC_FLAGS=-c \
-W \
-Wall \
-fcommon
# Command used at clean target
RM = rm -rf
# Compiling and linking
all: objFolder $(PROJ_NAME)
$(PROJ_NAME): $(OBJ)
@ echo 'Building binary using GCC linker: $@'
$(CC) $^ -o ./build/$@ -lncurses -lpthread
@ echo 'Finished building binary: $@'
@ echo ' '
./build/objects/%.o: ./src/%.c ./src/%.h
@ echo 'Building target using GCC compiler: $<'
$(CC) $< $(CC_FLAGS) -o $@ -lncurses -lpthread
@ echo ' '
./build/objects/main.o: ./src/main.c $(H_SOURCE)
@ echo 'Building target using GCC compiler: $< '
$(CC) $< $(CC_FLAGS) -o $@ -lncurses -lpthread
@ echo ' '
objFolder:
@ mkdir -p build
@ mkdir -p build/objects
install:
install -d $(DESTDIR)$(PREFIX)/bin
install -m 655 ./build/$(PROJ_NAME) $(DESTDIR)$(PREFIX)/bin
clean:
@ $(RM) ./build/objects/*.o $(PROJ_NAME)
@ rmdir ./build/objects
.PHONY: all clean