* Dynamic make target
@ 2009-12-02 17:49 Toan Pham
2009-12-02 18:20 ` Manish Katiyar
2009-12-03 5:30 ` Glynn Clements
0 siblings, 2 replies; 3+ messages in thread
From: Toan Pham @ 2009-12-02 17:49 UTC (permalink / raw)
To: linux-c-programming
hi all,
I do not know where to ask this question perhaps this mailing list is
best because it had to do with c complilation.
I would like to set up a make target dynamicly. for example
when one issue command: make sda1
it auto compile and install to a mount point @ /mnt/sda1
similiarly: make sda2 would compile and install to /mnt/sda2
i know that in a makefile one can accomplish this by setting up two targets, ie.
sda1:
make all
mount /dev/sda1 /mnt/sda1
cp releases/* /mnt/sda1
umount /mnt/sda1
sda2:
make all
mount /dev/sda1 /mnt/sda2
cp releases/* /mnt/sda2
umount /mnt/sda2
i am curious if we can simplify everything by having a make target
like this when no matches found
$param1:
make all
mount /dev/sda1 /mnt/$param1
cp releases/* /mnt/$param1
umount /mnt/$param1
thank you,
Toan
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: Dynamic make target
2009-12-02 17:49 Dynamic make target Toan Pham
@ 2009-12-02 18:20 ` Manish Katiyar
2009-12-03 5:30 ` Glynn Clements
1 sibling, 0 replies; 3+ messages in thread
From: Manish Katiyar @ 2009-12-02 18:20 UTC (permalink / raw)
To: Toan Pham; +Cc: linux-c-programming
On Wed, Dec 2, 2009 at 11:19 PM, Toan Pham <tpham3783@gmail.com> wrote:
> hi all,
>
> I do not know where to ask this question perhaps this mailing list is
> best because it had to do with c complilation.
>
> I would like to set up a make target dynamicly. for example
>
> when one issue command: make sda1
> it auto compile and install to a mount point @ /mnt/sda1
>
> similiarly: make sda2 would compile and install to /mnt/sda2
>
>
> i know that in a makefile one can accomplish this by setting up two targets, ie.
>
> sda1:
> make all
> mount /dev/sda1 /mnt/sda1
> cp releases/* /mnt/sda1
> umount /mnt/sda1
>
> sda2:
> make all
> mount /dev/sda1 /mnt/sda2
> cp releases/* /mnt/sda2
> umount /mnt/sda2
>
>
> i am curious if we can simplify everything by having a make target
> like this when no matches found
Will something like this help ?
/tmp/test> make
echo "Making defaults"
Making defaults
/tmp/test> make TARGET=manish
echo manish is target;
manish is target
/tmp/test> cat Makefile
ifeq ("$(origin TARGET)", "command line")
$(TARGET):
echo $@ is target;
else
all:
echo "Making defaults"
endif
>
> $param1:
> make all
> mount /dev/sda1 /mnt/$param1
> cp releases/* /mnt/$param1
> umount /mnt/$param1
>
> thank you,
>
> Toan
> --
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
--
Thanks -
Manish
==================================
[$\*.^ -- I miss being one of them
==================================
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: Dynamic make target
2009-12-02 17:49 Dynamic make target Toan Pham
2009-12-02 18:20 ` Manish Katiyar
@ 2009-12-03 5:30 ` Glynn Clements
1 sibling, 0 replies; 3+ messages in thread
From: Glynn Clements @ 2009-12-03 5:30 UTC (permalink / raw)
To: Toan Pham; +Cc: linux-c-programming
Toan Pham wrote:
> I do not know where to ask this question perhaps this mailing list is
> best because it had to do with c complilation.
>
> I would like to set up a make target dynamicly. for example
>
> when one issue command: make sda1
> it auto compile and install to a mount point @ /mnt/sda1
>
> similiarly: make sda2 would compile and install to /mnt/sda2
>
>
> i know that in a makefile one can accomplish this by setting up two targets, ie.
>
> sda1:
> make all
> mount /dev/sda1 /mnt/sda1
> cp releases/* /mnt/sda1
> umount /mnt/sda1
>
> sda2:
> make all
> mount /dev/sda1 /mnt/sda2
> cp releases/* /mnt/sda2
> umount /mnt/sda2
>
>
> i am curious if we can simplify everything by having a make target
> like this when no matches found
>
> $param1:
> make all
> mount /dev/sda1 /mnt/$param1
> cp releases/* /mnt/$param1
> umount /mnt/$param1
You could use a pattern rule, e.g.:
sda%:
make all
mount /dev/$@ /mnt/$@
cp releases/* /mnt/$@
umount /mnt/$@
But that's really abusing make; it's better to use variables for this,
e.g.:
DISC = sda1
install:
make all
mount /dev/$(DISC) /mnt/$(DISC)
cp releases/* /mnt/$(DISC)
umount /mnt/$(DISC)
and use e.g.:
make install DISC=sda1
Beyond that:
1. Don't use "make" in commands; use $(MAKE) instead. This will work
if your make program is actually called e.g. gmake, make-3.81, etc.
Also, if you use "make -n", $(MAKE) will perform a recursive "make -n"
rather than just printing the "make" command.
1a. But only invoke $(MAKE) explicitly if you need to force a
particular sequence. It's usually preferable to list the target as a
prerequisite, e.g.:
install: all
rather than:
install:
$(MAKE) all
2. Use $(INSTALL) rather than "cp". "install" will replace files
atomically, while "cp" overwrites the destination in-place. This fails
if the destination is an executable which is in-use, and can cause
problems due to parallel builds attempting to proceed with an
incomplete source file.
3. "phony" targets shouldn't be over-used. Their behaviour can be
non-intuitive with respect to parallel builds, and executing commands
unconditionally becomes a nuisance once a project gets large.
--
Glynn Clements <glynn@gclements.plus.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-12-03 5:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-02 17:49 Dynamic make target Toan Pham
2009-12-02 18:20 ` Manish Katiyar
2009-12-03 5:30 ` Glynn Clements
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).