What would be the best way to compile a project with GDC?

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Mon Aug 5 03:05:02 PDT 2013


On 08/01/2013 07:46 PM, Gary Willoughby wrote:
> There must be a simpler way to pass these files to dmd in the right order? rdmd
> does it somehow.
> 
> Any ideas? How do you handle compiling projects with 50+ source files?

This is a Makefile pattern I've found useful:
https://github.com/WebDrake/Dgraph/blob/cache/Makefile

You have:

   DC -- D compiler, so you can replace with an arbitrary choice.  By habit I
         always use the DMD-like interfaces of compilers (so, gdmd and not gdc,
         ldmd2 and not ldc2), but you don't need to do that.

   DFLAGS -- compiler flags to use.

   LIBSRC -- list of source files.  You can see how I just use *.d to bring in
             everything.  This is fine in many circumstances.

   PROGS -- list of executables to build.

   all: $(PROGS) -- tells make that by default, it should build all the
                    programs.

   %: %.d $(LIBSRC)
       	$(DC) $(DFLAGS) -of$* $*.d $(LIBSRC)

       -- this basically uses a placeholder % that says: if you get issued a
          command, "make foo", then look for foo.d and build it together with
          the library sources to output the executable foo.

          It's a useful pattern because it means (i) if you add an extra program
          to the list of PROGS you don't have to update the Makefile anywhere
          else and (ii) you can create an arbitrary test file "bar.d" and then
          "make bar", and it'll build, even though it's not listed in PROGS.
            This means you can create and build local exploratory test programs
          which don't need to be added to the repo and for which you don't need
          to carry a local delta in your Makefile.

Whether that works for your 50+ file project will probably depend on how it's
organized.  As others have said, you may want to look into a more sophisticated
build system, and doing so is going to be helpful in any case.

Besides SCons and Tup, I've been recommended Waf and CMake.


More information about the Digitalmars-d-learn mailing list