Thread: Makefile for similar targets

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149

    Makefile for similar targets

    I want to have a number of make target in the following format:
    Code:
    test2:mylang.exe test2.mir test2.out.expect.txt test2.err.expect.txt
    	./mylang.exe test2.mir >test2.out.txt 2>test2.err.txt
    	diff test2.out.expect.txt test2.out.txt 
    	diff test2.err.expect.txt test2.err.txt
    So I want to have targets test1, test2, test3, ect., without having to manually that whole block of code and replace test2 with testx.

    How can I do that?
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by King Mir View Post
    I want to have a number of make target in the following format:
    Code:
    test2:mylang.exe test2.mir test2.out.expect.txt test2.err.expect.txt
        ./mylang.exe test2.mir >test2.out.txt 2>test2.err.txt
        diff test2.out.expect.txt test2.out.txt 
        diff test2.err.expect.txt test2.err.txt
    So I want to have targets test1, test2, test3, ect., without having to manually that whole block of code and replace test2 with testx.

    How can I do that?
    By a separate 'configure' script ?

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    I'd rather use copy-paste then that. Seems too much to add one just for this.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Code:
    all_tests.mk: test1.mir test2.mir test3.mir
        generate_test_rules.sh $^ > $@
    
    -include all_tests.mk
    Then write script generate_test_rules.sh which takes .mir filenames on command line and prints make rules for those tests to stdout. To add a test .mir, add its name to the deps for all_tests.mk target
    Last edited by brewbuck; 11-25-2011 at 03:00 PM.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #5
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    That won't let run one test at a time. That does make me realize I don't need the testx preqs, just mylang.exe.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  6. #6
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by King Mir View Post
    That won't let run one test at a time.
    It doesn't run the tests at all, it just automatically generates the rules for the tests. You still run the tests by saying 'make test2' or whatever.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  7. #7
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    After doing some more searching, I came up with this:
    Code:
    test%:mylang.exe
    	./mylang.exe $(addprefix $@,.mir) >$(addprefix $@,.out.txt) 2>$(addprefix $@,.err.txt)
    	diff $(addprefix $@,.out.expect.txt .out.txt) 
    	diff $(addprefix $@,.err.expect.txt .err.txt)
    It seems to work.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Date in mm-dd or similar
    By Muscovy in forum C++ Programming
    Replies: 12
    Last Post: 07-18-2009, 06:22 PM
  2. difference makefile makefile.am makefile.in
    By Bargi in forum Linux Programming
    Replies: 7
    Last Post: 10-28-2007, 02:08 PM
  3. Something similar to novell
    By frozt in forum Windows Programming
    Replies: 0
    Last Post: 06-09-2006, 12:04 PM
  4. make incorrectly remaking targets
    By jarro_2783 in forum C Programming
    Replies: 4
    Last Post: 05-26-2006, 12:10 AM
  5. Umm...Inheritance or something similar?
    By Callith in forum C++ Programming
    Replies: 5
    Last Post: 11-27-2004, 10:41 AM