-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
52 lines (45 loc) · 1.08 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
####
#### Generic Makefile only for C projects
####
#### This file is public domain.
#### J. Camilo Gomez C.
####
##############################
### Configurable variables ###
##############################
# The compiler
CC = gcc
# The linker
LD = gcc
# Flags to pass to the compiler for release builds
CFLAGS ?= -std=c89 -Wall -O3
# Flags to pass to the linker
LFLAGS ?= -lm -lpthread
# Output directories
OBJ_DIR := obj
BIN_DIR := bin
OBJ_EXT ?= .o
#####################################
### Do NOT touch the lines below ###
#####################################
INC := -I. $(addprefix -I./,$(dir $(wildcard src/**/*.h)))
SRC := $(wildcard src/**/*.c)
OBJ := $(addprefix $(OBJ_DIR)/,$(SRC:.c=$(OBJ_EXT)))
OUT = $(BIN_DIR)/$(notdir $(CURDIR))
.SUFFIXES:
.PHONY: clean show
$(OUT): $(OBJ)
@mkdir -p $(dir $@)
$(LD) $^ $(LFLAGS) -o $@
@echo "-------------------------------"
@echo "Build Success!"
$(OBJ_DIR)/%$(OBJ_EXT): %.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(INC) -c $< -o $@
run: $(OUT)
@./$(OUT)
test: run
clean:
@$(RM) -rf $(OUT) $(OBJ_DIR) $(BIN_DIR)
show:
@echo SRC = $(SRC)