We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

How to move files with a make file?

mikrodidakt
mikrodidakt asked
on
Medium Priority
536 Views
Last Modified: 2010-04-21
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.
Comment
Watch Question

Author

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?




Software Developer
CERTIFIED EXPERT
Commented:
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 $@ $^

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Duncan RoeSoftware Developer
CERTIFIED EXPERT

Commented:
See "info make" "Automatic Variables" for an explanation
movebin::
    $(MV) myclient mydisserver mymemserver ../bin/

# or

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

# keep the tab in mind :)
Duncan RoeSoftware Developer
CERTIFIED EXPERT

Commented:
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
Duncan RoeSoftware Developer
CERTIFIED EXPERT

Commented:
Fine with me
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.