exhale/src/makefile.base

306 lines
7.7 KiB
Plaintext
Raw Normal View History

2020-01-02 02:05:09 +01:00
## makefile.base - common make-file for compiling exhale on Linux and MacOS platforms
2020-01-02 03:01:24 +01:00
# written by C. R. Helmrich, last modified in 2020 - see License.htm for legal notices
2020-01-02 02:05:09 +01:00
#
2020-01-02 03:01:24 +01:00
# The copyright in this software is being made available under a Modified BSD-Style License
2020-01-02 02:05:09 +01:00
# and comes with ABSOLUTELY NO WARRANTY. This software may be subject to other third-
# party rights, including patent rights. No such rights are granted under this License.
#
2020-01-02 03:01:24 +01:00
# Copyright (c) 2018-2020 Christian R. Helmrich, project ecodis. All rights reserved.
2020-01-02 02:05:09 +01:00
##
#########################################################
# check CONFIG parameter
#########################################################
ifneq ($(CONFIG), CONSOLE)
ifneq ($(CONFIG), LIBRARY)
CONFIG_ERR = TRUE
endif
endif
#########################################################
# executables used
#########################################################
AR = ar
ASM = nasm
CPP = g++
LD = $(CPP)
#########################################################
# output file names and version information
#########################################################
ifeq ($(CONFIG), CONSOLE)
STAT_DEBUG_OUT = $(DIR_BIN)/$(PRD_NAME)d
STAT_RELEASE_OUT = $(DIR_BIN)/$(PRD_NAME)
DYN_DEBUG_OUT = $(DIR_BIN)/$(PRD_NAME)Dynd
DYN_RELEASE_OUT = $(DIR_BIN)/$(PRD_NAME)Dyn
else
ifeq ($(CONFIG), LIBRARY)
STAT_DEBUG_OUT = $(DIR_LIB)/lib$(PRD_NAME)d.a
STAT_RELEASE_OUT = $(DIR_LIB)/lib$(PRD_NAME).a
DYN_DEBUG_OUT = $(DIR_LIB)/lib$(PRD_NAME)Dynd.so
DYN_RELEASE_OUT = $(DIR_LIB)/lib$(PRD_NAME)Dyn.so
endif
endif
#########################################################
# c compiler flags
#########################################################
# default cpp flags for all configurations
#CPPFLAGS = -Wall -fPIC $(DEFS) -I$(CURDIR)/$(DIR_INC)
CPPFLAGS = -fPIC $(DEFS) -I$(CURDIR)/$(DIR_INC) -Wall -Wshadow -Wno-sign-compare -Werror -D_FILE_OFFSET_BITS=64
##########
# enforce 32-bit build : 1=yes, 0=no
##########
M32?= 0
ifeq ($(M32),1)
CPPFLAGS+=-m32
endif
##########
#
# debug cpp flags
DEBUG_CPPFLAGS = -g -D_DEBUG
#
# release cpp
RELEASE_CPPFLAGS = -O3 -Wuninitialized
#########################################################
# linker flags
#########################################################
# linker flags for all
ALL_LDFLAGS = -Wall
##########
# enforce 32-bit build : 1=yes, 0=no
##########
ifeq ($(M32),1)
ALL_LDFLAGS+=-m32
endif
##########
ifeq ($(CONFIG), LIBRARY)
# linker flags for library
# LDFLAGS = $(ALL_LDFLAGS) -shared -Wl,-Bsymbolic
LDFLAGS = $(ALL_LDFLAGS) -shared
#
# debug linker flags for library
DEBUG_LDFLAGS = -Wl,-soname,lib$(PRD_NAME)d.so
#
# release linker flags for library
RELEASE_LDFLAGS = -Wl,-soname,lib$(PRD_NAME).so
#
else
ifeq ($(CONFIG), CONSOLE)
# linker flags for console
LDFLAGS = $(ALL_LDFLAGS)
#
# debug linker flags for console
DEBUG_LDFLAGS =
#
# release linker flags for console
RELEASE_LDFLAGS =
#
endif
endif
#########################################################
# objects that have to be created
#########################################################
# the object types that have to be created
RELEASE_OBJS = $(OBJS:.o=.r.o)
DEBUG_OBJS = $(OBJS:.o=.d.o)
#########################################################
# rules
#########################################################
# suffixes
.SUFFIXES: .asm .cpp .d.o .r.o
## specification of assembler rules
ASMFLAGS = -f elf $(DEFS)
DEBUG_ASMFLAGS = -g
RELEASE_ASMFLAGS =
# creation of ASM debug objects
$(DIR_OBJ)/%.d.o: $(DIR_SRC)/%.asm
$(ASM) $(ASMFLAGS) $(DEBUG_ASMFLAGS) -o $@ $<
# creation of ASM release objects
$(DIR_OBJ)/%.r.o: $(DIR_SRC)/%.asm
$(ASM) $(ASMFLAGS) $(RELEASE_ASMFLAGS) -o $@ $<
## specification of C and C++ rules
define COMPILE_AND_DEPEND_DEBUG
$(CPP) -c -MMD -MF $(DIR_OBJ)/$*.d.d -MT $(DIR_OBJ)/$*.d.o $(CPPFLAGS) $(DEBUG_CPPFLAGS) -o $@ $(CURDIR)/$<
@cp $(DIR_OBJ)/$*.d.d $(DIR_OBJ)/$*.d.p; \
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $(DIR_OBJ)/$*.d.d >> $(DIR_OBJ)/$*.d.p; \
rm -f $(DIR_OBJ)/$*.d.d
endef
define COMPILE_AND_DEPEND_RELEASE
$(CPP) -c -MMD -MF $(DIR_OBJ)/$*.r.d -MT $(DIR_OBJ)/$*.r.o $(CPPFLAGS) $(RELEASE_CPPFLAGS) -o $@ $(CURDIR)/$<
@cp $(DIR_OBJ)/$*.r.d $(DIR_OBJ)/$*.r.p; \
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $(DIR_OBJ)/$*.r.d >> $(DIR_OBJ)/$*.r.p; \
rm -f $(DIR_OBJ)/$*.r.d
endef
# creation of C++ debug objects
$(DIR_OBJ)/%.d.o: $(DIR_SRC)/%.cpp
$(COMPILE_AND_DEPEND_DEBUG)
# creation of C++ release objects
$(DIR_OBJ)/%.r.o: $(DIR_SRC)/%.cpp
$(COMPILE_AND_DEPEND_RELEASE)
# creation of C debug objects
$(DIR_OBJ)/%.d.o: $(DIR_SRC)/%.c
$(COMPILE_AND_DEPEND_DEBUG)
# creation of C release objects
$(DIR_OBJ)/%.r.o: $(DIR_SRC)/%.c
$(COMPILE_AND_DEPEND_RELEASE)
## config dependent directory setup
ifeq ($(CONFIG), CONSOLE)
CHECK_DIRS = $(DIR_OBJ) $(DIR_BIN)
else
ifeq ($(CONFIG), LIBRARY)
CHECK_DIRS = $(DIR_OBJ) $(DIR_LIB)
endif
endif
## specification of build targets
all: check_errors debug release
debug: check_errors \
$(CHECK_DIRS) \
$(STAT_DEBUG_OUT)
# $(DYN_DEBUG_OUT) \
release: check_errors \
$(CHECK_DIRS) \
$(STAT_RELEASE_OUT)
# $(DYN_RELEASE_OUT) \
## check for configuration errors
check_errors:
@if [ "$(CONFIG_ERR)" = "TRUE" ]; then\
echo "ERROR: Wrong CONFIG parameter specified: $(CONFIG)";\
false;\
fi
## creation of output directories
$(DIR_BIN):
@if [ ! -d $(DIR_BIN) ]; then\
mkdir $(DIR_BIN);\
fi
$(DIR_OBJ):
@if [ ! -d $(DIR_OBJ) ]; then\
mkdir $(DIR_OBJ);\
fi
$(DIR_LIB):
@if [ ! -d $(DIR_LIB) ]; then\
mkdir $(DIR_LIB);\
fi
## creation of binary output files
ifeq ($(CONFIG), LIBRARY)
#
# create static debug out
$(STAT_DEBUG_OUT): $(DEBUG_OBJS)
$(AR) -crs $@ $(DEBUG_OBJS)
#
#
# create release debug out
$(STAT_RELEASE_OUT): $(RELEASE_OBJS)
$(AR) -crs $@ $(RELEASE_OBJS)
#
#
# create dynamic debug out
$(DYN_DEBUG_OUT): $(DYN_DEBUG_OUT)
ln -fs lib$(PRD_NAME)d.so $@
#
# create dynamic debug out
$(DYN_DEBUG_OUT): $(DEBUG_OBJS)
$(LD) $(LDFLAGS) $(DEBUG_LDFLAGS) -o $@ $(DEBUG_OBJS) -L$(DIR_LIB) $(LIBS) $(DYN_LIBS) $(DYN_DEBUG_LIBS)
#
#
# create dynamic release out
$(DYN_RELEASE_OUT): $(DYN_RELEASE_OUT)
ln -fs lib$(PRD_NAME).so $@
#
# create dynamic release out
$(DYN_RELEASE_OUT): $(RELEASE_OBJS)
$(LD) $(LDFLAGS) $(RELEASE_LDFLAGS) -o $@ $(RELEASE_OBJS) -L$(DIR_LIB) $(LIBS) $(DYN_LIBS) $(DYN_RELEASE_LIBS)
#
#
#
#
#
else
ifeq ($(CONFIG), CONSOLE)
#
# added linked libraries to target prerequisites - $(*_PREREQS) variables - to force relinking when libraries have been rebuilt
#
# create static debug out
$(STAT_DEBUG_OUT): $(DEBUG_OBJS) $(STAT_DEBUG_PREREQS)
$(LD) -o $@ $(LDFLAGS) $(DEBUG_LDFLAGS) $(DEBUG_OBJS) -L$(DIR_LIB) $(LIBS) $(STAT_LIBS) $(STAT_DEBUG_LIBS)
#
#
# create static release out
$(STAT_RELEASE_OUT): $(RELEASE_OBJS) $(STAT_RELEASE_PREREQS)
$(LD) -o $@ $(LDFLAGS) $(RELEASE_LDFLAGS) $(RELEASE_OBJS) -L$(DIR_LIB) $(LIBS) $(STAT_LIBS) $(STAT_RELEASE_LIBS)
#
#
# create dynamic debug out
$(DYN_DEBUG_OUT): $(DEBUG_OBJS) $(DYN_DEBUG_PREREQS)
$(LD) -o $@ $(LDFLAGS) $(DEBUG_LDFLAGS) $(DEBUG_OBJS) -L$(DIR_LIB) $(LIBS) $(DYN_LIBS) $(DYN_DEBUG_LIBS)
#
#
# create dynamic release out
$(DYN_RELEASE_OUT): $(RELEASE_OBJS) $(DYN_RELEASE_PREREQS)
$(LD) -o $@ $(LDFLAGS) $(RELEASE_LDFLAGS) $(RELEASE_OBJS) -L$(DIR_LIB) $(LIBS) $(DYN_LIBS) $(DYN_RELEASE_LIBS)
#
#
endif
endif
## clean: delete all created files
clean:
/bin/rm -rf $(DYN_DEBUG_OUT)
/bin/rm -rf $(DYN_RELEASE_OUT)
/bin/rm -rf $(STAT_DEBUG_OUT)
/bin/rm -rf $(STAT_RELEASE_OUT)
/bin/rm -rf $(DIR_OBJ)
## include needed dependency files
-include $(OBJS:.o=.d.p)
-include $(OBJS:.o=.r.p)