Jump to content

Creating Makefiles in Linux for installing programs

- - - - -

  • Please log in to reply
2 replies to this topic

#1
uniquerockrz

uniquerockrz

    Newbie

  • Members
  • Pip
  • 1 posts
I have written a console program in C named main.c.

I want to turn it into an application, so that using a Makefile and 'make' and 'make install' commands one is able to install that in his/her computer.

Any ideas how to do that? I have searched tutorials for making the Makefile but they just tell me the way to compile the source files, not "install" them.

PS, I use Fedora 15 and Code::Blocks Ide, if that is of any help.

PPS : I have seen that copying the executable produced by gcc to /usr/bin directory does has the same result as installing. Is that what 'make install' command does?

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Installing a program on *nix involves copying the compiled files to specific locations with specific permissions. How much do you know about the file system on *nix?

In response to your PPS: basically, yes.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
A make file can reduce the need for multiple scripts to configure, compile, test, install, and possibly uninstall programs. There is no need to have a compiling step, or to use a make file all together if you have no need for one.

Within your make install: directive (within Makefile) or in a shell script you can easily have the following:
prefix=/usr/local
    
    install: somebinary
        install -m 0755 somebinary $(prefix)/bin
        ...
    
    .PHONY: install

The install program being the key executable to set permissions and do the copy in more safe manner.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users