help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: can't always get make to auto create build directory


From: LMH
Subject: Re: can't always get make to auto create build directory
Date: Wed, 29 Jun 2016 14:03:31 -0400
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:43.0) Gecko/20100101 Firefox/43.0 SeaMonkey/2.40

Paul Smith wrote:
On Wed, 2016-06-29 at 12:41 -0400, LMH wrote:
Apparently the forum I posted to forwards posts to a mailing list.

The GNU/FSF mailing lists have existed since the 1990's.  In that time
various external sites have come along and begun mirroring the mailing
lists, and some of them also provide the ability to post back to the
list.  We aren't involved with this.  If you have an issue with how
they do it, you should bring it up with them.

I don't generally have an issue with anyone who is trying to be helpful, though the nabble methodology seems to leave a bit to be desired in this case. It's just as easy to post directly to the mailing list if that is preferable.

The mot reliable way to ask questions is to send directly to the
mailing lists, using text-mode rather than HTML.

I also never read email in HTML as it can be a considerable security risk. It is nice to have code tags to preserve indents and such but in the case of a make file, that should not be an issue. I just didn't realize that I was composing email.

Below is the text of my original post as I expected it would appear. Please let me know if there are any questions or if I need to post any additional information.

Note:
I have added the line for my "all" target as it was left out of my earlier post.

LMH



Hello,

I have a make file that gathers some local information and uses it (in theory) to create a locally named build directory if it doesn't exist.

SOURCELOC = ./src

# get version of g++
CMP := $(shell g++ --version | cut -d ' ' -f 3 | sed q)
CMP := gcc-$(CMP)

# create build location name
OS   := $(shell uname -s)
ARCH := $(shell uname -m)
KERN := $(shell uname -r | cut -d. -f 1,2)
BDIR := bld_$(OS)_$(KERN).$(ARCH)_$(CMP)

#test print
$(info OS is  : $(OS))
$(info BDIR is: $(BDIR))

# create build directory if it doesn't exist
$(BDIR):
        @mkdir -p $(BDIR)

all: $(BDIR)/SMD2_i386.exe


The test print code prints what I would expect,

OS is  : CYGWIN_NT-5.1
BDIR is: bld_CYGWIN_NT-5.1_2.3.i686_gcc-4.9.3


When I run this from "make -f makefile all" I get an error,

Assembler messages:
Fatal error: can't create bld_CYGWIN_NT-5.1_2.3.i686_gcc-4.9.3/main.o: No such file or directory
MAKE_SMD1.mak:73: recipe for target 
'bld_CYGWIN_NT-5.1_2.3.i686_gcc-4.9.3/main.o' failed
make: *** [bld_CYGWIN_NT-5.1_2.3.i686_gcc-4.9.3/main.o] Error 1


If I manually create the build directory, bld_CYGWIN_NT-5.1_2.3.i686_gcc-4.9.3, the compiler continues and creates the first object, main.o. I have had this issue off and on and can't seem to identify where the problem is. In some cases, the directory doesn't get created and in others it does. I use the same syntax for mkdir in every make file, so I'm not sure where I am going wrong. It's not the end of the world to have to manually create a directory but I am trying to set up some of this to be automated based on whatever system I am booted into. The "@ mkdir" statement is indented with a tab if that isn't clear with this formatting.

For now, I have replaced the make command,

# create build directory if it doesn't exist
$(BDIR):
        @mkdir -p $(BDIR)


with some shell commands,

# run ls to determine if build directory exists
EXISTS := $(shell ls -d $(BDIR))
# if the output of ls is empty, create directory
ifeq "$(EXISTS)" ""
   $(shell mkdir $(BDIR))
endif


This seems to work. The code creates the directory when it is not present and does nothing when it is. There are no error messages to deal with.

I would prefer to get this working with make commands instead of going to the shell but I do need to get this working with some solution. Can anyone point out why my make commands fail to create the directory when it doesn't exist? Is the shell method above a reasonable solution, meaning will it likely work on most platforms?

Suggestions would be appreciated.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]