0% found this document useful (0 votes)
26 views

Make Files

The document describes the compilation process from source code files through various stages to produce an executable binary file. Source code files use extensions like .c and .h. They pass through a precompiler, assembler, and compiler to produce object files with a .o extension. The linker then links the object files together into a single executable binary file. The document also describes how to make the code more modular by splitting it across multiple source code files and using header files to include function prototypes. It shows how Makefiles can automate and simplify the build process across multiple source files.

Uploaded by

sbvhotkar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Make Files

The document describes the compilation process from source code files through various stages to produce an executable binary file. Source code files use extensions like .c and .h. They pass through a precompiler, assembler, and compiler to produce object files with a .o extension. The linker then links the object files together into a single executable binary file. The document also describes how to make the code more modular by splitting it across multiple source code files and using header files to include function prototypes. It shows how Makefiles can automate and simplify the build process across multiple source files.

Uploaded by

sbvhotkar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 6

The Compilation Process

.o

1110

.c

Precompiler

Assembler

.s

Compiler

.o

Linker

Straight substitution of # signs


08048fac <main>: 8048fac: 8048fad: 8048faf: 8048fb2: 8048fb3: 8048fb4: 8048fb5: 8048fb8: 8048fbb: 8048fc2: 8048fc9: 8048fcc: 8048fd1: 8048fd3: 8048fd8: 8048fdb: 55 89 83 57 56 53 8b 8b c7 c7 83 68 6a e8 83 68 push mov sub push push push 75 08 mov 5d 0c mov 45 f8 00 00 00 00 movl 45 f4 01 00 00 00 movl c4 f8 add 7c 8e 04 08 push 0b push 00 f7 ff ff call c4 f8 add 4c 8e 04 08 push e5 ec 1c %ebp %esp,%ebp $0x1c,%esp %edi %esi %ebx 0x8(%ebp),%esi 0xc(%ebp),%ebx $0x0,0xfffffff8(%ebp) $0x1,0xfffffff4(%ebp) $0xfffffff8,%esp $0x8048e7c $0xb 80486d8 <_init+0x70> $0xfffffff8,%esp $0x8048e4c

1010 .o 0110 1010 1110 0110 Final Executable Binary File

Making Code More Modular


Precompile info
#include <stdlib.h> #include <stdio.h> #define MAX_WORD_LEN 30 void print_menu (void); int insert (char **array, int *numwords, char *buf); int print_to_file (char **array, int numwords, char *file); int main (int argc, char *argv[]) { ... } void print_menu (void) { ... } int insert (char **array, int *numwords, char *buf) { ... }

Prototypes

Create a header file for each

Main Function

Leave in main .c file

Additional Functions

Place each in its own .c file

Making Code More Modular


labx.c
#include #include #include #include #define <stdlib.h> <stdio.h> print.h insert.h MAX_WORD_LEN 30

print.h
void print_menu (void); int print_to_file (char **array, int numwords, char *file);

insert.h
int insert (char **array, int *numwords, char *buf);

int main (int argc, char *argv[]) { ... }

print.c
void print_menu (void) { ... } int print_to_file (char **array, int numwords, char *file); { ... }

insert.c
int insert (char **array, int *numwords, char *buf) { ... }

Putting the Modules Together


labx.c

labx.o

print.c

print.o

LINKER

insert.o

insert.c

a.out

Confused??? Enter Makefiles


Located in the directory of your code Must be named Makefile Syntax:
Comments: #Put anything here Macros: CC = gcc CFLAGS = -Wall O pedantic o LabX.exe FILES = labx.c print.c insert.c --------------------------------------------$(CC) $(CFLAGS) $(FILES) Translates to gcc Wall O2 pedantic o LabX.exe labx.c print.c insert.c

Syntax cont.
Statements:
{name}: {dependency1 dependency2 } <tab> {command1} <tab> {command2} <tab>

all: is the default statement (run when just make is typed at the command line) cleanup: cleans up when there is an error make <name> will explicitly run the statement name

You might also like