1 ############################################################################
3 # Author: Daniel Giritzer, S1510306010
6 # Description: Universal Makefile for Unix based Operating Systems
8 # Remarks: Compatible with CodeBlocks (C::B)
9 # PROJNAME variable should match your project name!
11 # Usage: make debug - builds debug version
12 # make release - builds release version
13 # make all - builds debug and release version
14 # make clean - cleans project
15 # make rebuild - builds everything from scratch
16 ############################################################################
21 WORKDIR = $(shell pwd)
22 SOURCES := $(shell ls *.c)
32 CFLAGS = -Wall -fexceptions
38 ############################
39 #DEBUG SETTINGS | EDIT: 2/3
40 ############################
42 CFLAGS_DEBUG = $(CFLAGS) -g
43 RESINC_DEBUG = $(RESINC)
44 RCFLAGS_DEBUG = $(RCFLAGS)
45 LIBDIR_DEBUG = $(LIBDIR)
47 LDFLAGS_DEBUG = $(LDFLAGS)
48 OBJDIR_DEBUG = obj/Debug
50 OUT_DEBUG = bin/Debug/$(PROJNAME)
53 ##############################
54 #RELEASE SETTINGS | EDIT: 3/3
55 ##############################
57 CFLAGS_RELEASE = $(CFLAGS) -O2
58 RESINC_RELEASE = $(RESINC)
59 RCFLAGS_RELEASE = $(RCFLAGS)
60 LIBDIR_RELEASE = $(LIBDIR)
62 LDFLAGS_RELEASE = $(LDFLAGS) -s
63 OBJDIR_RELEASE = obj/Release
65 OUT_RELEASE = bin/Release/$(PROJNAME)
67 ############################
68 #OBJECT LISTS | DO NOT EDIT!
69 ############################
70 OBJ_DEBUG = $(addprefix $(OBJDIR_DEBUG)/,$(SOURCES:%.c=%.o))
71 OBJ_RELEASE = $(addprefix $(OBJDIR_RELEASE)/,$(SOURCES:%.c=%.o))
74 ##########################
75 #FUNCTIONS | DO NOT EDIT!
76 ##########################
79 all All: debug release
80 clean Clean: cleanDebug cleanRelease
81 rebuild Rebuild: clean debug release
85 test -d bin/Debug || mkdir -p bin/Debug
86 test -d $(OBJDIR_DEBUG) || mkdir -p $(OBJDIR_DEBUG)
90 debug Debug: before_debug out_debug after_debug
92 out_debug: before_debug $(OBJ_DEBUG) $(DEP_DEBUG)
93 $(LD) $(LDFLAGS_DEBUG) $(LIBDIR_DEBUG) $(OBJ_DEBUG) $(LIB_DEBUG) -o $(OUT_DEBUG)
95 $(OBJDIR_DEBUG)/%.o: %.c
96 $(CC) $(CFLAGS_DEBUG) $(INC_DEBUG) -c $< -D_DEBUG -o $@
98 clean_debug cleanDebug:
99 rm -f $(OBJ_DEBUG) $(OUT_DEBUG)
101 rm -rf $(OBJDIR_DEBUG)
106 test -d bin/Release || mkdir -p bin/Release
107 test -d $(OBJDIR_RELEASE) || mkdir -p $(OBJDIR_RELEASE)
111 release Release: before_release out_release after_release
113 out_release: before_release $(OBJ_RELEASE) $(DEP_RELEASE)
114 $(LD) $(LDFLAGS_RELEASE) $(LIBDIR_RELEASE) $(OBJ_RELEASE) $(LIB_RELEASE) -o $(OUT_RELEASE)
116 $(OBJDIR_RELEASE)/%.o: %.c
117 $(CC) $(CFLAGS_RELEASE) $(INC_RELEASE) -c $< -o $@
119 clean_release cleanRelease:
120 rm -f $(OBJ_RELEASE) $(OUT_RELEASE)
122 rm -rf $(OBJDIR_RELEASE)
124 .PHONY: before_debug after_debug clean_debug cleanDebug before_release after_release clean_release cleanRelease