-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile-build
91 lines (66 loc) · 1.49 KB
/
Makefile-build
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# Main Makefile
CC := gcc
CFLAGS := -Wall -MMD
# Default target
TARGET := debug
# Check for debug/release build
ifeq ($(TARGET), debug)
CFLAGS += -g -DDEBUG
else
CFLAGS += -O3
endif
# Library name for dll
LIB_NAME :=
# OS-dependent variables
ifeq ($(OS),Windows_NT)
BIN := main-$(TARGET).exe
DLE := dll
ODIR := obj/windows
CFLAGS+= -mno-ms-bitfields
# LOADLIBES := -municode
else
BIN := aviao
DLE := so
ODIR := obj/linux
endif
# Directories
IDIR := include
SDIR := src
# Include Paths
INCLUDE_PATHS := -I$(IDIR)
# Libraries
LIBS :=
#CFLAGS += `pkg-config --cflags $(LIBS)`
LOADLIBES = -lm -lGL -lGLU -lglut
#LOADLIBES += `pkg-config --libs $(LIBS)`
#Compilation line
COMPILE := $(CC) $(CFLAGS) $(INCLUDE_PATHS)
#FILEs
#---------------Source----------------#
SRCS := $(wildcard $(SDIR)/*.c)
#---------------Object----------------#
OBJS := $(SRCS:$(SDIR)/%.c=$(ODIR)/$(TARGET)/%.o)
#-------------Dependency--------------#
DEPS := $(OBJS:%.o=%.d)
# Build Rules
all: $(OBJS) $(BIN)
debug: all
release: all
run: $(BIN)
./$(BIN)
$(BIN): $(OBJS) main.c
$(COMPILE) $(OBJS) main.c -o $(BIN) $(LOADLIBES)
dll: LOADLIBES += -lm -fPIC
dll: $(OBJS)
$(COMPILE) -shared -o lib$(LIB_NAME).$(DLE) $(OBJS) $(LOADLIBES)
# Include all .d files
-include $(DEPS)
$(ODIR)/$(TARGET)/%.o: $(SDIR)/%.c
@mkdir -p $(ODIR)/$(TARGET)
$(COMPILE) -c $< -o $@ $(LOADLIBES)
# Other Rules
init:
@mkdir $(IDIR) $(SDIR)
clean:
-rm -rf $(ODIR)/ *.d $(BIN) lib$(LIB_NAME).$(DLE)
.PHONY: all init release debug dll run clean