forked from OpenDUNE/OpenDUNE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.tcc
132 lines (109 loc) · 2.89 KB
/
Makefile.tcc
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# Settings via env variables
# CC - Your C compiler
# CFLAGS - Your CFLAGS (we add a few we find essential)
# LDFLAGS - Your LDFLAGS
# LIBS - Which libs to include (we add a few we find essential)
#
# Settings via parameters
# OSX:=1 - To compile on/for OSX
# WIN32:=1 - To compile on/for Windows
# STATIC:=1 - If you want to compile static (default yes for WIN32)
CFLAGS := $(CFLAGS)
ifdef WIN32
CFLAGS := $(CFLAGS) -DWIN32
ifndef STATIC
STATIC := 1
endif
EXTENSION := .exe
LIB_EXTENSION := .dll
else
EXTENSION :=
ifdef OSX
LIB_EXTENSION := .dylib
else
LIB_EXTENSION := .so
endif
endif
ifndef SDL_INCLUDE
ifdef OSX
SDL_INCLUDE := /opt/local/include/SDL
else
SDL_INCLUDE := /usr/include/SDL
endif
endif
ifdef STATIC
LIBS := $(LIBS)
else
LIBS := $(LIBS)
endif
ifdef OSX
ifdef STATIC
LDFLAGS := $(LDFLAGS) `sdl-config --static-libs`
else
LDFLAGS := $(LDFLAGS) `sdl-config --libs`
endif
else
LIBS := $(LIBS) -lSDL
ifdef WIN32
LIBS := $(LIBS) -lwinmm
endif
endif
ifdef WIN32
LIBS := $(LIBS) -lSDL -lwinmm
endif
ifdef OSX
LIBS := $(LIBS) -lSDL -L/opt/local/lib
endif
ifdef ALSA
LIBS := $(LIBS) -lasound
CFLAGS := $(CFLAGS) -DALSA
endif
CFLAGS := $(CFLAGS) -g -Wall
LDFLAGS := $(LDFLAGS) -g
HEADER := $(shell ls decompiled/*.h src/*.h src/*/*.h include/*.h 2>/dev/null)
DECOMPILED := $(shell ls decompiled/*.c 2>/dev/null)
DECOMPILED_OBJS := $(DECOMPILED:%.c=objs/%.o)
SOURCE := $(shell ls src/*.c src/*/*.c 2>/dev/null)
SOURCE_OBJS := $(SOURCE:%.c=objs/%.o)
RES := $(shell mkdir -p objs/decompiled objs/src)
ifdef VERBOSE
Q =
else
Q = @
endif
all: opendune$(EXTENSION)
objs/depend: tools/depend/depend.cpp
@echo "[Compiling / Linking] depend"
$(Q)$(CXX) $(LDFLAGS) -o $@ $^
ifeq ($(filter depend clean, $(MAKECMDGOALS)),)
-include Makefile.dep
endif
ifeq ($(filter depend, $(MAKECMDGOALS)),)
Makefile.dep: objs/depend $(SOURCE) $(DECOMPILED) $(HEADER)
else
Makefile.dep: objs/depend FORCE
endif
@echo "[Dependency Check] All files"
$(Q)objs/depend -fMakefile.dep.tmp -o.o -Y -v -- $(CFLAGS) -I include -- $(DECOMPILED) $(SOURCE) 2>/dev/null
$(Q)cat Makefile.dep.tmp | sed 's@^src@objs/src@g;s@^decompiled@objs/decompiled@g' > Makefile.dep
$(Q) rm -f Makefile.dep.tmp Makefile.dep.tmp.bak
depend: Makefile.dep
objs/%.o: %.c
$(shell mkdir -p `dirname $@`)
@echo "[Compiling] $<"
$(Q)cat $< | perl -p -e "s/'([A-Z\s]{4})'/'0x' . unpack('H*', \$$1)/ge" > $<.tmp.c
$(Q)$(CC) $(CFLAGS) -c $<.tmp.c -o $@ -I include/ -I $(SDL_INCLUDE)
$(Q)rm -f $<.tmp.c
opendune$(EXTENSION): $(DECOMPILED_OBJS) $(SOURCE_OBJS)
@echo "[Linking] $@"
$(Q)$(CC) $(LDFLAGS) -o $@ $(DECOMPILED_OBJS) $(SOURCE_OBJS) $(LIBS)
clean:
@echo "[Cleaning] opendune"
$(Q)rm -f Makefile.dep opendune$(EXTENSION) $(DECOMPILED_OBJS) $(SOURCE_OBJS)
run: all
$(Q)./opendune$(EXTENSION)
run-gdb: all
$(Q)gdb --ex run --args ./opendune$(EXTENSION)
run-prof: all
$(Q)./opendune$(EXTENSION) && gprof opendune | less
FORCE: