1## makefile.base - common make-file for compiling exhale on Linux and MacOS platforms 2 # written by C. R. Helmrich, last modified in 2021 - see License.htm for legal notices 3 # 4 # The copyright in this software is being made available under the exhale Copyright License 5 # and comes with ABSOLUTELY NO WARRANTY. This software may be subject to other third- 6 # party rights, including patent rights. No such rights are granted under this License. 7 # 8 # Copyright (c) 2018-2021 Christian R. Helmrich, project ecodis. All rights reserved. 9 ## 10 11## verification of config parameter 12ifneq ($(CONFIG), CONSOLE) 13 ifneq ($(CONFIG), LIBRARY) 14 CONFIG_ERR = TRUE 15 endif 16endif 17 18# specification of used executables 19AR = ar 20ASM = nasm 21CPP = g++ 22LD = $(CPP) 23 24# location and name of output files 25ifeq ($(CONFIG), CONSOLE) 26 STAT_DEBUG_OUT = $(DIR_BIN)/$(PRD_NAME)d 27 STAT_RELEASE_OUT = $(DIR_BIN)/$(PRD_NAME) 28 DYN_DEBUG_OUT = $(DIR_BIN)/$(PRD_NAME)Dynd 29 DYN_RELEASE_OUT = $(DIR_BIN)/$(PRD_NAME)Dyn 30else 31 ifeq ($(CONFIG), LIBRARY) 32 STAT_DEBUG_OUT = $(DIR_LIB)/lib$(PRD_NAME)d.a 33 STAT_RELEASE_OUT = $(DIR_LIB)/lib$(PRD_NAME).a 34 DYN_DEBUG_OUT = $(DIR_LIB)/lib$(PRD_NAME)Dynd.so 35 DYN_RELEASE_OUT = $(DIR_LIB)/lib$(PRD_NAME)Dyn.so 36 endif 37endif 38 39# type of debug and release objects 40DEBUG_OBJS = $(OBJS:.o=.d.o) 41RELEASE_OBJS = $(OBJS:.o=.r.o) 42 43 44## specification of compiler flags 45CPPFLAGS = -fPIC $(DEFS) -I$(CURDIR)/$(DIR_INC) -Wall -Werror -Wshadow -D_FILE_OFFSET_BITS=64 -std=c++11 $(CXXFLAGS) 46 47# setting of 32-bit compiler flags 48MM32?=0 49ifeq ($(MM32), 1) 50 CPPFLAGS+=-m32 51endif 52 53# setting of MacOSX compiler flags 54UNIVERSAL2?=0 55ifeq ($(UNIVERSAL2), 1) 56 CPPFLAGS+=-arch x86_64 -arch arm64 -mmacosx-version-min=10.9 57endif 58 59# debug and release compiler flags 60DEBUG_CPPFLAGS = -g -D_DEBUG 61RELEASE_CPPFLAGS = -O3 -Wuninitialized 62 63 64## specification of linker flags 65ALL_LDFLAGS = -Wall $(ADDITIONAL_LDFLAGS) 66ifeq ($(OS), Windows_NT) 67 ALL_LDFLAGS+=-municode 68endif 69 70# setting of 32-bit linker flags 71ifeq ($(MM32), 1) 72 ALL_LDFLAGS+=-m32 73endif 74 75# setting of MacOSX linker flags 76ifeq ($(UNIVERSAL2), 1) 77 ALL_LDFLAGS+=-arch x86_64 -arch arm64 -mmacosx-version-min=10.9 78endif 79 80# debug and release linker flags 81ifeq ($(CONFIG), CONSOLE) 82 LDFLAGS = $(ALL_LDFLAGS) 83 DEBUG_LDFLAGS = 84 RELEASE_LDFLAGS = 85else 86 ifeq ($(CONFIG), LIBRARY) 87 LDFLAGS = $(ALL_LDFLAGS) -shared 88 DEBUG_LDFLAGS = -Wl, -soname, lib$(PRD_NAME)Dynd.so 89 RELEASE_LDFLAGS = -Wl, -soname, lib$(PRD_NAME)Dyn.so 90 endif 91endif 92 93 94## specification of assembler flags 95ASMFLAGS = -f elf $(DEFS) 96DEBUG_ASMFLAGS = -g 97RELEASE_ASMFLAGS = 98 99# creation of ASM debug objects 100$(DIR_OBJ)/%.d.o: $(DIR_SRC)/%.asm 101 $(ASM) $(ASMFLAGS) $(DEBUG_ASMFLAGS) -o $@ $< 102 103# creation of ASM release objects 104$(DIR_OBJ)/%.r.o: $(DIR_SRC)/%.asm 105 $(ASM) $(ASMFLAGS) $(RELEASE_ASMFLAGS) -o $@ $< 106 107 108## specification of C and C++ flags 109define COMPILE_AND_DEPEND_DEBUG 110 $(CPP) -c -MMD -MF $(DIR_OBJ)/$*.d.d -MT $(DIR_OBJ)/$*.d.o $(CPPFLAGS) $(DEBUG_CPPFLAGS) -o $@ $(CURDIR)/$< 111 @cp $(DIR_OBJ)/$*.d.d $(DIR_OBJ)/$*.d.p; \ 112 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ 113 -e '/^$$/ d' -e 's/$$/ :/' < $(DIR_OBJ)/$*.d.d >> $(DIR_OBJ)/$*.d.p; \ 114 rm -f $(DIR_OBJ)/$*.d.d 115endef 116define COMPILE_AND_DEPEND_RELEASE 117 $(CPP) -c -MMD -MF $(DIR_OBJ)/$*.r.d -MT $(DIR_OBJ)/$*.r.o $(CPPFLAGS) $(RELEASE_CPPFLAGS) -o $@ $(CURDIR)/$< 118 @cp $(DIR_OBJ)/$*.r.d $(DIR_OBJ)/$*.r.p; \ 119 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ 120 -e '/^$$/ d' -e 's/$$/ :/' < $(DIR_OBJ)/$*.r.d >> $(DIR_OBJ)/$*.r.p; \ 121 rm -f $(DIR_OBJ)/$*.r.d 122endef 123 124# creation of C++ debug objects 125$(DIR_OBJ)/%.d.o: $(DIR_SRC)/%.cpp 126 $(COMPILE_AND_DEPEND_DEBUG) 127 128# creation of C++ release objects 129$(DIR_OBJ)/%.r.o: $(DIR_SRC)/%.cpp 130 $(COMPILE_AND_DEPEND_RELEASE) 131 132# creation of C debug objects 133$(DIR_OBJ)/%.d.o: $(DIR_SRC)/%.c 134 $(COMPILE_AND_DEPEND_DEBUG) 135 136# creation of C release objects 137$(DIR_OBJ)/%.r.o: $(DIR_SRC)/%.c 138 $(COMPILE_AND_DEPEND_RELEASE) 139 140 141## config dependent directory setup 142ifeq ($(CONFIG), CONSOLE) 143 CHECK_DIRS = $(DIR_OBJ) $(DIR_BIN) 144else 145 ifeq ($(CONFIG), LIBRARY) 146 CHECK_DIRS = $(DIR_OBJ) $(DIR_LIB) 147 endif 148endif 149 150 151## specification of build targets 152all: check_errors debug release 153 154debug: check_errors \ 155 $(CHECK_DIRS) \ 156 $(STAT_DEBUG_OUT) 157 158# $(DYN_DEBUG_OUT) \ 159 160release: check_errors \ 161 $(CHECK_DIRS) \ 162 $(STAT_RELEASE_OUT) 163 164# $(DYN_RELEASE_OUT) \ 165 166 167## check for configuration errors 168check_errors: 169 @if [ "$(CONFIG_ERR)" = "TRUE" ]; then\ 170 echo "ERROR: Wrong CONFIG parameter specified: $(CONFIG)";\ 171 false;\ 172 fi 173 174 175## creation of output directories 176$(DIR_BIN): 177 @if [ ! -d $(DIR_BIN) ]; then\ 178 mkdir $(DIR_BIN);\ 179 fi 180 181$(DIR_OBJ): 182 @if [ ! -d $(DIR_OBJ) ]; then\ 183 mkdir $(DIR_OBJ);\ 184 fi 185 186$(DIR_LIB): 187 @if [ ! -d $(DIR_LIB) ]; then\ 188 mkdir $(DIR_LIB);\ 189 fi 190 191 192## creation of binary output files 193ifeq ($(CONFIG), CONSOLE) 194# creation of static debug output 195$(STAT_DEBUG_OUT): $(DEBUG_OBJS) $(STAT_DEBUG_PREREQS) 196 $(LD) -o $@ $(LDFLAGS) $(DEBUG_LDFLAGS) $(DEBUG_OBJS) -L$(DIR_LIB) $(LIBS) $(STAT_LIBS) $(STAT_DEBUG_LIBS) 197# creation of static release output 198$(STAT_RELEASE_OUT): $(RELEASE_OBJS) $(STAT_RELEASE_PREREQS) 199 $(LD) -o $@ $(LDFLAGS) $(RELEASE_LDFLAGS) $(RELEASE_OBJS) -L$(DIR_LIB) $(LIBS) $(STAT_LIBS) $(STAT_RELEASE_LIBS) 200# creation of dynamic debug output 201$(DYN_DEBUG_OUT): $(DEBUG_OBJS) $(DYN_DEBUG_PREREQS) 202 $(LD) -o $@ $(LDFLAGS) $(DEBUG_LDFLAGS) $(DEBUG_OBJS) -L$(DIR_LIB) $(LIBS) $(DYN_LIBS) $(DYN_DEBUG_LIBS) 203# creation of dynamic release output 204$(DYN_RELEASE_OUT): $(RELEASE_OBJS) $(DYN_RELEASE_PREREQS) 205 $(LD) -o $@ $(LDFLAGS) $(RELEASE_LDFLAGS) $(RELEASE_OBJS) -L$(DIR_LIB) $(LIBS) $(DYN_LIBS) $(DYN_RELEASE_LIBS) 206else 207 ifeq ($(CONFIG), LIBRARY) 208# creation of static debug output 209$(STAT_DEBUG_OUT): $(DEBUG_OBJS) 210 $(AR) -crs $@ $(DEBUG_OBJS) 211# creation of static release output 212$(STAT_RELEASE_OUT): $(RELEASE_OBJS) 213 $(AR) -crs $@ $(RELEASE_OBJS) 214# creation of dynamic debug output 215$(DYN_DEBUG_OUT): $(DYN_DEBUG_OUT) 216 ln -fs lib$(PRD_NAME)Dynd.so $@ 217# creation of dynamic release output 218$(DYN_RELEASE_OUT): $(DYN_RELEASE_OUT) 219 ln -fs lib$(PRD_NAME)Dyn.so $@ 220 endif 221endif 222 223 224## clean: delete all created files 225clean: 226 /bin/rm -rf $(DYN_DEBUG_OUT) 227 /bin/rm -rf $(DYN_RELEASE_OUT) 228 /bin/rm -rf $(STAT_DEBUG_OUT) 229 /bin/rm -rf $(STAT_RELEASE_OUT) 230 /bin/rm -rf $(DIR_OBJ) 231 232 233## include needed dependency files 234-include $(OBJS:.o=.d.p) 235-include $(OBJS:.o=.r.p) 236