Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 520
  • Last Modified:

How to move files with a make file?

Hi!
I am using a make file for my c++ project and i would like to move my bin files to a directory bin that i have created in the same dir as my cc files.
How can i do this?
Some of the  make file is posted and looks like this:
[code/]
# Targets
PROGS      = mydiskserver mymemserver myclient

# Phony targets
.PHONY: all clean cleaner

all: $(PROGS)

mydiskserver: mydiskserver.o messagehandler.o commandfactory.o createnewsgroup.o listnewsgroup.o deletenewsgroup.o listarticles.o createarticle.o getarticle.o deletearticle.o diskdatabase.o filehandler.o identifier.o

mymemserver: mymemserver.o messagehandler.o commandfactory.o createnewsgroup.o listnewsgroup.o deletenewsgroup.o listarticles.o createarticle.o getarticle.o deletearticle.o memorydatabase.o filehandler.o identifier.o

myclient: myclient.o uiprinter.o uicommandfactory.o messagehandler.o uilistnewsgroup.o uicreatenewsgroup.o uideletenewsgroup.o uilistarticles.o uicreatearticle.o uireadarticle.o uideletearticle.o uiclearwindow.o

movebin:
    $(MV) myclient mydisserver mymemserver ../bin/
 
# Standard clean and cleaner
clean:
      $(RM) *.o    

cleaner: clean
      $(RM) $(PROGS)

/code]
it is the movebin command that i cant get to work the bin files have the same names as the link command.
The error i get is
 Makefile:50: *** missing separator.  Stop.
0
mikrodidakt
Asked:
mikrodidakt
  • 4
  • 3
2 Solutions
 
mikrodidaktAuthor Commented:
I dont get the error message any more  by using tab instead og space at the movebin command but i dont get the bin files to be moved to the bin dir?
I changed the make file to this

# Targets
PROGS     = mydiskserver mymemserver myclient movebin
....
.......
.........
movebin:
    $(MV) myclient mydisserver mymemserver ../bin/

what can i do?




0
 
Duncan RoeSoftware DeveloperCommented:
movebin should be declared PHONY, as you've done for all & clean. It's not a program, and you should't have it in PROGS
But that's not your real problem. movebin needs dependencies or make won't make it.
However if all you want to do is have your executables in the bin subdirectory, you can do that directly by something like:
PROGS     = bin/mydiskserver bin/mymemserver bin/myclient
 
  bin/bin/mydiskserver: $(SERVEROBJS)
^I$(CC) -o $@ $^
0
 
Duncan RoeSoftware DeveloperCommented:
See "info make" "Automatic Variables" for an explanation
0
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
ahoffmannCommented:
movebin::
    $(MV) myclient mydisserver mymemserver ../bin/

# or

movebin: myclient mydisserver mymemserver
    $(MV) myclient mydisserver mymemserver ../bin/

# keep the tab in mind :)
0
 
Duncan RoeSoftware DeveloperCommented:
A few typos in my last post - and I didn't notice you wanted ../bin. Sorry about that.

Really Really simple solution: get rid of movebin and do the move as a part of all

PROGS     = mydiskserver mymemserver myclient

 all: $(PROGS)
    mv $^ ../bin

You can use a macro like MV for your wanted mv command (mv -i, mv -f &c) as ahoffman suggests.
make will expand $^ to the contents of $(PROGS) (in general, $^ expands to the current rule's dependencies).
As always, put a tab at the start of the 2nd line above (I showed ^I last time to indicate that).

BTW my bad last time: movebin *could* be in PROGS ( and also .PHONY because no movebin file is created). But then movebin must have all targets in PROGS except itself as dependencies - not real neat.

ahoffman - I hadn't seen that double-colon to avoid the need for dependencies before - cool
0
 
ahoffmannCommented:
> hadn't seen that double-colon ..
not all make do support it, but most modern make (IIRC not part of the original AT&T), you then have to use:
.PHONY: movebin
0
 
ahoffmannCommented:
I'd vote for a split
0
 
Duncan RoeSoftware DeveloperCommented:
Fine with me
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now