Reputation: 1579
I am very new to Makefiles, so I am probably not doing this the best way (your input is much appreciated, since I would like to learn how/why mine is bad). Anyway, here is my problem:
I have a Daemon that I wrote for a program of mine and I am trying to install it with the Makefile (target is "install"). What the "install" target is supposed to do is move the daemon binary to a location, then move the "service script" to either /etc/init.d/ or /etc/rc.d/ (since different distros have different folders...). Here is my makefile so far:
all:
@echo "Making Components"
@cd Daemon; make
@echo "Components Built"
install:
@echo "Installing Components"
@mkdir -p /usr/lib/
@cp Daemon/myprog_d /usr/lib/myprog_d
-@test -d /etc/init.d && cp Scripts/myprog /etc/init.d/
-@test -d /etc/rc.d && cp Scripts/myprog /etc/rc.d/
-@test ! -d /etc/init.d -a ! -d /etc/rc.d && echo " Warning: Couldn't install script. Manually install Scripts/myprog"
@mkdir -p /var/log/
@echo "Installed."
uninstall:
@echo "Uninstalling Components"
@./Scripts/myprog stop > /dev/null
@rm -f /usr/lib/myprog_d
@echo "Uninstall complete"
clean:
@echo "Cleaning Components"
@cd Daemon; make clean
@echo "Clean complete"
As you can see, the "install" target tests to see if those two directories exist and, if they do, copies the script into them (I haven't yet done it to "uninstall", don't worry).
My first question: Is this the right way to do this? The "all" and "clean" targets work (there is another makefile in "Daemon/", as you can deduce), but I want to know if there is a cleaner way of doing this.
Secondly, because the "test" function returns non-zero, I had to do "-" before it so the error would be ignored. Unfortunately, that results in the "make install" output being:
Installing Components
make: [install] Error 1 (ignored)
make: [install] Error 1 (ignored)
Installed.
Which is very ugly and probably not good practice. What can I do in this case? (I have tried both -@ and @-, but @ will not suppress the "ignored" output)
Sincerely, Chris
Upvotes: 0
Views: 1394
Reputation: 99124
I'd do it this way:
@if [ -d /etc/init.d ]; then cp Scripts/myprog /etc/init.d/ ; fi
@if [ -d /etc/rc.d ]; then cp Scripts/myprog /etc/rc.d/ ; fi
And I'm a little confused by your next line (-@test ! -d /etc/init.d -a !...
) but you can probably do it the same way.
That takes care of the error messages, but if you wanted to keep the makefile as it is, you could suppress them by running make -s
.
Upvotes: 1