Skip to content

Commit

Permalink
README: added info about the -I makefile flag.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuno-Jesus committed Jul 31, 2023
1 parent 7a058f0 commit e95e64d
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,11 @@ As told before, implicit rules rely on variables already known by the Makefile,
<td><code>make</code></td>
<td>Useful when multi-jobs of Makefile come into play. This will be explained later in detail in an upcoming section, but keep in mind this is the best way of calling make targets inside the Makefile</td>
</tr>
<tr>
<td><code>MAKEFLAGS</code></td>
<td><code></code></td>
<td>The flags given to make.</td>
</tr>
</tbody>
</table>

Expand Down Expand Up @@ -1284,6 +1289,23 @@ cc main.c hello/hello.c
<strong><a href="#index-0">🚀 Go back to top 🚀</a></strong>
</div>

- `-I <dir>` - specifies a directory to search for included Makefiles. Useful to prevent building the path to the dependencies. You can find an example of this in the [code/13-I-flag-example](/code/13-I-flag-example).

```shell
13-I-flag-example git:(advanced-topics) ✗ make
Makefile:18: main.d: No such file or directory
make: *** No rule to make target 'main.d'. Stop.
13-I-flag-example git:(advanced-topics) ✗ make -I teste
cc -Wall -Werror -Wextra -c -o main.o main.c
cc -Wall -Werror -Wextra main.o -o a.out
13-I-flag-example git:(advanced-topics) ✗
```

<div align=center>
<strong><a href="#index-0">🚀 Go back to top 🚀</a></strong>
</div>
<br>


------------------------------------------------------------------

Expand Down
27 changes: 27 additions & 0 deletions code/13-I-flag-example/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
####################### Compilation ######################
CC = cc
CFLAGS = -Wall -Werror -Wextra

######################## Commands #######################
RM = rm -rf

######################### Files #########################
NAME = a.out
OBJS = main.o

all: $(NAME)

$(NAME): $(OBJS)
$(CC) $(CFLAGS) $(OBJS) -o $(NAME)

#Try to eliminate main.d from teste folder and run make again
include main.d

clean:
$(RM) $(OBJS)

fclean: clean
$(RM) $(NAME)

re: fclean
$(MAKE) all
19 changes: 19 additions & 0 deletions code/13-I-flag-example/header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* a.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: marvin <marvin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/30 19:02:29 by marvin #+# #+# */
/* Updated: 2023/07/30 19:02:29 by marvin ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef HEADER_H
# define HEADER_H
# include <stdio.h>

# define NUMBER 42

#endif
19 changes: 19 additions & 0 deletions code/13-I-flag-example/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: marvin <marvin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/01 21:43:38 by ncarvalh #+# #+# */
/* Updated: 2023/07/30 19:31:37 by marvin ### ########.fr */
/* */
/* ************************************************************************** */

#include "header.h"

int main()
{
printf("This is the number: %d\n", NUMBER);
return 0;
}
File renamed without changes.

0 comments on commit e95e64d

Please sign in to comment.