Skip to content

Commit 3908cc8

Browse files
committed
refactoring
1 parent 8634559 commit 3908cc8

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/prorab.mk

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ ifneq ($(prorab_is_included),true)
9494
# function to find all header files from specified directory recursively
9595
prorab-hdr-dir = $(call prorab-rwildcard,$1,*$(this_dot_hxx) *.h)
9696

97+
# function to print colored action info, args: action text, filename, bash color.
98+
# to be used only from the recipe
99+
prorab-private-print = @test -t 1 && printf "\e[$3m$1\e[0m$2\n" || printf "$1$2\n"
100+
97101
# function which clears all 'this_'-prefixed variables and sets default values
98102
define prorab-clear-this-vars
99103
# clear all vars
@@ -463,10 +467,10 @@ $(.RECIPEPREFIX)$(a)rm -rf $(d)out
463467
define prorab-private-rules
464468

465469
echo-clean:
466-
$(.RECIPEPREFIX)@test -t 1 && printf "\e[0;32mclean\e[0m\n" || printf "clean\n"
470+
$(.RECIPEPREFIX)$(call prorab-private-print,clean,,0;32)
467471

468472
echo-clean-all:
469-
$(.RECIPEPREFIX)@test -t 1 && printf "\e[0;32mclean all configurations\e[0m\n" || printf "clean all configurations\n"
473+
$(.RECIPEPREFIX)$(call prorab-private-print,clean all configurations,,0;32)
470474

471475
clean:: echo-clean
472476

@@ -485,7 +489,7 @@ $(.RECIPEPREFIX)+$(a)$(MAKE)
485489
prorab_private_out_dir = $(if $(this_out_dir),$(if $(patsubst %/,,$(this_out_dir)),$(this_out_dir)/,$(this_out_dir)))
486490

487491
define prorab-private-generate-test-source-file-recepie
488-
$(.RECIPEPREFIX)@test -t 1 && printf "\e[1;90mgenerate\e[0m $$(patsubst $(prorab_root_dir)%,%,$$@)\n" || printf "generate $$(patsubst $(prorab_root_dir)%,%,$$@)\n"
492+
$(.RECIPEPREFIX)$(call prorab-private-print,generate, $$(patsubst $(prorab_root_dir)%,%,$$@),1;90)
489493
$(.RECIPEPREFIX)$(a)mkdir -p $$(dir $$@)
490494
$(.RECIPEPREFIX)$(a)echo '#include "$$(call prorab-private-make-include-path,$$<)"' > $$@
491495
$(.RECIPEPREFIX)$(a)echo '#include "$$(call prorab-private-make-include-path,$$<)"' >> $$@
@@ -545,15 +549,15 @@ $(prorab-private-generate-test-source-file-recepie)
545549

546550
# compile .hpp.test_cpp static pattern rule
547551
$(prorab_this_hxx_test_objs): $(d)%.o: $(d)%
548-
$(.RECIPEPREFIX)@test -t 1 && printf "\e[1;34mcompile\e[0m $$(patsubst $(prorab_root_dir)%,%,$$<)\n" || printf "compile $$(patsubst $(prorab_root_dir)%,%,$$<)\n"
552+
$(.RECIPEPREFIX)$(call prorab-private-print,compile, $$(patsubst $(prorab_root_dir)%,%,$$<),1;34)
549553
$(.RECIPEPREFIX)$(a)mkdir -p $$(dir $$@)
550554
# NOTE: using short -x option instead of --language because some compilers (e.g. emcc) only support -x
551555
$(.RECIPEPREFIX)$(a)(cd $(d) && $(this_cxx) -x c++ -c -MF "$$(patsubst %.o,%.d,$$@)" -MD -MP $(this_cxxflags_test) -o "$$@" $$<)
552556
$(.RECIPEPREFIX)$(a)$(prorab_private_d_file_sed_command)
553557

