Link to home
Start Free TrialLog in
Avatar of mikrodidakt
mikrodidakt

asked on

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.
Avatar of mikrodidakt
mikrodidakt

ASKER

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?




ASKER CERTIFIED SOLUTION
Avatar of Duncan Roe
Duncan Roe
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
See "info make" "Automatic Variables" for an explanation
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
> 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
I'd vote for a split
Fine with me