Skip to content

Instantly share code, notes, and snippets.

@soudai
Last active December 22, 2020 06:56
Show Gist options
  • Save soudai/33dd61b26d8cd57135d785f97f0c4912 to your computer and use it in GitHub Desktop.
Save soudai/33dd61b26d8cd57135d785f97f0c4912 to your computer and use it in GitHub Desktop.
makeで簡単に並列

ファイルの中身を並列実行

FILE := list.txt
LIST := $(shell cat $(FILE))
TARGETS := $(addsuffix .run,$(LIST))
all: $(TARGETS)
%.run:
    sh hoge.sh $*
#!/bin/sh
sleep 3
echo $@
aa
bb
cc

ajiyoshiさん

$ /usr/bin/time make -j 5
sh hoge.sh aa
sh hoge.sh bb
sh hoge.sh cc
aa
bb
cc
        3.04 real         0.01 user         0.02 sys

さいないぷさん

FILE := list.txt
LIST := $(shell cat $(FILE))
TARGETS := $(addsuffix .run,$(LIST))
all: $(TARGETS)
%.run:
    sh hoge.sh $* 2>&1 > $@.tmp
    mv $@.tmp $@

フォルダの中身を引数で並列実行

しょーた

まずは1件づつ

FILE_PATH := test_dir
LIST := $(shell ls -R $(FILE_PATH))

.PHONY: echo
echo : 
	@echo $(LIST)

all: $(TARGETS)
	$(shell ls -1R $(FILE_PATH) | xargs -I {} sh test.sh {})

完成した

FILE_PATH := target_dir
LIST := $(shell ls -FR $(FILE_PATH) | grep -v "/" | grep -v "FILE_PATH:" )
TARGETS := $(addsuffix .run,$(LIST))

echo : 
	@echo $(TARGETS)

all: $(TARGETS)

%.run:
	sh hoge.sh $*

FILEのフルパスがほしいとき

BASE_PATH := target_dir
LIST := $(shell find $(BASE_PATH) -type f)
TARGETS := $(addsuffix .run,$(LIST))

echo : 
	@echo $(LIST)

all: $(TARGETS)

%.run:
	sh zcat $*  | hoge.sh 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment