Reputation: 11
How do I add permissions to this simple make file?
all: shell ls cat groups
shell: shell.o cd.o
gcc shell.o cd.o -o shell
cat: cat.o
gcc -c cat.c -o cat
ls: ls.o header.h
gcc -c ls.c -o ls
groups: groups.o groups.h
gcc -c groups.c -o groups
shell.o: shell.c tlpi_hdr.h
gcc -c shell.c
cd.o: cd.c tlpi_hdr.h
gcc -c cd.c
cat.o: cat.c tlpi_hdr.h
gcc -c cat.c
ls.o: ls.c header.h
gcc -c ls.c
groups.o: groups.c groups.h
gcc -c groups.c
clean:
rm *.o shell cat ls groups
I need to run cat/ls/groups/cd within the shell that I created, but can't because it doesn't have permissions. How can I do this?
Upvotes: 0
Views: 815
Reputation: 753695
As an example, this rule:
groups: groups.o groups.h
gcc -c groups.c -o groups
tells GCC to produce an object file called groups
(instead of the normal groups.o
) because you included the -c
option. Object files are not executables, so the compiler doesn't make them executable, hence your problem with the permissions. Note that the rule requires make
to build groups.o
, but then proceeds to ignore the object file because it recompiles the source code.
You wanted to write something more like:
groups: groups.o
gcc groups.o -o groups
groups.o: groups.h
You need to use a lot more macros — or you could leave the rules out of the makefile since make
knows how to build groups
from groups.c
.
You should also be compiling with warning options. At minimum -Wall
; preferably -Wall -Wextra -Werror
(and I use still more options than these). You might want optimization (-O3
); you might want debugging (-g
). These are normally handled via setting macros and then using them in the commands.
Upvotes: 1