<commit_before>include gmsl/gmsl

dollars=$$

SHELL := /bin/bash

# arg 1: names
define include_sub_makes
$$(foreach name,$(1),$$(eval $$(call include_sub_make,$$(name))))
endef

# arg 1: name
# arg 2: dir (optional, is the same as $(1) if not given)
# arg 3: makefile (optional, is $(2)/$(1).mk if not given)
define include_sub_make
$(if $(trace3),$$(warning called include_sub_make "$(1)" "$(2)" "$(3)" CWD=$(CWD)))
DIRNAME:=$(if $(2),$(2),$(1))
MAKEFILE:=$(if $(3),$(3),$(1).mk)
$$(call push,DIRS,$$(call peek,DIRS)$$(if $$(call peek,DIRS),/,)$$(DIRNAME))
CWD:=$$(call peek,DIRS)
include $$(if $$(CWD),$$(CWD)/,)/$$(MAKEFILE)
$$(CWD_NAME)_SRC :=	$(SRC)/$$(CWD)
$$(CWD_NAME)_OBJ :=	$(OBJ)/$$(CWD)
#$$(warning stack contains $(__gmsl_stack_DIRS))
CWD:=$$(call pop,DIRS)
endef

# add a c++ source file
# $(1): filename of source file
# $(2): basename of the filename
define add_c++_source
$(if $(trace),$$(warning called add_c++_source "$(1)" "$(2)"))
BUILD_$(CWD)/$(2).lo_COMMAND:=$(CXX) $(CXXFLAGS) -o $(OBJ)/$(CWD)/$(2).lo -c $(SRC)/$(CWD)/$(1) -MP -MMD -MF $(OBJ)/$(CWD)/$(2).d -MQ $(OBJ)/$(CWD)/$(2).lo $$(OPTIONS_$(CWD)/$(1))
$(if $(trace),$$(warning BUILD_$(CWD)/$(2).lo_COMMAND := "$$(BUILD_$(CWD)/$(2).lo_COMMAND)"))
$(OBJ)/$(CWD)/$(2).d:
$(OBJ)/$(CWD)/$(2).lo:	$(SRC)/$(CWD)/$(1) $(OBJ)/$(CWD)/.dir_exists
	$$(if $(verbose_build),@echo $$(BUILD_$(CWD)/$(2).lo_COMMAND),@echo "[C++] $(CWD)/$(1)")
	@$$(BUILD_$(CWD)/$(2).lo_COMMAND) || (echo "FAILED += $$@" >> .target.mk && false)
	@if [ -f $(2).d ] ; then mv $(2).d $(OBJ)/$(CWD)/$(2).d; fi

-include $(OBJ)/$(CWD)/$(2).d
endef

# add a fortran source file
define add_fortran_source
$(if $(trace),$$(warning called add_fortran_source "$(1)" "$(2)"))
BUILD_$(CWD)/$(2).lo_COMMAND:=$(FC) $(FFLAGS) -o $(OBJ)/$(CWD)/$(2).lo -c $(SRC)/$(CWD)/$(1) -MP -MMD
$(if $(trace),$$(warning BUILD_$(CWD)/$(2).lo_COMMAND := "$$(BUILD_$(CWD)/$(2).lo_COMMAND)"))
$(OBJ)/$(CWD)/$(2).d:
$(OBJ)/$(CWD)/$(2).lo:	$(SRC)/$(CWD)/$(1) $(OBJ)/$(CWD)/.dir_exists
	$$(if $(verbose_build),@echo $$(BUILD_$(CWD)/$(2).lo_COMMAND),@echo "[FORTRAN] $(CWD)/$(1)")
	@$$(BUILD_$(CWD)/$(2).lo_COMMAND) || (echo "FAILED += $$@" >> .target.mk && false)


-include $(OBJ)/$(CWD)/$(2).d
endef

