]> Shamusworld >> Repos - legend/blob - makefile
Initial commit for the Legend of A... project!
[legend] / makefile
1 #
2 # Unified Makefile for Apple 2 SDL
3 #
4 # by James Hammons
5 # (C) 2014 Underground Software
6 # This software is licensed under the GPL v3
7 #
8
9 FIND = find
10 FINDSDL2 := $(shell which $(CROSS)sdl2-config 2> /dev/null)
11
12 # Figure out which system we're compiling for, and set the appropriate variables
13
14 ifeq "$(CROSS)" ""
15 OSTYPE   := $(shell uname -a)
16
17 # Win32
18 ifeq "$(findstring Msys,$(OSTYPE))" "Msys"
19
20 SYSTYPE    = __GCCWIN32__
21 EXESUFFIX  = .exe
22 ICON       = obj/icon.o
23 SDLLIBTYPE = --libs
24 MSG        = Win32 on MinGW
25
26 # Should catch both 'darwin' and 'darwin7.0'
27 else ifeq "$(findstring Darwin,$(OSTYPE))" "Darwin"
28
29 SYSTYPE    = __GCCUNIX__ -D_OSX_
30 EXESUFFIX  =
31 ICON       =
32 SDLLIBTYPE = --static-libs
33 MSG        = Mac OS X
34
35 # *nix
36 else ifeq "$(findstring Linux,$(OSTYPE))" "Linux"
37
38 SYSTYPE    = __GCCUNIX__
39 EXESUFFIX  =
40 ICON       =
41 SDLLIBTYPE = --libs
42 MSG        = generic Unix/Linux
43
44 # Throw error, unknown OS
45 else
46
47 $(error OS TYPE UNDETECTED)
48
49 endif
50 # Cross compile using MXE under Linux host
51 else
52
53 SYSTYPE    = __GCCWIN32__
54 EXESUFFIX  = .exe
55 ICON       = obj/icon.o
56 SDLLIBTYPE = --libs
57 MSG        = Win32 under MXE (cross compile)
58
59 endif
60
61 CC         = $(CROSS)gcc
62 LD         = $(CROSS)gcc
63 TARGET     = legend
64
65 SDL_CFLAGS = `$(CROSS)sdl2-config --cflags`
66 SDL_LIBS   = `$(CROSS)sdl2-config $(SDLLIBTYPE)` -lSDL2_image
67 DEFINES    = -D$(SYSTYPE)
68 GCC_DEPS   = -MMD
69
70 # Note that we use optimization level 2 instead of 3--3 doesn't seem to gain much over 2
71 #CFLAGS   = -MMD -Wall -Wno-switch -O2 -D$(SYSTYPE) -ffast-math -fomit-frame-pointer `sdl2-config --cflags`
72 #CPPFLAGS = -MMD -Wall -Wno-switch -Wno-non-virtual-dtor -O2 -D$(SYSTYPE) \
73 # No optimization and w/gcov flags, so that we get an accurate picture from gcov
74 #CFLAGS   = -MMD -Wall -Wno-switch -D$(SYSTYPE) \
75 #               -ffast-math -fomit-frame-pointer `sdl2-config --cflags` -fprofile-arcs -ftest-coverage
76 #CPPFLAGS = -MMD -Wall -Wno-switch -Wno-non-virtual-dtor -D$(SYSTYPE) \
77 #               -ffast-math -fomit-frame-pointer `sdl2-config --cflags` -fprofile-arcs -ftest-coverage
78 # No optimization for profiling with gprof...
79 #CFLAGS   = -MMD -Wall -Wno-switch -D$(SYSTYPE) \
80 #               -ffast-math `sdl2-config --cflags` -pg -g
81 #CPPFLAGS = -MMD -Wall -Wno-switch -Wno-non-virtual-dtor -D$(SYSTYPE) \
82 #               -ffast-math `sdl2-config --cflags` -pg -g
83 #               -fomit-frame-pointer `sdl2-config --cflags` -g
84 #               -fomit-frame-pointer `sdl2-config --cflags` -DLOG_UNMAPPED_MEMORY_ACCESSES
85 CFLAGS   = $(GCC_DEPS) -Wall -Wno-switch $(DEFINES) -ffast-math $(SDL_CFLAGS) -pg -g
86 CPPFLAGS = $(GCC_DEPS) -Wall -Wno-switch -Wno-non-virtual-dtor $(DEFINES) \
87                 -ffast-math $(SDL_CFLAGS) -pg -g
88
89 LDFLAGS =
90
91 #LIBS = -L/usr/local/lib -L/usr/lib `sdl2-config $(SDLLIBTYPE)` -lstdc++ -lz $(GLLIB)
92 # Link in the gcov library (for profiling purposes)
93 #LIBS = -L/usr/local/lib -L/usr/lib `sdl2-config $(SDLLIBTYPE)` -lstdc++ -lz $(GLLIB) -lgcov
94 # Link in the gprof lib
95 #LIBS = -L/usr/local/lib -L/usr/lib `sdl2-config $(SDLLIBTYPE)` -lstdc++ -lz $(GLLIB) -pg
96 #LIBS = -L/usr/local/lib -L/usr/lib $(SDL_LIBS) -lstdc++ -lz $(GLLIB) -pg
97 LIBS = $(SDL_LIBS) -lstdc++ -lz $(GLLIB) -pg
98
99 #INCS = -I. -I./src -I/usr/local/include -I/usr/include
100 INCS = -I. -I./src
101
102 OBJS = \
103         obj/data.o            \
104         obj/log.o             \
105         obj/sound.o           \
106         obj/sprite.o          \
107         obj/tile.o            \
108         obj/video.o           \
109         obj/legend.o          \
110         $(ICON)
111
112 all: checkenv message obj $(TARGET)$(EXESUFFIX)
113         @echo
114         @echo -e "\033[01;33m***\033[00;32m Looks like it compiled OK... Give it a whirl!\033[00m"
115
116 # Check the compilation environment, barf if not appropriate
117
118 checkenv:
119         @echo
120         @echo -en "\033[01;33m***\033[00;32m Checking compilation environment... \033[00m"
121 ifeq "$(FINDSDL2)" ""
122         @echo
123         @echo
124         @echo -e "\033[01;33mIt seems that you don't have the SDL 2 development libraries installed. If you"
125         @echo -e "have installed them, make sure that the sdl2-config file is somewhere in your"
126         @echo -e "path and is executable.\033[00m"
127         @echo
128 #Is there a better way to break out of the makefile?
129         @false;
130 #       @break
131 # YES! But ignores all the echo's above... :-/
132 #$(error SDL2 MISSING)
133
134 else
135         @echo -e "\033[01;37mOK\033[00m"
136 endif
137
138 message:
139         @echo
140         @echo -e "\033[01;33m***\033[00;32m Building Legend of Ayeron SDL2 for $(MSG)...\033[00m"
141         @echo
142
143 clean:
144         @echo -en "\033[01;33m***\033[00;32m Cleaning out the garbage...\033[00m"
145         @rm -rf obj
146         @rm -f ./$(TARGET)$(EXESUFFIX)
147         @echo -e "\033[01;37mdone!\033[00m"
148
149 obj:
150         @mkdir obj
151
152 # This is only done for Win32 at the moment...
153
154 ifneq "" "$(ICON)"
155 $(ICON): res/$(TARGET).rc res/$(TARGET).ico
156         @echo -e "\033[01;33m***\033[00;32m Processing icon...\033[00m"
157         @$(CROSS)windres -i res/$(TARGET).rc -o $(ICON) --include-dir=./res
158 endif
159
160 obj/%.o: src/%.c
161         @echo -e "\033[01;33m***\033[00;32m Compiling $<...\033[00m"
162         @$(CC) $(CFLAGS) $(INCS) -c $< -o $@
163
164 obj/%.o: src/%.cpp
165         @echo -e "\033[01;33m***\033[00;32m Compiling $<...\033[00m"
166         @$(CC) $(CPPFLAGS) $(INCS) -c $< -o $@
167
168 #GUI compilation...
169 obj/%.o: src/gui/%.cpp
170         @echo -e "\033[01;33m***\033[00;32m Compiling $<...\033[00m"
171         @$(CC) $(CPPFLAGS) $(INCS) -c $< -o $@
172
173 $(TARGET)$(EXESUFFIX): $(OBJS)
174         @echo -e "\033[01;33m***\033[00;32m Linking it all together...\033[00m"
175         @$(LD) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
176 #       strip --strip-all vj$(EXESUFFIX)
177 #       upx -9 vj$(EXESUFFIX)
178
179 statistics:
180         @echo -n "Lines in source files: "
181         @-$(FIND) ./src -name "*.cpp" | xargs cat | wc -l
182         @echo -n "Lines in header files: "
183         @-$(FIND) ./src -name "*.h" | xargs cat | wc -l
184
185 # Pull in dependencies autogenerated by gcc's -MMD switch
186 # The "-" in front in there just in case they haven't been created yet
187
188 -include obj/*.d
189