554558
# compile .h.test_c static pattern rule
555559
$(prorab_this_h_test_objs): $(d)%.o: $(d)%
556-
$(.RECIPEPREFIX)@test -t 1 && printf "\e[0;35mcompile\e[0m $$(patsubst $(prorab_root_dir)%,%,$$<)\n" || printf "compile $$(patsubst $(prorab_root_dir)%,%,$$<)\n"
560+
$(.RECIPEPREFIX)$(call prorab-private-print,compile, $$(patsubst $(prorab_root_dir)%,%,$$<),0;35)
557561
$(.RECIPEPREFIX)$(a)mkdir -p $$(dir $$@)
558562
# NOTE: using short -x option instead of --language because some compilers (e.g. emcc) only support -x
559563
$(.RECIPEPREFIX)$(a)(cd $(d) && $(this_cc) -x c -c -MF "$$(patsubst %.o,%.d,$$@)" -MD -MP $(this_cflags_test) -o "$$@" $$<)
@@ -704,7 +708,7 @@ $(.RECIPEPREFIX)$(a)rm -f $(prorab_prefix)lib/$(notdir $(prorab_this_static_lib)
704708
# static library rule
705709
# NOTE: need to remove the lib before creating, otherwise files will just be appended to the existing .a archive.
706710
$(prorab_this_static_lib): $(prorab_this_objs) $(prorab_objs_file)
707-
$(.RECIPEPREFIX)@test -t 1 && printf "\e[0;33mcreate static library\e[0m $$(notdir $$@)\n" || printf "create static library $$(notdir $$@)\n"
711+
$(.RECIPEPREFIX)$(call prorab-private-print,create static library, $$(notdir $$@),0;33)
708712
$(.RECIPEPREFIX)$(a)rm -f $$@
709713
$(.RECIPEPREFIX)$(a)$(this_ar) cr $$@ $$(filter %.o,$$^)
710714
endef
@@ -801,7 +805,7 @@ $(prorab-private-generate-test-source-file-recepie)
801805

802806
# compile .cpp static pattern rule
803807
$(prorab_this_cxx_objs): $(prorab_this_obj_dir)$(prorab_this_obj_spacer)%.o: $(d)% $(prorab_cxxflags_file)
804-
$(.RECIPEPREFIX)@test -t 1 && printf "\e[1;34mcompile\e[0m $$(patsubst $(prorab_root_dir)%,%,$$<)\n" || printf "compile $$(patsubst $(prorab_root_dir)%,%,$$<)\n"
808+
$(.RECIPEPREFIX)$(call prorab-private-print,compile, $$(patsubst $(prorab_root_dir)%,%,$$<),1;34)
805809
$(.RECIPEPREFIX)$(a)mkdir -p $$(dir $$@)
806810
# NOTE: using short -x option instead of --language because some compilers (e.g. emcc) only support -x
807811
$(.RECIPEPREFIX)$(a)(cd $(d) && $(this_cxx) -x c++ -c -MF "$$(patsubst %.o,%.d,$$@)" -MD -MP -o "$$@" $(prorab_cxxflags) $$<)
@@ -810,15 +814,15 @@ $(if $(this_lint_cmd),$(if $(filter $(lint),off),,$(.RECIPEPREFIX)$(a)(cd $(d) &
810814

811815
# compile .hpp.hdr_cpp static pattern rule
812816
$(prorab_this_hxx_objs): $(d)%.o: $(d)% $(prorab_cxxflags_file)
813-
$(.RECIPEPREFIX)@test -t 1 && printf "\e[1;34mcompile\e[0m $$(patsubst $(prorab_root_dir)%,%,$$<)\n" || printf "compile $$(patsubst $(prorab_root_dir)%,%,$$<)\n"
817+
$(.RECIPEPREFIX)$(call prorab-private-print,compile, $$(patsubst $(prorab_root_dir)%,%,$$<),1;34)
814818
$(.RECIPEPREFIX)$(a)mkdir -p $$(dir $$@)
815819
# NOTE: using short -x option instead of --language because some compilers (e.g. emcc) only support -x
816820
$(.RECIPEPREFIX)$(a)(cd $(d) && $(this_cxx) -x c++ -c -MF "$$(patsubst %.o,%.d,$$@)" -MD -MP -o "$$@" $(prorab_cxxflags) $$<)
817821
$(.RECIPEPREFIX)$(a)$(prorab_private_d_file_sed_command)
818822

819823
# compile .c static pattern rule
820824
$(prorab_this_c_objs): $(prorab_this_obj_dir)$(prorab_this_obj_spacer)%.o: $(d)% $(prorab_cflags_file)
821-
$(.RECIPEPREFIX)@test -t 1 && printf "\e[0;35mcompile\e[0m $$(patsubst $(prorab_root_dir)%,%,$$<)\n" || printf "compile $$(patsubst $(prorab_root_dir)%,%,$$<)\n"
825+
$(.RECIPEPREFIX)$(call prorab-private-print,compile, $$(patsubst $(prorab_root_dir)%,%,$$<),0;35)
822826
$(.RECIPEPREFIX)$(a)mkdir -p $$(dir $$@)
823827
# NOTE: using short -x option instead of --language because some compilers (e.g. emcc) only support -x
824828
$(.RECIPEPREFIX)$(a)(cd $(d) && $(this_cc) -x c -c -MF "$$(patsubst %.o,%.d,$$@)" -MD -MP -o "$$@" $(prorab_cflags) $$<)
@@ -827,7 +831,7 @@ $(if $(this_lint_cmd),$(if $(filter $(lint),off),,$(.RECIPEPREFIX)$(a)(cd $(d) &
827831

828832
# compile .h.hdr_c static pattern rule
829833
$(prorab_this_h_objs): $(d)%.o: $(d)% $(prorab_cflags_file)
830-
$(.RECIPEPREFIX)@test -t 1 && printf "\e[0;35mcompile\e[0m $$(patsubst $(prorab_root_dir)%,%,$$<)\n" || printf "compile $$(patsubst $(prorab_root_dir)%,%,$$<)\n"
834+
$(.RECIPEPREFIX)$(call prorab-private-print,compile, $$(patsubst $(prorab_root_dir)%,%,$$<),0;35)
831835
$(.RECIPEPREFIX)$(a)mkdir -p $$(dir $$@)
832836
# NOTE: using short -x option instead of --language because some compilers (e.g. emcc) only support -x
833837
$(.RECIPEPREFIX)$(a)(cd $(d) && $(this_cc) -x c -c -MF "$$(patsubst %.o,%.d,$$@)" -MD -MP -o "$$@" $(prorab_cflags) $$<)
@@ -837,7 +841,7 @@ $(.RECIPEPREFIX)$(a)$(prorab_private_d_file_sed_command)
837841
# Note, that assembler has its own ".include" directive to include files, so in addition to preprocessor include
838842
# directives, there can be .include directives, and we need to generate dependency rules (into .d file) for both of those.
839843
$(prorab_this_as_objs): $(prorab_this_obj_dir)$(prorab_this_obj_spacer)%.o: $(d)% $(prorab_asflags_file)
840-
$(.RECIPEPREFIX)@test -t 1 && printf "\e[2;36mcompile\e[0m $$(patsubst $(prorab_root_dir)%,%,$$<)\n" || printf "compile $$(patsubst $(prorab_root_dir)%,%,$$<)\n"
844+
$(.RECIPEPREFIX)$(call prorab-private-print,compile, $$(patsubst $(prorab_root_dir)%,%,$$<),2;36)
841845
$(.RECIPEPREFIX)$(a)mkdir -p $$(dir $$@)
842846
$(.RECIPEPREFIX)$(a)(cd $(d) && $(this_cc) -E $(this_cppflags) -MF "$$(patsubst %.o,%.d,$$@)" -MT "$$@" -MD -MP $$< | $(this_as) $(if $(filter true,$(this_as_supports_deps_gen)),-MD "$$(patsubst %.o,%.as.d,$$@)") -o "$$@" $(prorab_asflags))
843847
$(if $(filter true,$(this_as_supports_deps_gen)),$(.RECIPEPREFIX)$(a)cat $$(patsubst %.o,%.as.d,$$@) >> $$(patsubst %.o,%.d,$$@) && rm $$(patsubst %.o,%.as.d,$$@))
@@ -876,11 +880,11 @@ $(.RECIPEPREFIX)$(a)rm -rf $(prorab_this_obj_dir)
876880
# to the binary name.
877881
# this is why we build the binary and create symbolic link in the same recepie.
878882
$(prorab_this_name): $(prorab_this_objs) $(prorab_ldargs_file) $(prorab_objs_file) $(prorab_private_dep_libs)
879-
$(.RECIPEPREFIX)@test -t 1 && printf "\e[0;31mlink\e[0m $(patsubst $(prorab_root_dir)%,%,$(prorab_private_this_binary_name))\n" || printf "link $(patsubst $(prorab_root_dir)%,%,$(prorab_private_this_binary_name))\n"
883+
$(.RECIPEPREFIX)$(call prorab-private-print,link, $(patsubst $(prorab_root_dir)%,%,$(prorab_private_this_binary_name)),0;31)
880884
$(.RECIPEPREFIX)$(a)mkdir -p $(d)$(prorab_private_out_dir)
881885
$(.RECIPEPREFIX)$(a)(cd $(d) && $(this_cc) $(prorab_ldflags) $$(filter %.o,$$^) $(prorab_ldlibs) -o "$(prorab_private_this_binary_name)")
882886
$(if $(prorab_this_so_name),
883-
$(.RECIPEPREFIX)@test -t 1 && printf "\e[1;36mcreate symbolic link\e[0m $(notdir $(prorab_this_name)) -> $(notdir $(prorab_private_this_binary_name))\n" || printf "create symbolic link $(notdir $(prorab_this_name)) -> $(notdir $(prorab_private_this_binary_name))\n"
887+
$(.RECIPEPREFIX)$(call prorab-private-print,create symbolic link, $(notdir $(prorab_this_name)) -> $(notdir $(prorab_private_this_binary_name)),1;36)
884888
$(.RECIPEPREFIX)$(a)(cd $(dir $(prorab_private_this_binary_name)) && ln -f -s $(notdir $(prorab_private_this_binary_name)) $(notdir $(prorab_this_name)))
885889
)
886890

0 commit comments

Comments
 (0)