comp.lang.c
[Top] [All Lists]

Re: How can I deal with multi-dirs?

Subject: Re: How can I deal with multi-dirs?
From: Mingliang Liu
Date: Tue, 1 Apr 2008 10:28:44 -0700 PDT
Newsgroups: comp.lang.c

On Apr 1, 11:09 pm, Antoninus Twink <nos...@xxxxxxxxxxxxxx> wrote:
> On  1 Apr 2008 at 12:20, fnegroni wrote:
>
>
>
> > On Apr 1, 11:16 am, Antoninus Twink <nos...@xxxxxxxxxxxxxx> wrote:
> >> On  1 Apr 2008 at  8:05, M.Liang Liu wrote:
>
> >> > I have a project with the following dirs:
> >> > ---------------------------------------------------------------------------
> >> >  ------------
> >> > +src
> >> >  |-proj0
> >> >      |-program1
> >> >      |-program2
> >> >  |-proj1
> >> >      |-program1
> >> >      |-program2
> >> >      |-program3
> >> >      |-program4
> >> >  |-proj3
> >> >      |-program1
> >> >      |-program2
> >> >      |-program3
> >> >    ....
> >> >  |-proj9
> >> > -Makefile
> >> > +include
> >> > -README
> >> > +lib
> >> >  |-lib1
> >> >  |-lib2
> >> > ---------------------------------------------------------------------------
> >> >  ------------
> >> > There are 10 project-dirs here in src, named proj0-proj9. Each project
> >> > has several program_dirs which containing some .c files
> >> > All .h files are under include in the top dir, the same as src.
>
> >> > I would like to write a makefile, which can help me compile all the .c
> >> > files and generate an executable file for each *program*.  Considering
> >> > there are several independent programs in each project, the work
> >> > should be done within a single makefile at the top dir.
>
> >> > How can I deal all the programs under each project in a single top-
> >> > level makefile?
>
> >> Which part of the section of your make program's documentation on
> >> recursive use of make didn't you understand?
>
> > I think this is OT. comp.unix.programmer might be a better place to
> > ask this question.
>
> That seems unlikely, given that the OP appears to be posting from a
> Windows box.
>
> > I believe recursive makefiles have serious flaws and should be
> > avoided.
>
> I believe you've read some stupid polemic about recursive Makefiles
> having serious flaws, and have bought into it hook line and sinker.
>
> > In this case, if each project is standalone, each needs a Makefile and
> > then you might want a script to run all the makefiles in sequence.
>
> A "script", eh? But definitely not a top-level Makefile?
>
> > If the project are interlinked, the one makefile would be enough, just
> > use relative paths in your dependencies.
>
> That would be one way, but then you end up with one incredibly complex
> Makefile. Why not split the Makefile, for exactly the same reason that
> you separate out the source files into different directories?
>
> > Also, a better source code file structuring also helps: I would place
> > all source files together in the same directory. After all, if they
> > are interrelated, what would be the advantage in splitting them about?
>
> > But that's my opinion. Yours may differ.
>
> It sounds like the OP's project consists of one or more libraries, and
> then some number of independent executables that link against these
> libraries. Separating the source files for each executable into its own
> directory seems perfectly reasonable to me.

=======================Just see here!===============================

Hi, thanks for ur reply.

I am, u have seen, a freshman to Makefile and have read some
documentation without enough experience.
And I'm wondering how can I do a job gracefully if all the programs of
each project are almost independent?
Namelly, i can write a makefile for each program (so it should work
with recursive Makefiles).But the question is that I would like to
avoid copy the same Makefile for each program --- suppose my teacher
tell me that the gcc should have a O3 optimazition and then I should
modify every Makefile one by one.

Any hints?

Thanks!

<Prev in Thread] Current Thread [Next in Thread>
Privacy Policy