MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST))) SERENITY_BASE_DIR := $(patsubst %/,%,$(dir $(MAKEFILE_PATH))) CXX_STANDARD_FLAGS = -std=c++2a CXX_WARNING_FLAGS = -Werror -Wextra -Wall -Wno-nonnull-compare -Wno-deprecated-copy -Wno-address-of-packed-member -Wundef -Wcast-qual -Wwrite-strings -Wimplicit-fallthrough -Wno-expansion-to-defined CXX_FLAVOR_FLAGS = -fno-exceptions -fno-rtti -fstack-protector #CXX_SUGGEST_FLAGS = -Wsuggest-final-types -Wsuggest-final-methods -Wsuggest-override #-Wsuggest-attribute=noreturn C_STANDARD_FLAGS = C_WARNING_FLAGS = -Werror -Wextra -Wall -Wno-nonnull-compare -Wno-address-of-packed-member -Wundef -Wcast-qual -Wwrite-strings -Wimplicit-fallthrough -Wno-expansion-to-defined C_FLAVOR_FLAGS = -fstack-protector ARCH_FLAGS = OPTIMIZATION_FLAGS = -Os INCLUDE_FLAGS += \ -I. \ -I$(SERENITY_BASE_DIR)/DevTools \ -I$(SERENITY_BASE_DIR) \ -I$(SERENITY_BASE_DIR)/Libraries \ -I$(SERENITY_BASE_DIR)/Servers VERBOSE = 0 ifneq ($(USE_HOST_CXX),) UNAME_S := $(shell uname -s) ifeq ($(UNAME_S),OpenBSD) HOST_CXX ?= clang++ endif ifeq '' '$(findstring clang++,$(CXX))' C_WARNING_FLAGS += -Wno-unknown-warning-option CXX_WARNING_FLAGS += -Wno-unknown-warning-option endif ifeq ($(HOST_CXX),) CXX = $(PRE_CXX) g++ else CXX = $(HOST_CXX) endif AS = as LINK = ld OBJ_SUFFIX ?= .host ARCH = $(shell arch -s) else TOOLCHAIN_PATH = $(SERENITY_BASE_DIR)/Toolchain/Local/bin CXX = $(PRE_CXX) $(TOOLCHAIN_PATH)/i686-pc-serenity-g++ CC = $(PRE_CC) $(TOOLCHAIN_PATH)/i686-pc-serenity-gcc AS = $(TOOLCHAIN_PATH)/i686-pc-serenity-as LINK = $(TOOLCHAIN_PATH)/i686-pc-serenity-ld RANLIB = $(TOOLCHAIN_PATH)/i686-pc-serenity-ranlib AR = $(TOOLCHAIN_PATH)/i686-pc-serenity-ar ARCH = i386 DEFINES += -DDEBUG INCLUDE_FLAGS += \ -I$(SERENITY_BASE_DIR)/Libraries/LibC \ -I$(SERENITY_BASE_DIR)/Libraries/LibM \ -I$(SERENITY_BASE_DIR)/Libraries/LibPthread ifdef KERNEL DEFINES += -DKERNEL else ifdef BOOTSTRAPPER DEFINES += -DBOOTSTRAPPER else # everything else gets -lc -lm LIB_DEPS := C M $(LIB_DEPS) endif # turn "LIB_DEPS=C Core Thread" into "-lc -lcore -lthread -L.../LibC ..." LDFLAGS += $(foreach lib,$(LIB_DEPS),\ -l$(shell echo $(lib) | tr A-Z a-z)) LDFLAGS += $(foreach lib,$(LIB_DEPS),\ -L$(SERENITY_BASE_DIR)/Libraries/Lib$(lib)) STATIC_LIB_DEPS = $(foreach lib,$(LIB_DEPS),\ $(SERENITY_BASE_DIR)/Libraries/Lib$(lib)/lib$(shell echo $(lib) | tr A-Z a-z).a) OBJ_SUFFIX ?= endif #CXX = clang $(CLANG_FLAGS) #CLANG_FLAGS = -Wconsumed -m32 -ffreestanding -march=i686 CXXFLAGS = -MMD -MP $(CXX_WARNING_FLAGS) $(OPTIMIZATION_FLAGS) $(CXX_FLAVOR_FLAGS) $(ARCH_FLAGS) $(CXX_STANDARD_FLAGS) $(CXX_SUGGEST_FLAGS) $(INCLUDE_FLAGS) $(DEFINES) $(SUBPROJECT_CXXFLAGS) CFLAGS = -MMD -MP $(C_FLAVOR_FLAGS) $(ARCH_FLAGS) $(C_STANDARD_FLAGS) $(C_SUGGEST_FLAGS) $(INCLUDE_FLAGS) $(DEFINES) $(SUBPROJECT_CXXFLAGS) DEFINES += -DSANITIZE_PTRS SUFFIXED_OBJS = $(patsubst %.o,%$(OBJ_SUFFIX).o,$(OBJS)) ifeq ($(VERBOSE),1) QUIET = else QUIET = @ endif -include $(SUFFIXED_OBJS:%.o=%.d) .SUFFIXES: %$(OBJ_SUFFIX).o: %.cpp $(EXTRA_SOURCES) @echo "$(notdir $(CURDIR)): C++ $@" $(QUIET) $(CXX) $(CXXFLAGS) -o $@ -c $< %$(OBJ_SUFFIX).o: %.c @echo "$(notdir $(CURDIR)): C $@" $(QUIET) $(CC) $(CFLAGS) -o $@ -c $< %.ao: %.S @echo "$(notdir $(CURDIR)): AS $@" $(QUIET) $(AS) -o $@ $< $(PROGRAM): $(STATIC_LIB_DEPS) $(SUFFIXED_OBJS) $(EXTRA_OBJS) @echo "$(notdir $(CURDIR)): LINK $(PROGRAM)" $(QUIET) $(CXX) -o $(PROGRAM) $(EXTRA_OBJS) $(SUFFIXED_OBJS) $(LDFLAGS) $(LIBRARY): $(SUFFIXED_OBJS) $(EXTRA_OBJS) @echo "$(notdir $(CURDIR)): LIB $@" $(QUIET) $(AR) rcs $@ $(OBJS) $(EXTRA_OBJS) $(LIBS) $(POST_LIBRARY_BUILD) #.PHONY: $(STATIC_LIB_DEPS) $(STATIC_LIB_DEPS): @flock $(dir $(@)) $(MAKE) -C $(dir $(@)) IPCCOMPILER = $(SERENITY_BASE_DIR)/DevTools/IPCCompiler/IPCCompiler IPCCOMPILER: $(IPCCOMPILER) $(IPCCOMPILER): @flock $(dir $(@)) $(MAKE) -C $(dir $(@)) FORMCOMPILER = $(SERENITY_BASE_DIR)/DevTools/FormCompiler/FormCompiler FORMCOMPILER: $(FORMCOMPILER) $(FORMCOMPILER): @flock $(dir $(@)) $(MAKE) -C $(dir $(@)) .DEFAULT_GOAL := all all: $(PROGRAM) $(LIBRARY) EXTRA_CLEAN ?= clean: @echo "$(notdir $(CURDIR)): CLEAN" $(QUIET) rm -f $(PROGRAM) $(LIBRARY) $(SUFFIXED_OBJS) $(EXTRA_OBJS) $(patsubst %.o,%.d,$(SUFFIXED_OBJS) $(EXTRA_OBJS)) $(EXTRA_CLEAN) install: .DELETE_ON_ERROR: .PHONY: all clean install