LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-03-2011, 05:48 AM   #1
spiros
LQ Newbie
 
Registered: Jun 2011
Location: Greece
Distribution: Xubuntu
Posts: 2

Rep: Reputation: Disabled
make install error with Makefile I created


hi everybody,

I am new to Linux and I am trying to install a C program from source using Makefile. So I 've created a "hello world" program and then a Makefile to install it. Then I logged in as root and used
make install

The following error occurs:
make: execvp: /usr/bin: Permission denied
make: *** [install] Error 127

here is the Makefile:

CC=gcc
CFLAGS=-c -Wall
PROGS = hello
INSTDIR = $(prefix)/usr/bin/
INSTMODE = 0755
INSTOWNER = root
INSTGROUP = root

all: $(PROGS)

$(PROGS): main.o
$(CC) main.o

main.o: main.c
$(CC) $(CFLAGS) main.c

install: $(PROGS)
$(INSTALL) $(INSTDIR)
$(INSTALL) $(INSTMODE) $(INSTOWNER) -o $(INSTGROUP) $(PROGS) $(INSTDIR)

clean:
rm -rf $(PROGS) *o $(PROGS)

--So, where are the errors

Thank you in advance,
Spiros
 
Old 06-03-2011, 06:23 AM   #2
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
I suspect that
Code:
INSTDIR = $(prefix)/usr/bin/
is giving you a problem (the $(prefix) appears undefined and the trailing / doesn't need to be there).

Here's a Makefile that does it all that may help
Code:
MAKEFILE =      Makefile

# We use ${HOME}, you can use /usr, /usr/local, etc. Note ${BINDIR} below
BASDIR  =       ${HOME}

LDFLAGS =       -lm

OWNER   =       ${LOGNAME}

GROUP   =       ${GRPNAME}

BINDIR  =       $(BASDIR)/bin

BMASK   =       0755

MAINS   =       sample

OBJECTS =       caldat.o julday.o sample.o

SOURCES =       caldat.c julday.c sample.c

ALL:            $(MAINS)

sample:         sample.o caldat.o julday.o $(LIBRARY)
        $(CC) $(CFLAGS) -s -o sample sample.o caldat.o julday.o $(LDFLAGS)


caldat.o:

julday.o:

sample.o:

install:        $(MAINS)
        cp $(MAINS) $(BINDIR)
        cd $(BINDIR);\
        chown $(OWNER) $(MAINS);\
        chgrp $(GROUP) $(MAINS);\
        chmod $(BMASK) $(MAINS)

remove:
        cd $(BINDIR);\
        rm -f $(MAINS)

clean:
        rm -f $(OBJECTS)

clobber:
        rm -f $(OBJECTS) $(MAINS)
The above follows the AT&T Bell Labs method.

Note that this consturct
Code:
$(CC) $(CFLAGS) -s -o
"strips" information from the executable (makes it smaller); a reasonable thing to do if you're not using profiling or debugging -- and don't do it if you are using either of those.

By the way, it's helpful if you enclose code samples in code blocks (easier to read).

Hope this helps some.

Last edited by tronayne; 06-03-2011 at 06:28 AM.
 
1 members found this post helpful.
Old 06-03-2011, 09:54 AM   #3
spiros
LQ Newbie
 
Registered: Jun 2011
Location: Greece
Distribution: Xubuntu
Posts: 2

Original Poster
Rep: Reputation: Disabled
Smile Problem solved !

I modified the code given by tronayne and it works ! The user can now use make install from within the directory containing the source code and the Makefile and after installation, all the mess can be cleaned up using make remove and make clean or make clobber.

Many thanks to user tronayne !!!

Here is my new Makefile:


MAKEFILE = Makefile


CC=gcc
CFLAGS = -c -Wall
LDFLAGS = -lm

OWNER = root
GROUP = root
BMASK = 0755

MAINS = hello123 #binary name
SOURCEDIR = ${PWD}
TARGETDIR = /usr/bin

OBJECTS = main.o
SOURCES = main.c

ALL: $(MAINS)

hello123: main.o $(LIBRARY)
$(CC) -o hello123 main.o $(LDFLAGS)

main.o:

install: $(MAINS)
cd /
cp $(SOURCEDIR)/$(MAINS) $(TARGETDIR)
cd /usr/bin;\
chown $(OWNER) $(MAINS);\
chgrp $(GROUP) $(MAINS);\
chmod $(BMASK) $(MAINS)
remove:
cd $(SOURCEDIR);\
rm -f $(MAINS)
clean:
rm -f $(OBJECTS)
clobber:
rm -f $(OBJECTS) $(MAINS)
 
Old 06-03-2011, 11:37 AM   #4
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
Glad to know it helped.

One comment: in your Makefile you have
Code:
remove:
cd $(SOURCEDIR);\
rm -f $(MAINS)
remove is meant to remove an installed executable from $(BINDIR) (you occasionally may want to do that); it's analogous to make uninstall.

The clobber directive is meant to remove both the object and executable file(s) create by make -- idea being to keep your source code directory size to a minimum.

Just a thought.

Last edited by tronayne; 06-03-2011 at 11:42 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
make: *** [Makefile.in] Error 1 mghorbani Linux - Desktop 6 10-11-2018 07:07 PM
Make-3.82 error:Makefile:282:error: mixed implicit and normal rules Ramanc51 Linux - Newbie 5 06-08-2011 07:55 AM
Makefile error : make recursively loops Venomal Linux - Newbie 2 09-16-2009 01:42 PM
Error in Makefile:No rule to make target `g++',needed by... stop karthik.c Programming 5 03-09-2009 12:55 AM
tinkering with dkms: make error no targets. Makefile issue? Emmanuel_uk Linux - Newbie 1 06-03-2005 01:26 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration