1# 2# common bits used by all libraries 3# 4 5DEFAULT_X86ASMD=.dbg 6 7ifeq ($(DBG),1) 8X86ASMD=$(DEFAULT_X86ASMD) 9else 10X86ASMD= 11endif 12 13ifndef SUBDIR 14 15BIN2CEXE = ffbuild/bin2c$(HOSTEXESUF) 16BIN2C = $(BIN2CEXE) 17 18ifndef V 19Q = @ 20ECHO = printf "$(1)\t%s\n" $(2) 21BRIEF = CC CXX OBJCC HOSTCC HOSTLD AS X86ASM AR LD STRIP CP WINDRES NVCC BIN2C 22SILENT = DEPCC DEPHOSTCC DEPAS DEPX86ASM RANLIB RM 23 24MSG = $@ 25M = @$(call ECHO,$(TAG),$@); 26$(foreach VAR,$(BRIEF), \ 27 $(eval override $(VAR) = @$$(call ECHO,$(VAR),$$(MSG)); $($(VAR)))) 28$(foreach VAR,$(SILENT),$(eval override $(VAR) = @$($(VAR)))) 29$(eval INSTALL = @$(call ECHO,INSTALL,$$(^:$(SRC_DIR)/%=%)); $(INSTALL)) 30endif 31 32# Prepend to a recursively expanded variable without making it simply expanded. 33PREPEND = $(eval $(1) = $(patsubst %,$$(%), $(2)) $(value $(1))) 34 35# NASM requires -I path terminated with / 36IFLAGS := -I. -I$(SRC_LINK)/ 37CPPFLAGS := $(IFLAGS) $(CPPFLAGS) 38CFLAGS += $(ECFLAGS) 39CCFLAGS = $(CPPFLAGS) $(CFLAGS) 40OBJCFLAGS += $(EOBJCFLAGS) 41OBJCCFLAGS = $(CPPFLAGS) $(CFLAGS) $(OBJCFLAGS) 42ASFLAGS := $(CPPFLAGS) $(ASFLAGS) 43# Use PREPEND here so that later (target-dependent) additions to CPPFLAGS 44# end up in CXXFLAGS. 45$(call PREPEND,CXXFLAGS, CPPFLAGS CFLAGS) 46X86ASMFLAGS += $(IFLAGS:%=%/) -I$(<D)/ -Pconfig.asm 47 48HOSTCCFLAGS = $(IFLAGS) $(HOSTCPPFLAGS) $(HOSTCFLAGS) 49LDFLAGS := $(ALLFFLIBS:%=$(LD_PATH)lib%) $(LDFLAGS) 50 51define COMPILE 52 $(call $(1)DEP,$(1)) 53 $($(1)) $($(1)FLAGS) $($(2)) $($(1)_DEPFLAGS) $($(1)_C) $($(1)_O) $(patsubst $(SRC_PATH)/%,$(SRC_LINK)/%,$<) 54endef 55 56COMPILE_C = $(call COMPILE,CC) 57COMPILE_CXX = $(call COMPILE,CXX) 58COMPILE_S = $(call COMPILE,AS) 59COMPILE_M = $(call COMPILE,OBJCC) 60COMPILE_X86ASM = $(call COMPILE,X86ASM) 61COMPILE_HOSTC = $(call COMPILE,HOSTCC) 62COMPILE_NVCC = $(call COMPILE,NVCC) 63COMPILE_MMI = $(call COMPILE,CC,MMIFLAGS) 64COMPILE_MSA = $(call COMPILE,CC,MSAFLAGS) 65COMPILE_LSX = $(call COMPILE,CC,LSXFLAGS) 66COMPILE_LASX = $(call COMPILE,CC,LASXFLAGS) 67 68%_mmi.o: %_mmi.c 69 $(COMPILE_MMI) 70 71%_msa.o: %_msa.c 72 $(COMPILE_MSA) 73 74%_lsx.o: %_lsx.c 75 $(COMPILE_LSX) 76 77%_lasx.o: %_lasx.c 78 $(COMPILE_LASX) 79 80%.o: %.c 81 $(COMPILE_C) 82 83%.o: %.cpp 84 $(COMPILE_CXX) 85 86%.o: %.m 87 $(COMPILE_M) 88 89%.s: %.c 90 $(CC) $(CCFLAGS) -S -o $@ $< 91 92%.o: %.S 93 $(COMPILE_S) 94 95%_host.o: %.c 96 $(COMPILE_HOSTC) 97 98%$(DEFAULT_X86ASMD).asm: %.asm 99 $(DEPX86ASM) $(X86ASMFLAGS) -M -o $@ $< > $(@:.asm=.d) 100 $(X86ASM) $(X86ASMFLAGS) -e $< | sed '/^%/d;/^$$/d;' > $@ 101 102%.o: %.asm 103 $(COMPILE_X86ASM) 104 -$(if $(ASMSTRIPFLAGS), $(STRIP) $(ASMSTRIPFLAGS) $@) 105 106%.o: %.rc 107 $(WINDRES) $(IFLAGS) $(foreach ARG,$(CC_DEPFLAGS),--preprocessor-arg "$(ARG)") -o $@ $< 108 109%.i: %.c 110 $(CC) $(CCFLAGS) $(CC_E) $< 111 112%.h.c: 113 $(Q)echo '#include "$*.h"' >$@ 114 115$(BIN2CEXE): ffbuild/bin2c_host.o 116 $(HOSTLD) $(HOSTLDFLAGS) $(HOSTLD_O) $^ $(HOSTEXTRALIBS) 117 118%.metal.air: %.metal 119 $(METALCC) $< -o $@ 120 121%.metallib: %.metal.air 122 $(METALLIB) --split-module-without-linking $< -o $@ 123 124%.metallib.c: %.metallib $(BIN2CEXE) 125 $(BIN2C) $< $@ $(subst .,_,$(basename $(notdir $@))) 126 127%.ptx: %.cu $(SRC_PATH)/compat/cuda/cuda_runtime.h 128 $(COMPILE_NVCC) 129 130ifdef CONFIG_PTX_COMPRESSION 131%.ptx.gz: TAG = GZIP 132%.ptx.gz: %.ptx 133 $(M)gzip -c9 $(patsubst $(SRC_PATH)/%,$(SRC_LINK)/%,$<) >$@ 134 135%.ptx.c: %.ptx.gz $(BIN2CEXE) 136 $(BIN2C) $(patsubst $(SRC_PATH)/%,$(SRC_LINK)/%,$<) $@ $(subst .,_,$(basename $(notdir $@))) 137else 138%.ptx.c: %.ptx $(BIN2CEXE) 139 $(BIN2C) $(patsubst $(SRC_PATH)/%,$(SRC_LINK)/%,$<) $@ $(subst .,_,$(basename $(notdir $@))) 140endif 141 142clean:: 143 $(RM) $(BIN2CEXE) 144 145%.c %.h %.pc %.ver %.version: TAG = GEN 146 147# Dummy rule to stop make trying to rebuild removed or renamed headers 148%.h %_template.c: 149 @: 150 151# Disable suffix rules. Most of the builtin rules are suffix rules, 152# so this saves some time on slow systems. 153.SUFFIXES: 154 155# Do not delete intermediate files from chains of implicit rules 156$(OBJS): 157endif 158 159include $(SRC_PATH)/ffbuild/arch.mak 160 161OBJS += $(OBJS-yes) 162SLIBOBJS += $(SLIBOBJS-yes) 163SHLIBOBJS += $(SHLIBOBJS-yes) 164STLIBOBJS += $(STLIBOBJS-yes) 165FFLIBS := $($(NAME)_FFLIBS) $(FFLIBS-yes) $(FFLIBS) 166TESTPROGS += $(TESTPROGS-yes) 167 168LDLIBS = $(FFLIBS:%=%$(BUILDSUF)) 169FFEXTRALIBS := $(LDLIBS:%=$(LD_LIB)) $(foreach lib,EXTRALIBS-$(NAME) $(FFLIBS:%=EXTRALIBS-%),$($(lib))) $(EXTRALIBS) 170 171OBJS := $(sort $(OBJS:%=$(SUBDIR)%)) 172SLIBOBJS := $(sort $(SLIBOBJS:%=$(SUBDIR)%)) 173SHLIBOBJS := $(sort $(SHLIBOBJS:%=$(SUBDIR)%)) 174STLIBOBJS := $(sort $(STLIBOBJS:%=$(SUBDIR)%)) 175TESTOBJS := $(TESTOBJS:%=$(SUBDIR)tests/%) $(TESTPROGS:%=$(SUBDIR)tests/%.o) 176TESTPROGS := $(TESTPROGS:%=$(SUBDIR)tests/%$(EXESUF)) 177HOSTOBJS := $(HOSTPROGS:%=$(SUBDIR)%.o) 178HOSTPROGS := $(HOSTPROGS:%=$(SUBDIR)%$(HOSTEXESUF)) 179TOOLS += $(TOOLS-yes) 180TOOLOBJS := $(TOOLS:%=tools/%.o) 181TOOLS := $(TOOLS:%=tools/%$(EXESUF)) 182HEADERS += $(HEADERS-yes) 183 184PATH_LIBNAME = $(foreach NAME,$(1),lib$(NAME)/$($(2)LIBNAME)) 185DEP_LIBS := $(foreach lib,$(FFLIBS),$(call PATH_LIBNAME,$(lib),$(CONFIG_SHARED:yes=S))) 186STATIC_DEP_LIBS := $(foreach lib,$(FFLIBS),$(call PATH_LIBNAME,$(lib))) 187 188SRC_DIR := $(SRC_PATH)/lib$(NAME) 189ALLHEADERS := $(subst $(SRC_DIR)/,$(SUBDIR),$(wildcard $(SRC_DIR)/*.h $(SRC_DIR)/$(ARCH)/*.h)) 190SKIPHEADERS += $(ARCH_HEADERS:%=$(ARCH)/%) $(SKIPHEADERS-) 191SKIPHEADERS := $(SKIPHEADERS:%=$(SUBDIR)%) 192HOBJS = $(filter-out $(SKIPHEADERS:.h=.h.o),$(ALLHEADERS:.h=.h.o)) 193PTXOBJS = $(filter %.ptx.o,$(OBJS)) 194$(HOBJS): CCFLAGS += $(CFLAGS_HEADERS) 195checkheaders: $(HOBJS) 196.SECONDARY: $(HOBJS:.o=.c) $(PTXOBJS:.o=.c) $(PTXOBJS:.o=.gz) $(PTXOBJS:.o=) 197 198alltools: $(TOOLS) 199 200$(HOSTOBJS): %.o: %.c 201 $(COMPILE_HOSTC) 202 203$(HOSTPROGS): %$(HOSTEXESUF): %.o 204 $(HOSTLD) $(HOSTLDFLAGS) $(HOSTLD_O) $^ $(HOSTEXTRALIBS) 205 206$(OBJS): | $(sort $(dir $(OBJS))) 207$(HOBJS): | $(sort $(dir $(HOBJS))) 208$(HOSTOBJS): | $(sort $(dir $(HOSTOBJS))) 209$(SLIBOBJS): | $(sort $(dir $(SLIBOBJS))) 210$(SHLIBOBJS): | $(sort $(dir $(SHLIBOBJS))) 211$(STLIBOBJS): | $(sort $(dir $(STLIBOBJS))) 212$(TESTOBJS): | $(sort $(dir $(TESTOBJS))) 213$(TOOLOBJS): | tools 214 215OUTDIRS := $(OUTDIRS) $(dir $(OBJS) $(HOBJS) $(HOSTOBJS) $(SLIBOBJS) $(SHLIBOBJS) $(STLIBOBJS) $(TESTOBJS)) 216 217CLEANSUFFIXES = *.d *.gcda *.gcno *.h.c *.ho *.map *.o *.pc *.ptx *.ptx.gz *.ptx.c *.ver *.version *$(DEFAULT_X86ASMD).asm *~ *.ilk *.pdb 218LIBSUFFIXES = *.a *.lib *.so *.so.* *.dylib *.dll *.def *.dll.a 219 220define RULES 221clean:: 222 $(RM) $(HOSTPROGS) $(TESTPROGS) $(TOOLS) 223endef 224 225$(eval $(RULES)) 226 227-include $(wildcard $(OBJS:.o=.d) $(HOSTOBJS:.o=.d) $(TESTOBJS:.o=.d) $(HOBJS:.o=.d) $(SHLIBOBJS:.o=.d) $(STLIBOBJS:.o=.d) $(SLIBOBJS:.o=.d)) $(OBJS:.o=$(DEFAULT_X86ASMD).d) 228