0

I have 3 questions about compiling and linking my project in fewer steps...

First, my project looks like: ( I use Watcom C to compile//link my project )

Directory 'MyProject' contains 3 sub directories for different modules and some files:

  • directory 'A' ( a.h and a.c included )
  • directory 'B' ( b.h and b.c included )
  • directory 'C' ( c.h and c.c included )
  • my.c and my.h
  • my.lnk
  • makefile

And within each sub directory there is one corresponding makefile...

[Q1] Assume I update a.h in directory A and a.h is referenced by b.c in directory B, then my original steps will be:

  1. compile in directory A ( obj and lib generated...)
  2. compile in directory B ( obj and lib generated...)
  3. back to directory MyProject then compile and link

Can I just take one step to cover above ?

[Q2] If I want to ignore all existing obj/lib and rebuild all, how to do it ?

  • I know this takes time but sometimes "kill and rebuild" will be better...

[Q3] If my.h is updated and it is referenced by a.c,b.c, and c.c...

Can I just take one step to cover above ?

[My makefile in sub directory looks like]

INCLUDE1 = -ic:\watcom\h
OBJECTS1 = a.obj
CFLAGS   = -zq -mf -oxsbl $(INCLUDE1)
DEST     = a.exe
COMPILER = wpp386

.erase # special cmd, tell wmake to "erase" target if make is not successful
.cpp.obj: .AUTODEPEND
      $(COMPILER) $(CFLAGS) $<

$(DEST) : $(OBJECTS1) makefile

[My makefile in main directory looks like]

INCLUDE1 = -i=c:\myproj\my -i=c:\watcom\h 
OBJECTS1 = my.obj
CFLAGS   = -zq -fp6 -mf -6r -s -oxsbl $(INCLUDE1)
DEST     = my.exe
COMPILER = wpp386
LINKER   = wlink
LNK_FILE = my.lnk

.erase # special cmd, tell wmake to "erase" target if make is not successful

.cpp.obj: .AUTODEPEND
      $(COMPILER) $(CFLAGS) $<


$(DEST) : $(OBJECTS1) makefile my.lnk
      $(LINKER) @$(LNK_FILE)

[Update 1]

I use wpp386 as compiler and it is watcom c++ tool.

To build the target I use one batch file to compile cpp file:

@echo off
del a1.lib
del *.err
wmake -h
wlib -q a1.lib + a.obj

del *.obj
  • I can successfully compile cpp file and everything is fine.
  • In directory B, I use the same way(batch file+makefile) to compile b.cpp

To sum up my project works and the reason why I ask is to find "faster compiling/linking sequence" if I just update some header file...

I tried add the command ehco hello to the rule $(DEST) and found it was ok. Then use echo $(MAKE) and got:

...
echo C:\WATCOM\BINW\WMAKE.EXE
C:\WATCOM\BINW\WMAKE.EXE
...

Thanks !

liaoo
  • 193
  • 2
  • 15
  • A good makefile should do exactly what you are asking for. How does your makefile looks like? – Matthias Aug 27 '12 at 09:15
  • To Matthias, I listed my makefiles above. – liaoo Aug 27 '12 at 09:47
  • The main Makefile must command the Makefiles in the subdirectories. Would you prefer that it `include` them, or invoke them (`$(MAKE) A/makefile`)? – Beta Aug 27 '12 at 13:14
  • To Beta: I added `( $(MAKE) A/makefile )` in the main makefile and updated a.h(for testing) in sub-directory A. Then execute **wmake** -h in the main directory and found: the lib file in A is "not" re-built... Do I miss something ? – liaoo Aug 28 '12 at 01:29

1 Answers1

1

I'm not familiar with your compiler, so I can't see how these makefiles work, so we'll have to take this one step at a time.

1) when you go into a subdirectory A, what command do you use to build the targets? Does it work? How about in subdirectory B?

2) In the main makefile, can you add a command, like echo hello to the $(DEST) rule? If that works, try echo $(MAKE).

EDIT:

Non-GNU versions of Make are troublesome, but we'll see what we can do.

Try editing the makefile in subdir A:

INCLUDE1 = -ic:\watcom\h
OBJECTS1 = a.obj
CFLAGS   = -zq -mf -oxsbl $(INCLUDE1)
DEST     = a1.lib # NOTE THIS CHANGE
COMPILER = wpp386

.erase # special cmd, tell wmake to "erase" target if make is not successful
.cpp.obj: .AUTODEPEND
      $(COMPILER) $(CFLAGS) $<

$(DEST) : $(OBJECTS1) makefile
      wlib -q $@ + $(OBJECTS1)
      del $(OBJECTS1)

Instead of the batch file, just run make -h. This should rebuild the library (if the library needs rebuilding). If it works, try moving up into MyProject and running make -h -C A. This should execute the makefile in A and rebuild the library there (unless WMAKE has some other syntax).

If that works, try making the same changes in B, then editing the $(DEST) rule in the main makefile:

$(DEST) : $(OBJECTS1) makefile my.lnk
    $(MAKE) -h -C A
    $(MAKE) -h -C B
    $(LINKER) @$(LNK_FILE)

Cross your fingers and run make -h. This should rebuild both libraries, compile, link, and solve Q1...

Beta
  • 96,650
  • 16
  • 149
  • 150
  • I tried and please check the **[Update 1]** in my question above, thanks ! – liaoo Aug 28 '12 at 04:54
  • I found 2 differences in the makefile in directory A. The 1st is `a.lib` and the 2nd is `2 prerequisites` added for target. I did not know why a.exe is changed to a.lib, but I can understand the 2nd because `Prerequisites need to be updated first, before the target on the left hand side can be updated`. For my **Q2**, I found using `wmake -a` can rebuild all targets, am I correct ? – liaoo Aug 30 '12 at 08:06
  • I don't know `wmake`, so I don't know whether `wmake -a` satisfies **Q2**. And I don't know `.AUTODEPEND`, so I don't know whether it satisfies **Q3** (if it doesn't, why have it?). – Beta Sep 01 '12 at 01:03
  • `wmake -a` means make all targs(ignoring time stamp) and `.AUTODEPEND` means With wmake and the Open Watcom compilers, it is trivial to use automatic dependency checks. All the user needs to do is specify the .AUTODEPEND directive with the appropriate rules. The C/C++ compilers as well as the Windows and OS/2 resource compiler automatically emit dependency information in object files where wmake will read it from. There is no need for additional files or compiler switches. I will check both of them...! – liaoo Sep 03 '12 at 02:34