Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6809651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:06:41+00:00 2026-05-26T20:06:41+00:00

I have some .PHONY targets such as ‘clean’, ‘backup’, and ‘help’ the rule for

  • 0

I have some .PHONY targets such as ‘clean’, ‘backup’, and ‘help’
the rule for some of these targets is very large.
For example:

   .PHONY: backup
    backup:
        @$(GREEN)
        @mkdir -p backup/include #make an backup include folder if it doesn't already exist
        @mkdir -p backup/src     #make a backup src folder if it doesn't already exist
        @mkdir -p backup/docs    #make a backup docs folder if it doesn't already exist

        @total=0; headerCount=0; sourceCount=0; documentCount=0; \
        for file in $(HEADER_PATH)*; do \
            if ls $$file[~] >/dev/null 2>&1; then \
                mv -fu $$file[~] backup/$$file; \
                let "headerCount+=1"; \
                echo $(DATE)[Backed Up] $$file~ >> $(LOG); \
            fi; \
        done; \
        for file in $(SOURCE_PATH)*; do \
            if ls $$file[~] >/dev/null 2>&1; then \
                mv -fu $$file[~] backup/$$file; \
                let "sourceCount+=1"; \
                echo $(DATE)[Backed Up] $$file~ >> $(LOG); \
            fi; \
        done; \
        for file in $(DOC_PATH)*; do \
            if ls $$file[~] >/dev/null 2>&1; then \
                mv -fu $$file[~] backup/$$file; \
                let "documentCount+=1"; \
                echo $(DATE)[Backed Up] $$file~ >> $(LOG); \
            fi; \
        done; \
        let "total= headerCount + sourceCount + documentCount"; \
        echo -n $(OUTPUT_PROMPT)" "; \
        if test $$total -eq 0; then \
            echo Nothing To Back up; \
        else \
            if test $$headerCount -eq $$total; then \
                echo -n $$total" "; \
                echo -n "Header"; \
                if test $$total -ge 2; then \
                    echo -n "s"; \
                fi; \
                echo " Backed Up"; \
            elif test $$sourceCount -eq $$total; then \
                echo -n $$total" "; \
                echo -n "Source"; \
                if test $$total -ge 2; then \
                    echo -n "s"; \
                fi; \
                echo " Backed Up"; \
            elif test $$documentCount -eq $$total; then \
                echo -n $$total" "; \
                echo -n "Document"; \
                if test $$total -ge 2; then \
                    echo -n "s"; \
                fi; \
                echo " Backed Up"; \
            else \
                $(UNDERLINE); echo $$total " Files Backed Up"; $(UNUNDERLINE); \
                if test $$headerCount -eq 1; then \
                    echo $(OUTPUT_PROMPT)" "$$headerCount header; \
                elif test $$headerCount -ge 2; then \
                    echo $(OUTPUT_PROMPT)" "$$headerCount headers; \
                fi; \
                if test $$sourceCount -eq 1; then \
                    echo $(OUTPUT_PROMPT)" "$$sourceCount source; \
                elif test $$sourceCount -ge 2; then \
                    echo $(OUTPUT_PROMPT)" "$$sourceCount sources; \
                fi; \
                if test $$documentCount -eq 1; then \
                    echo $(OUTPUT_PROMPT)" "$$documentCount document; \
                elif test $$documentCount -ge 2; then \
                    echo $(OUTPUT_PROMPT)" "$$documentCount documents; \
                fi; \
            fi; \
        fi;
        @$(DEFAULT_TEXT)

what the code does is not important, but I wanted to illustrate that it has macros in which ‘make’ must expand, and that it also performs shell code (bash), and that some indication on what the script did, is displayed in the terminal.
I want to put this script outside of ‘make’ in another directory, and turn that code into something like this:

.PHONY: backup
backup:
    @run scripts/backup.scr
    #or something similar to that

How can I put the rule of my target (which is makefile/bash code) into a separate file, and have make practically paste it in so that it runs how I had it originally?

I thought I might be able to use the “include” command inside ‘make’.
It looks like it is used to include other makefiles though..
maybe I should just paste the entire target/rule into another makefile, and then include that makefile into my main one?
Would that be the best way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:06:41+00:00Added an answer on May 26, 2026 at 8:06 pm

    In your case, you have quite few output variables. It might be worth the hassle to separate the generation and execution, like:

    clean : clean-script
        sh clean-script
        rm -f clean-script
    
    clean-script : clean-script.in
         sed -e 's:[@]HEADER_PATH[@]:$(HEADER_PATH):g' $<.in > $@
    

    And write clean-script.in as a clean sh script with a few substitutions.
    If you use GNU make, you can of course build a list of output varables like:

    clean-script : clean-script.in
         sed $(foreach var,$(SUBSTVARS),-e 's:[@]$(var)[@]:$($(var)):g') $<.in > $@
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some trigger in my Windows Phone 7 Silverlight app such as <Grid
i have some fields in my database table,and a field with phone name ,
Say I have a Date, or a Phone number, or some Class which I
I have some UI in VB 2005 that looks great in XP Style, but
I have some ASP.NET web services which all share a common helper class they
I have some code for starting a thread on the .NET CF 2.0: ThreadStart
We have some input data that sometimes appears with &nbsp characters on the end.
I have some classes layed out like this class A { public virtual void
I have some C# / asp.net code I inherited which has a textbox which
I have some code like this in a winforms app I was writing to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.