define add_cuda_source
$(if $(trace),$$(warning called add_cuda_source "$(1)" "$(2)"))
$(OBJ)/$(CWD)/$(2).d: $(SRC)/$(CWD)/$(1) $(OBJ)/$(CWD)/.dir_exists
	($(NVCC) $(NVCCFLAGS) -M $$< | awk 'NR == 1 { print "$(OBJ)/$(CWD)/$(2).lo", "$$@", ":", $$$$3, "\\"; next; } /usr/ { next; } { print; }'; echo) > $$@~
	mv $$@~ $$@

BUILD_$(CWD)/$(2).lo_COMMAND:=$(NVCC) $(NVCCFLAGS) -c -o $(OBJ)/$(CWD)/$(2).lo --verbose $(SRC)/$(CWD)/$(1)
$(if $(trace),$$(warning BUILD_$(CWD)/$(2).lo_COMMAND := "$$(BUILD_$(CWD)/$(2).lo_COMMAND)"))

$(OBJ)/$(CWD)/$(2).lo:	$(SRC)/$(CWD)/$(1) $(OBJ)/$(CWD)/.dir_exists
	$$(if $(verbose_build),@echo $$(BUILD_$(CWD)/$(2).lo_COMMAND),@echo "[CUDA] $(CWD)/$(1)")
	@$$(BUILD_$(CWD)/$(2).lo_COMMAND) || (echo "FAILED += $$@" >> .target.mk && false)


-include $(OBJ)/$(CWD)/$(2).d
endef

# Set up the map to map an extension to the name of a function to call
$(call set,EXT_FUNCTIONS,.cc,add_c++_source)
$(call set,EXT_FUNCTIONS,.f,add_fortran_source)
$(call set,EXT_FUNCTIONS,.cu,add_cuda_source)

# add a single source file
# $(1): filename
# $(2): suffix of the filename<commit_msg>Fixed dependency generation for CUDA<commit_after>include gmsl/gmsl

dollars=$$

SHELL := /bin/bash

# arg 1: names
define include_sub_makes
$$(foreach name,$(1),$$(eval $$(call include_sub_make,$$(name))))
endef

# arg 1: name
# arg 2: dir (optional, is the same as $(1) if not given)
# arg 3: makefile (optional, is $(2)/$(1).mk if not given)
define include_sub_make
$(if $(trace3),$$(warning called include_sub_make "$(1)" "$(2)" "$(3)" CWD=$(CWD)))
DIRNAME:=$(if $(2),$(2),$(1))
MAKEFILE:=$(if $(3),$(3),$(1).mk)
$$(call push,DIRS,$$(call peek,DIRS)$$(if $$(call peek,DIRS),/,)$$(DIRNAME))
CWD:=$$(call peek,DIRS)
include $$(if $$(CWD),$$(CWD)/,)/$$(MAKEFILE)
$$(CWD_NAME)_SRC :=	$(SRC)/$$(CWD)
$$(CWD_NAME)_OBJ :=	$(OBJ)/$$(CWD)
#$$(warning stack contains $(__gmsl_stack_DIRS))
CWD:=$$(call pop,DIRS)
endef

# add a c++ source file
# $(1): filename of source file
# $(2): basename of the filename
define add_c++_source
$(if $(trace),$$(warning called add_c++_source "$(1)" "$(2)"))
BUILD_$(CWD)/$(2).lo_COMMAND:=$(CXX) $(CXXFLAGS) -o $(OBJ)/$(CWD)/$(2).lo -c $(SRC)/$(CWD)/$(1) -MP -MMD -MF $(OBJ)/$(CWD)/$(2).d -MQ $(OBJ)/$(CWD)/$(2).lo $$(OPTIONS_$(CWD)/$(1))
$(if $(trace),$$(warning BUILD_$(CWD)/$(2).lo_COMMAND := "$$(BUILD_$(CWD)/$(2).lo_COMMAND)"))
$(OBJ)/$(CWD)/$(2).d:
$(OBJ)/$(CWD)/$(2).lo:	$(SRC)/$(CWD)/$(1) $(OBJ)/$(CWD)/.dir_exists
	$$(if $(verbose_build),@echo $$(BUILD_$(CWD)/$(2).lo_COMMAND),@echo "[C++] $(CWD)/$(1)")
	@$$(BUILD_$(CWD)/$(2).lo_COMMAND) || (echo "FAILED += $$@" >> .target.mk && false)
	@if [ -f $(2).d ] ; then mv $(2).d $(OBJ)/$(CWD)/$(2).d; fi

