Aegisub/Makefile.target
wangqr 460cf9a9fd Drop support for macOS < 10.10
They are less than 2.4% in all macOS and 0.2% in all OS
2020-03-09 19:50:56 -04:00

121 lines
4 KiB
Makefile

ifneq (yes, $(INCLUDING_CHILD_MAKEFILES))
COMMANDS := all install clean distclean test depclean osx-bundle osx-dmg test-automation test-libaegisub
.PHONY: $(COMMANDS)
.DEFAULT_GOAL := all
# Would be nice to move this somewhere else (Makefile.inc?)
ifeq (yes, $(BUILD_DARWIN))
CFLAGS += -mmacosx-version-min=10.10 -gfull -DLUAJIT_ENABLE_GC64
CXXFLAGS += -mmacosx-version-min=10.10 -gfull -DLUAJIT_ENABLE_GC64
LDFLAGS += -mmacosx-version-min=10.10 -Wl,-dead_strip
LIB_SHARED_LINK = $(LIB_SHARED_LINK_OSX)
endif
LIB_TARGETS := $(addprefix $(TOP)lib/,$(LIB:%=lib%.a))
# Handle per-target flags in the form foo_CFLAGS := -w by mapping them to all
# of the objects a target depends on. This has potentially dumb results if
# multiple targets use a single object file, so don't do that.
define set_target_flags
OBJ += $($1_OBJ)
$($1_OBJ): CPPFLAGS := $(CPPFLAGS) $($1_CPPFLAGS)
$($1_OBJ): CXXFLAGS := $(CXXFLAGS) $($1_CXXFLAGS)
$($1_OBJ): OBJCXXFLAGS := $(CXXFLAGS) $($1_CXXFLAGS)
ifeq (yes, $(PRECOMPILED_HEADER))
ifdef $1_PCH
CLEANFILES += $($1_PCH).gch
$($1_OBJ): CXXFLAGS += -include $($1_PCH) $(PCHFLAGS)
$($1_OBJ): $($1_PCH).gch
$($1_PCH).gch: $($1_PCH)
$($1_PCH).gch: CPPFLAGS := $(CPPFLAGS) $($1_CPPFLAGS)
$($1_PCH).gch: CXXFLAGS := $(CXXFLAGS) $($1_CXXFLAGS)
else
$($1_OBJ): CXXFLAGS += -include acconf.h
endif
else
$($1_OBJ): CXXFLAGS += -include acconf.h
endif
endef
$(foreach target,$(LIB),$(eval $(call set_target_flags,$(target),$(TOP)lib/lib$(target).a)))
$(foreach target,$(PROGRAM),$(eval $(call set_target_flags,$(notdir $(target)),$(target))))
# Create the build and install targets for programs
# Not done with a pattern rule since the pattern would be just %: and doing that
# leads to make trying to use gcc to make any nonexistent targets rather than
# erroring
define create_program_targets
ifdef $1_INSTALLNAME
install: $(DESTDIR)$(P_BINDIR)/$($1_INSTALLNAME)
$(DESTDIR)$(P_BINDIR)/$($1_INSTALLNAME): $(dir $2)$($1_INSTALLNAME)
@$(BIN_MKDIR) -p $(DESTDIR)$(P_BINDIR)
@$(BIN_INSTALL) $(dir $2)$($1_INSTALLNAME) $(DESTDIR)$(P_BINDIR)/$($1_INSTALLNAME)
$(dir $2)$($1_INSTALLNAME): $($1_OBJ)
$(BIN_CXX) -o $(dir $2)$($1_INSTALLNAME) $(LDFLAGS) $($1_OBJ) $(LIBS) $($1_LIBS)
all: $(dir $2)$($1_INSTALLNAME)
else
$2: $($1_OBJ)
$(BIN_CXX) -o $2 $(LDFLAGS) $($1_OBJ) $(LIBS) $($1_LIBS)
all: $2
endif
$(eval CLEANFILES += $(filter-out %/,$2 $(dir $2)$($1_INSTALLNAME)))
endef
$(foreach target,$(PROGRAM),$(eval $(call create_program_targets,$(notdir $(target)),$(target))))
# The dependency files which will be automatically generated by gcc.
# The filter is due to that libraries also appear in OBJ
DEP := $(filter %.d,$(OBJ:%.o=%.d))
# If the goal is a relative path to a file, convert it to an absolute path
ifneq ($(filter-out $(COMMANDS),$(MAKECMDGOALS)),)
ABSGOAL := $(abspath $(MAKECMDGOALS))
ifneq ($(MAKECMDGOALS),$(ABSGOAL))
$(MAKECMDGOALS): $(ABSGOAL) ;
endif
endif
# Primary build targets
all: $(LIB_TARGETS)
clean:
$(BIN_RM) -f $(OBJ) $(CLEANFILES) $(LIB_TARGETS)
distclean: clean
$(BIN_RM) -rf $(DISTCLEANFILES) $(DEP)
depclean: clean
$(BIN_RM) -rf $(DEP)
install:
# The actual build rules
.SUFFIXES:
CXX_CMD = $(CXX_ENV) $(BIN_CXX) $(CFLAGS_DEP) $(CPPFLAGS)
CC_CMD = $(CXX_ENV) $(BIN_CC) $(CFLAGS_DEP) $(CPPFLAGS)
POST_FLAGS = $($@_FLAGS) -c -o $@ $<
%.o: %.c ; $(CC_CMD) $(CFLAGS) $(POST_FLAGS)
%.o: %.cpp ; $(CXX_CMD) $(CXXFLAGS) $(POST_FLAGS)
%.o: %.cxx ; $(CXX_CMD) $(CXXFLAGS) $(POST_FLAGS)
%.o: %.cc ; $(CXX_CMD) $(CXXFLAGS) $(POST_FLAGS)
%.o: %.mm ; $(CXX_CMD) $(OBJCXXFLAGS) $(POST_FLAGS)
%.o: %.m ; $(CC_CMD) $(CFLAGS) -fmodules $(POST_FLAGS)
%.gch: %
@$(BIN_RM) -f $@
$(CXX_ENV) $(BIN_CXX) $(CPPFLAGS) $(CXXFLAGS) -x c++-header $<
.SECONDEXPANSION:
# Libraries contain all object files they depend on (but they may depend on other files)
# Not using libtool on OS X because it has an unsilenceable warning about a
# compatibility issue with BSD 4.3 (wtf)
lib%.a: $$($$(*F)_OBJ)
@$(BIN_MKDIR_P) $(dir $@)
$(BIN_AR) cru $@ $(filter %.o,$^)
$(BIN_RANLIB) $@
-include $(DEP)
endif