Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

need help with makefile

0 views
Skip to first unread message

puzzlecracker

unread,
Oct 6, 2008, 10:41:49 AM10/6/08
to
I have Makefile that build a pretty complex application. In it, have

all: application that builds application. Now I want to add and
option that user can type 'make install' that will copy (and build
if it hasn't been) to $PLATFORM/application to $APP/bin/

Thanks

John Gordon

unread,
Oct 6, 2008, 11:52:14 AM10/6/08
to

> Thanks

From what you've said, adding this to your Makefile should work:

install: application
cp $PLATFORM/application $APP/bin/.

--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

viza

unread,
Oct 6, 2008, 12:09:16 PM10/6/08
to
On Mon, 06 Oct 2008 15:52:14 +0000, John Gordon wrote:
> puzzlecracker <irons...@gmail.com> writes:
>
>> I have Makefile that build a pretty complex application. In it, have
>> all: application that builds application. Now I want to add and
>> option that user can type 'make install' that will copy (and build if
>> it hasn't been) to $PLATFORM/application to $APP/bin/
>
> From what you've said, adding this to your Makefile should work:
>
> install: application
> cp $PLATFORM/application $APP/bin/.

Don't forget to add

.PHONY: install

so that make doesn't expect cp to generate a file called `install'.

Also, you probably need to set the ownership and permissions of the file.

Your system probably has a program called `install' to do these all at
once. Try:

man 1 install

Alternatively you can add more command lines to the Makefile:

install: application
cp $PLATFORM/application $APP/bin/
chmod 755 $APP/bin/
chown root:wheel $APP/bin/

puzzlecracker

unread,
Oct 6, 2008, 1:57:47 PM10/6/08
to
On Oct 6, 12:09 pm, viza <tom.v...@gm-il.com.obviouschange.invalid>
wrote:

Well, here is my solution that i discovered by googling for sample
Makefile:

Below is what has been added to the file:

.SILENT: install

install:
echo "Installing Application..."; \
if test ! -d $(APP_DIR); then \
mkdir -p $(APP_DIR)/; \
echo "Copying resources:"; \
cp -f config_file_template $(APP_DIR); \
echo "Rename config_file_template to config_file, and modify
it appropriately." ; \
cp -f start_app.sh $(APP_DIR)/; \
echo "Use start_app.sh to start the application"; \
fi; \
if test -e $(PLATFORM)/$(APP); then \
/bin/cp -f $(PLATFORM)/$(APP) $(APP_DIR)/ ; \
else \
echo $(APP) binary is missing; \
fi; \
echo Done

What do you think about this solution?

Måns Rullgård

unread,
Oct 6, 2008, 7:15:57 PM10/6/08
to
puzzlecracker <irons...@gmail.com> writes:

It's doing in 16 lines what could be done in four or less.

--
Måns Rullgård
ma...@mansr.com

toby

unread,
Oct 6, 2008, 9:02:26 PM10/6/08
to

And don't forget .PHONY, to be pedantic.

> if test -e $(PLATFORM)/$(APP); then \
> /bin/cp -f $(PLATFORM)/$(APP) $(APP_DIR)/ ; \
> else \
> echo $(APP) binary is missing; \
> fi; \

The right way to do that is to make $(PLATFORM)/$(APP) a prerequisite!

As Måns suggests, the rest can be simplified further.

James Kanze

unread,
Oct 7, 2008, 8:22:10 AM10/7/08
to
On Oct 6, 6:09 pm, viza <tom.v...@gm-il.com.obviouschange.invalid>
wrote:

> On Mon, 06 Oct 2008 15:52:14 +0000, John Gordon wrote:
> > puzzlecracker <ironsel2...@gmail.com> writes:

> >> I have Makefile that build a pretty complex application. In
> >> it, have all: application that builds application. Now I
> >> want to add and option that user can type 'make install'
> >> that will copy (and build if it hasn't been) to
> >> $PLATFORM/application to $APP/bin/

> > From what you've said, adding this to your Makefile should work:

> > install: application
> > cp $PLATFORM/application $APP/bin/.

> Don't forget to add

> .PHONY: install

> so that make doesn't expect cp to generate a file called `install'.

That's not really necessary. It does protect you if someone
accidentally creates a file named install, or from invoking the
rule twice in any given run, but typically, these aren't real
problems.

> Also, you probably need to set the ownership and permissions
> of the file.

> Your system probably has a program called `install' to do
> these all at once. Try:

> man 1 install

> Alternatively you can add more command lines to the Makefile:

> install: application
> cp $PLATFORM/application $APP/bin/
> chmod 755 $APP/bin/
> chown root:wheel $APP/bin/

Given the varieties in install, I generally either provide a
script in the local directory which does what I want, or do
something like the above. (Note, however, that the chown isn't
likely to work unless you're root.)

--
James Kanze (GABI Software) email:james...@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

James Kanze

unread,
Oct 7, 2008, 8:35:21 AM10/7/08
to
On Oct 6, 7:57 pm, puzzlecracker <ironsel2...@gmail.com> wrote:
> On Oct 6, 12:09 pm, viza <tom.v...@gm-il.com.obviouschange.invalid>
> wrote:
[...]

> Below is what has been added to the file:

> .SILENT: install

Why?

> install:
> echo "Installing Application..."; \
> if test ! -d $(APP_DIR); then \
> mkdir -p $(APP_DIR)/; \
> echo "Copying resources:"; \
> cp -f config_file_template $(APP_DIR); \
> echo "Rename config_file_template to config_file, and modify
> it appropriately." ; \
> cp -f start_app.sh $(APP_DIR)/; \
> echo "Use start_app.sh to start the application"; \
> fi; \

Don't you have a bit too much in the if? For that matter, the
if isn't really necessary: "mkdir -p" succeeds if the directory
is already present.

> if test -e $(PLATFORM)/$(APP); then \
> /bin/cp -f $(PLATFORM)/$(APP) $(APP_DIR)/ ; \
> else \
> echo $(APP) binary is missing; \
> fi; \
> echo Done

> What do you think about this solution?

Not knowing what your application needs, it's hard to judge.
For starters, I'd just do something like:

install: $(APP)
mkdir -p $(PREFIX)/bin
cp $(APP) $(PREFIX)/bin/$(APP)
chmod 644 $(PREFIX)/bin/$(APP)

This supposes only one version, of course. If you want to
maintain versions for several different platforms on the same
disk, you may want to split $(PREFIX) off into an $(EXEC_PREFIX)
and a $(SHARED_PREFIX).

toby

unread,
Oct 21, 2008, 12:44:45 AM10/21/08
to
On Oct 7, 8:22 am, James Kanze <james.ka...@gmail.com> wrote:
> On Oct 6, 6:09 pm, viza <tom.v...@gm-il.com.obviouschange.invalid>
> wrote:
>
> > On Mon, 06 Oct 2008 15:52:14 +0000, John Gordon wrote:
> > > puzzlecracker <ironsel2...@gmail.com> writes:
> > >> I have Makefile that build a pretty complex application. In
> > >> it,  have all: application  that builds application. Now  I
> > >> want  to add and option that user can type  'make install'
> > >> that will copy (and build if it hasn't been) to
> > >> $PLATFORM/application to  $APP/bin/
> > > From what you've said, adding this to your Makefile should work:
> > > install: application
> > >    cp $PLATFORM/application $APP/bin/.
> > Don't forget to add
> > .PHONY: install
> > so that make doesn't expect cp to generate a file called `install'.
>
> That's not really necessary.  It does protect you if someone
> accidentally creates a file named install, or from invoking the
> rule twice in any given run, but typically, these aren't real
> problems.

It's *unlikely* to be a real problem - but I prefer to include
a .PHONY declaration as it also adds to the Makefile's internal
documentation by clarifying intent.

This is more important if one is mixing phony and non-phony ('empty')
flag targets, which might otherwise be hard to distinguish without
carefully studying the rules.

> ...
> --
> James Kanze (GABI Software)             email:james.ka...@gmail.com

0 new messages