-include $(OBJ)/$(CWD)/$(2).d
endef

# add a fortran source file
define add_fortran_source
$(if $(trace),$$(warning called add_fortran_source "$(1)" "$(2)"))
BUILD_$(CWD)/$(2).lo_COMMAND:=$(FC) $(FFLAGS) -o $(OBJ)/$(CWD)/$(2).lo -c $(SRC)/$(CWD)/$(1) -MP -MMD
$(if $(trace),$$(warning BUILD_$(CWD)/$(2).lo_COMMAND := "$$(BUILD_$(CWD)/$(2).lo_COMMAND)"))
$(OBJ)/$(CWD)/$(2).d:
$(OBJ)/$(CWD)/$(2).lo:	$(SRC)/$(CWD)/$(1) $(OBJ)/$(CWD)/.dir_exists
	$$(if $(verbose_build),@echo $$(BUILD_$(CWD)/$(2).lo_COMMAND),@echo "[FORTRAN] $(CWD)/$(1)")
	@$$(BUILD_$(CWD)/$(2).lo_COMMAND) || (echo "FAILED += $$@" >> .target.mk && false)


-include $(OBJ)/$(CWD)/$(2).d
endef

define add_cuda_source
$(if $(trace),$$(warning called add_cuda_source "$(1)" "$(2)"))
$(OBJ)/$(CWD)/$(2).d: $(SRC)/$(CWD)/$(1) $(OBJ)/$(CWD)/.dir_exists
	($(NVCC) $(NVCCFLAGS) -D__CUDACC__ -M $$< | awk 'NR == 1 { print "$(OBJ)/$(CWD)/$(2).lo", "$$@", ":", $$$$3, "\\"; next; } /usr/ { next; } { print; }'; echo) > $$@~
	mv $$@~ $$@

BUILD_$(CWD)/$(2).lo_COMMAND:=$(NVCC) $(NVCCFLAGS) -c -o $(OBJ)/$(CWD)/$(2).lo --verbose $(SRC)/$(CWD)/$(1)
$(if $(trace),$$(warning BUILD_$(CWD)/$(2).lo_COMMAND := "$$(BUILD_$(CWD)/$(2).lo_COMMAND)"))

$(OBJ)/$(CWD)/$(2).lo:	$(SRC)/$(CWD)/$(1) $(OBJ)/$(CWD)/.dir_exists
	$$(if $(verbose_build),@echo $$(BUILD_$(CWD)/$(2).lo_COMMAND),@echo "[CUDA] $(CWD)/$(1)")
	@$$(BUILD_$(CWD)/$(2).lo_COMMAND) || (echo "FAILED += $$@" >> .target.mk && false)


-include $(OBJ)/$(CWD)/$(2).d
endef

# Set up the map to map an extension to the name of a function to call
$(call set,EXT_FUNCTIONS,.cc,add_c++_source)
$(call set,EXT_FUNCTIONS,.f,add_fortran_source)
$(call set,EXT_FUNCTIONS,.cu,add_cuda_source)

# add a single source file
# $(1): filename
# $(2): suffix of the filename
{'fraction_non_alphanumeric': 0.3294841031793641, 'fraction_numerical': 0.022195560887822437, 'mean_word_length': 5.662337662337662, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5956879', 'n_tokens_mistral': 2974, 'n_tokens_neox': 2870, 'n_words': 540}