need help with makefile - Unix

This is a discussion on need help with makefile - Unix ; 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 ...

+ Reply to Thread
Results 1 to 9 of 9

Thread: need help with makefile

  1. need help with makefile

    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

  2. Re: need help with makefile

    In <8a40973a-dd5b-4ca6-b5d3-59d794146200@i76g2000hsf.googlegroups.com> puzzlecracker 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/


    > 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
    gordon@panix.com B is for Basil, assaulted by bears
    -- Edward Gorey, "The Gashlycrumb Tinies"


  3. Re: need help with makefile

    On Mon, 06 Oct 2008 15:52:14 +0000, John Gordon wrote:
    > puzzlecracker 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/

  4. Re: need help with makefile

    On Oct 6, 12:09*pm, viza
    wrote:
    > On Mon, 06 Oct 2008 15:52:14 +0000, John Gordon wrote:
    > > puzzlecracker 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/


    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?

  5. Re: need help with makefile

    puzzlecracker writes:

    > On Oct 6, 12:09*pm, viza
    > wrote:
    >> On Mon, 06 Oct 2008 15:52:14 +0000, John Gordon wrote:
    >> > puzzlecracker 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/

    >
    > 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?


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

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

  6. Re: need help with makefile

    On Oct 6, 1:57 pm, puzzlecracker wrote:
    > On Oct 6, 12:09 pm, viza
    > wrote:
    >
    >
    >
    > > On Mon, 06 Oct 2008 15:52:14 +0000, John Gordon wrote:
    > > > puzzlecracker 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 buildif
    > > >> 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/

    >
    > Well, here is my solution that i discovered by googling for sample
    > Makefile:
    >
    > Below is what has been added to the file:
    >
    > .SILENT: install
    >


    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.


    > echo Done
    >
    > What do you think about this solution?



  7. Re: need help with makefile

    On Oct 6, 6:09 pm, viza
    wrote:
    > On Mon, 06 Oct 2008 15:52:14 +0000, John Gordon wrote:
    > > puzzlecracker 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.kanze@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

  8. Re: need help with makefile

    On Oct 6, 7:57 pm, puzzlecracker wrote:
    > On Oct 6, 12:09 pm, viza
    > 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).

    --
    James Kanze (GABI Software) email:james.kanze@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

  9. Re: need help with makefile

    On Oct 7, 8:22*am, James Kanze wrote:
    > On Oct 6, 6:09 pm, viza
    > wrote:
    >
    > > On Mon, 06 Oct 2008 15:52:14 +0000, John Gordon wrote:
    > > > puzzlecracker 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
    > 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



+ Reply to Thread