Program as a single file

Program created as five s eparate files

Compile as one file and execute

Compile each file separately to create four object files, then link into an executable

Use a shell script to compile each file separately

makefile to compile and link, long version

main.o: main.c myinclude.h
gcc -c main.c

input.o: input.c myinclude.h
gcc -c input.c

factorial.o: factorial.c myinclude.h
$(CC) -c factorial.c

output.o: output.c myinclude.h
$(CC) -c output.c
clean:
-rm -f *.o testfac core
all:
gcc -c main.c input.c factorial.c output.c
gcc main.o input.o factorial.o output.o -o testfac

makefile to compile and link

cis-lclient20:~/2012/c/make>more makefile

OBJ = main.o input.o factorial.o output.o
SOURCE = main.c input.c factorial.c output.c
CC = gcc
testfac: ${OBJ}
${CC} -o $@ ${OBJ}

main.o: myinclude.h

input.o: myinclude.h

factorial.o: myinclude.h

output.o: myinclude.h

clean:
-rm -f *.o testfac core
all:
gcc -c ${SOURCE}
gcc -o testfac ${OBJ}
cis-lclient20:~/2012/c/make>

Executing the makefile

cis-lclient20:~/2012/c/make>make clean
rm -f *.o testfac core
cis-lclient20:~/2012/c/make>make
gcc -c -o main.o main.c
gcc -c -o input.o input.c
gcc -c -o factorial.o factorial.c
gcc -c -o output.o output.c
gcc -o testfac main.o input.o factorial.o output.o
cis-lclient20:~/2012/c/make>make
make: `testfac' is up to date.
cis-lclient20:~/2012/c/make>testfac
input a number - 5
The length of f is 1
The factorial is 120

Change char to long long