2014-06-17 03:22:06 +02:00
|
|
|
ifneq (yes, $(INCLUDING_CHILD_MAKEFILES))
|
2014-07-09 16:22:49 +02:00
|
|
|
COMMANDS := all install clean distclean test depclean osx-bundle osx-dmg test-automation test-libaegisub
|
2014-06-17 03:22:06 +02:00
|
|
|
.PHONY: $(COMMANDS)
|
2011-12-22 22:20:34 +01:00
|
|
|
.DEFAULT_GOAL := all
|
2010-12-05 20:12:42 +01:00
|
|
|
|
2014-06-17 03:22:06 +02:00
|
|
|
# Would be nice to move this somewhere else (Makefile.inc?)
|
2010-12-05 20:12:42 +01:00
|
|
|
ifeq (yes, $(BUILD_DARWIN))
|
2017-07-04 21:31:55 +02:00
|
|
|
CFLAGS += -mmacosx-version-min=10.8 -gfull
|
|
|
|
CXXFLAGS += -mmacosx-version-min=10.8 -gfull
|
2020-02-10 21:27:07 +01:00
|
|
|
LDFLAGS += -mmacosx-version-min=10.8 -Wl,-dead_strip
|
2010-12-05 20:12:42 +01:00
|
|
|
LIB_SHARED_LINK = $(LIB_SHARED_LINK_OSX)
|
|
|
|
endif
|
|
|
|
|
2014-06-17 03:22:06 +02:00
|
|
|
LIB_TARGETS := $(addprefix $(TOP)lib/,$(LIB:%=lib%.a))
|
2010-12-05 20:12:42 +01:00
|
|
|
|
2014-06-17 03:22:06 +02:00
|
|
|
# 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)
|
2010-12-05 20:12:42 +01:00
|
|
|
|
2014-06-17 03:22:06 +02:00
|
|
|
$($1_OBJ): CPPFLAGS := $(CPPFLAGS) $($1_CPPFLAGS)
|
|
|
|
$($1_OBJ): CXXFLAGS := $(CXXFLAGS) $($1_CXXFLAGS)
|
|
|
|
$($1_OBJ): OBJCXXFLAGS := $(CXXFLAGS) $($1_CXXFLAGS)
|
2010-12-05 20:12:42 +01:00
|
|
|
|
2014-04-16 04:33:37 +02:00
|
|
|
ifeq (yes, $(PRECOMPILED_HEADER))
|
2014-06-17 03:22:06 +02:00
|
|
|
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)
|
2014-04-16 04:33:37 +02:00
|
|
|
else
|
2014-06-17 03:22:06 +02:00
|
|
|
$2: $($1_OBJ)
|
|
|
|
$(BIN_CXX) -o $2 $(LDFLAGS) $($1_OBJ) $(LIBS) $($1_LIBS)
|
|
|
|
all: $2
|
2010-12-05 20:12:42 +01:00
|
|
|
endif
|
2014-06-17 03:22:06 +02:00
|
|
|
$(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) ;
|
2010-12-05 20:12:42 +01:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2014-06-17 03:22:06 +02:00
|
|
|
# Primary build targets
|
|
|
|
all: $(LIB_TARGETS)
|
2010-12-05 20:12:42 +01:00
|
|
|
|
2014-06-17 03:22:06 +02:00
|
|
|
clean:
|
|
|
|
$(BIN_RM) -f $(OBJ) $(CLEANFILES) $(LIB_TARGETS)
|
|
|
|
|
|
|
|
distclean: clean
|
|
|
|
$(BIN_RM) -rf $(DISTCLEANFILES) $(DEP)
|
2010-12-05 20:12:42 +01:00
|
|
|
|
2014-06-17 03:22:06 +02:00
|
|
|
depclean: clean
|
|
|
|
$(BIN_RM) -rf $(DEP)
|
2010-12-05 20:12:42 +01:00
|
|
|
|
2014-06-17 03:22:06 +02:00
|
|
|
install:
|
2010-12-05 20:12:42 +01:00
|
|
|
|
2014-06-17 03:22:06 +02:00
|
|
|
# The actual build rules
|
|
|
|
.SUFFIXES:
|
2010-12-05 20:12:42 +01:00
|
|
|
|
2014-06-17 03:22:06 +02:00
|
|
|
CXX_CMD = $(CXX_ENV) $(BIN_CXX) $(CFLAGS_DEP) $(CPPFLAGS)
|
|
|
|
CC_CMD = $(CXX_ENV) $(BIN_CC) $(CFLAGS_DEP) $(CPPFLAGS)
|
|
|
|
POST_FLAGS = $($@_FLAGS) -c -o $@ $<
|
2012-11-07 16:36:31 +01:00
|
|
|
|
2014-06-17 03:22:06 +02:00
|
|
|
%.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)
|
2012-05-26 22:16:02 +02:00
|
|
|
|
2014-06-17 03:22:06 +02:00
|
|
|
%.gch: %
|
|
|
|
@$(BIN_RM) -f $@
|
2012-02-20 19:22:25 +01:00
|
|
|
$(CXX_ENV) $(BIN_CXX) $(CPPFLAGS) $(CXXFLAGS) -x c++-header $<
|
2010-12-05 20:12:42 +01:00
|
|
|
|
2014-06-17 03:22:06 +02:00
|
|
|
.SECONDEXPANSION:
|
2010-12-05 20:12:42 +01:00
|
|
|
|
2014-06-17 03:22:06 +02:00
|
|
|
# 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)
|
2020-02-17 07:42:07 +01:00
|
|
|
lib%.a: $$($$(*F)_OBJ)
|
2014-06-17 03:22:06 +02:00
|
|
|
@$(BIN_MKDIR_P) $(dir $@)
|
|
|
|
$(BIN_AR) cru $@ $(filter %.o,$^)
|
|
|
|
$(BIN_RANLIB) $@
|
|
|
|
|
|
|
|
-include $(DEP)
|
|
|
|
endif
|