make: config file for library linking - Unix

This is a discussion on make: config file for library linking - Unix ; Hello, I have implemented the Makefile what automatically search the given directory and build up the executables (.exe) from the source codes. %.exe:%.o $(CC) $(LIB_FLAG) $ %.o:%.cpp $(CC) -c $(CCFLAGS) -I $(INCLUDE_DIR) $ Now I would like to add the ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: make: config file for library linking

  1. make: config file for library linking

    Hello,
    I have implemented the Makefile what automatically search the given
    directory and build up the executables (.exe) from the source codes.

    %.exe:%.o
    $(CC) $(LIB_FLAG) $< $(TEST_LIB) -o $@ $(STANDART_LIB)

    %.o:%.cpp
    $(CC) -c $(CCFLAGS) -I $(INCLUDE_DIR) $< -o ./$@

    Now I would like to add the possibility that for each .cpp file is a
    special config file in the same directory as the .cpp file what
    determines what libraries should be linked to the executable.
    Do you have any idea or experiences?
    Thank you a lot.
    Have a nice day
    Martin

  2. Re: make: config file for library linking

    On Mar 2, 5:51 am, Martin Vcelak wrote:
    > Hello,
    > I have implemented the Makefile what automatically search the given
    > directory and build up the executables (.exe) from the source codes.
    >
    > %.exe:%.o
    > $(CC) $(LIB_FLAG) $< $(TEST_LIB) -o $@ $(STANDART_LIB)
    >
    > %.o:%.cpp
    > $(CC) -c $(CCFLAGS) -I $(INCLUDE_DIR) $< -o ./$@
    >
    > Now I would like to add the possibility that for each .cpp file is a
    > special config file in the same directory as the .cpp file what
    > determines what libraries should be linked to the executable.


    Something like this?

    # if you use the standard variables, you can just use
    # the built-in rule for compiling .cpp

    CXXFLAGS = ...whatever...
    CPPFLAGS = -I $(INCLUDE_DIR)

    # put each exe's extra link options (e.g. -lxxx -lyyy) into
    "foo.exe.opts"

    %.exe : %.o %.exe.opts
    $(CXX) -o $@ $< $(LIB_FLAG) $(TEST_LIB) $(STANDARD_LIB) `cat $@.opts`


    > Do you have any idea or experiences?
    > Thank you a lot.
    > Have a nice day
    > Martin



  3. Re: make: config file for library linking

    Thanks for answer,
    I have solved it in this way:

    %.exe:TEST_DEP_OBJ=$(shell cat $(wildcard $(patsubst %.exe,%.cfg,$@))
    /dev/null)
    %.exe:%.o $(patsubst %.exe,%.cfg,%.exe)
    @echo Linking objects: $(TEST_DEP_OBJ)
    $(CC) $(LIB_FLAG) $< $(TEST_LIB) -o $@ $(TEST_DEP_OBJ) $(STANDART_LIB)

    For me it is more comfortable if I see libraries what I'm linking than
    only 'cat ...' in the gcc command.
    Best regards
    Martin

    toby napsal(a):
    > On Mar 2, 5:51 am, Martin Vcelak wrote:
    >> Hello,
    >> I have implemented the Makefile what automatically search the given
    >> directory and build up the executables (.exe) from the source codes.
    >>
    >> %.exe:%.o
    >> $(CC) $(LIB_FLAG) $< $(TEST_LIB) -o $@ $(STANDART_LIB)
    >>
    >> %.o:%.cpp
    >> $(CC) -c $(CCFLAGS) -I $(INCLUDE_DIR) $< -o ./$@
    >>
    >> Now I would like to add the possibility that for each .cpp file is a
    >> special config file in the same directory as the .cpp file what
    >> determines what libraries should be linked to the executable.

    >
    > Something like this?
    >
    > # if you use the standard variables, you can just use
    > # the built-in rule for compiling .cpp
    >
    > CXXFLAGS = ...whatever...
    > CPPFLAGS = -I $(INCLUDE_DIR)
    >
    > # put each exe's extra link options (e.g. -lxxx -lyyy) into
    > "foo.exe.opts"
    >
    > %.exe : %.o %.exe.opts
    > $(CXX) -o $@ $< $(LIB_FLAG) $(TEST_LIB) $(STANDARD_LIB) `cat $@.opts`
    >
    >
    >> Do you have any idea or experiences?
    >> Thank you a lot.
    >> Have a nice day
    >> Martin

    >


  4. Re: make: config file for library linking

    On Mar 3, 12:45 pm, Martin Vcelak wrote:
    > Thanks for answer,
    > I have solved it in this way:
    >
    > %.exe:TEST_DEP_OBJ=$(shell cat $(wildcard $(patsubst %.exe,%.cfg,$@))
    > /dev/null)
    > %.exe:%.o $(patsubst %.exe,%.cfg,%.exe)
    > @echo Linking objects: $(TEST_DEP_OBJ)
    > $(CC) $(LIB_FLAG) $< $(TEST_LIB) -o $@ $(TEST_DEP_OBJ) $(STANDART_LIB)
    >
    > For me it is more comfortable if I see libraries what I'm linking than
    > only 'cat ...' in the gcc command.


    Nice solution. Why do you have '/dev/null' there?

    > Best regards
    > Martin
    >
    > toby napsal(a):
    >
    > > On Mar 2, 5:51 am, Martin Vcelak wrote:
    > >> Hello,
    > >> I have implemented the Makefile what automatically search the given
    > >> directory and build up the executables (.exe) from the source codes.

    >
    > >> %.exe:%.o
    > >> $(CC) $(LIB_FLAG) $< $(TEST_LIB) -o $@ $(STANDART_LIB)

    >
    > >> %.o:%.cpp
    > >> $(CC) -c $(CCFLAGS) -I $(INCLUDE_DIR) $< -o ./$@

    >
    > >> Now I would like to add the possibility that for each .cpp file is a
    > >> special config file in the same directory as the .cpp file what
    > >> determines what libraries should be linked to the executable.

    >
    > > Something like this?

    >
    > > # if you use the standard variables, you can just use
    > > # the built-in rule for compiling .cpp

    >
    > > CXXFLAGS = ...whatever...
    > > CPPFLAGS = -I $(INCLUDE_DIR)

    >
    > > # put each exe's extra link options (e.g. -lxxx -lyyy) into
    > > "foo.exe.opts"

    >
    > > %.exe : %.o %.exe.opts
    > > $(CXX) -o $@ $< $(LIB_FLAG) $(TEST_LIB) $(STANDARD_LIB) `cat $@.opts`

    >
    > >> Do you have any idea or experiences?
    > >> Thank you a lot.
    > >> Have a nice day
    > >> Martin



  5. Re: make: config file for library linking

    In article <05898848-d5e7-401b-be63-9ec8e3000a3e@i12g2000prf.googlegroups.com>,
    toby wrote:
    >On Mar 3, 12:45 pm, Martin Vcelak wrote:
    >> Thanks for answer,
    >> I have solved it in this way:
    >>
    >> %.exe:TEST_DEP_OBJ=$(shell cat $(wildcard $(patsubst %.exe,%.cfg,$@))
    >> /dev/null)
    >> %.exe:%.o $(patsubst %.exe,%.cfg,%.exe)
    >> @echo Linking objects: $(TEST_DEP_OBJ)
    >> $(CC) $(LIB_FLAG) $< $(TEST_LIB) -o $@ $(TEST_DEP_OBJ) $(STANDART_LIB)
    >>
    >> For me it is more comfortable if I see libraries what I'm linking than
    >> only 'cat ...' in the gcc command.

    >
    >Nice solution. Why do you have '/dev/null' there?


    Probably to avoid getting errors or unexpected results if the patsubst
    expands to an empty set.
    (In this case, the cat would have no arguments, so it would wait for
    input on stdin; probably not something you want to do in the middle of
    a long build.)


    dave

    --
    Dave Vandervies dj3vande at eskimo dot com
    I suspect my neighbours learned some new italians words yesterday evening,
    I only hope they are not going to show their knowledge in italy
    --Davide Bianchi in the scary devil monastery

  6. Re: make: config file for library linking

    On Mar 4, 12:54 pm, dj3va...@csclub.uwaterloo.ca.invalid wrote:
    > In article <05898848-d5e7-401b-be63-9ec8e3000...@i12g2000prf.googlegroups.com>,
    >
    > toby wrote:
    > >On Mar 3, 12:45 pm, Martin Vcelak wrote:
    > >> Thanks for answer,
    > >> I have solved it in this way:

    >
    > >> %.exe:TEST_DEP_OBJ=$(shell cat $(wildcard $(patsubst %.exe,%.cfg,$@))
    > >> /dev/null)
    > >> %.exe:%.o $(patsubst %.exe,%.cfg,%.exe)
    > >> @echo Linking objects: $(TEST_DEP_OBJ)
    > >> $(CC) $(LIB_FLAG) $< $(TEST_LIB) -o $@ $(TEST_DEP_OBJ) $(STANDART_LIB)

    >
    > >> For me it is more comfortable if I see libraries what I'm linking than
    > >> only 'cat ...' in the gcc command.

    >
    > >Nice solution. Why do you have '/dev/null' there?

    >
    > Probably to avoid getting errors or unexpected results if the patsubst
    > expands to an empty set.
    > (In this case, the cat would have no arguments, so it would wait for
    > input on stdin; probably not something you want to do in the middle of
    > a long build.)


    Ah. Even cleverer.

    >
    > dave
    >
    > --
    > Dave Vandervies dj3vande at eskimo dot com
    > I suspect my neighbours learned some new italians words yesterday evening,
    > I only hope they are not going to show their knowledge in italy
    > --Davide Bianchi in the scary devil monastery



+ Reply to Thread