🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
🪟 Windows TippsAnytype Announces Next-Generation Anytwo Platform(11.09.2026 um 21:27 Uhr)
⚠️ Malware / Trojaner / VirenWindows 11 just dropped the tool ransomware abused, Microsoft says don’t restore WMIC(10.09.2026 um 20:11 Uhr)
⚠️ Malware / Trojaner / VirenVorsicht: Android-Malware verschlüsselt Ihre Handys und nimmt heimlich Fotos auf(11.09.2026 um 09:35 Uhr)
🕵️ SicherheitslückenMicrosoft geht endlich eines der nervigsten Probleme von Windows 11 an(11.09.2026 um 11:58 Uhr)
💾 IT Security ToolsSysinternals Suite(11.09.2026 um 12:00 Uhr)
🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
🪟 Windows TippsAnytype Announces Next-Generation Anytwo Platform(11.09.2026 um 21:27 Uhr)
⚠️ Malware / Trojaner / VirenWindows 11 just dropped the tool ransomware abused, Microsoft says don’t restore WMIC(10.09.2026 um 20:11 Uhr)
⚠️ Malware / Trojaner / VirenVorsicht: Android-Malware verschlüsselt Ihre Handys und nimmt heimlich Fotos auf(11.09.2026 um 09:35 Uhr)
🕵️ SicherheitslückenMicrosoft geht endlich eines der nervigsten Probleme von Windows 11 an(11.09.2026 um 11:58 Uhr)
💾 IT Security ToolsSysinternals Suite(11.09.2026 um 12:00 Uhr)

🔧 Programmierung 🕛 vor 1 Jahr 3 Min Lesezeit
0

Makefile

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht




What is a Makefile?



A Makefile is a special file, traditionally named Makefile or makefile, that contains a set of rules to automate the building, testing, and deployment of projects. It is used with the make utility, a build automation tool that interprets these rules to execute tasks efficiently.









Why Use a Makefile?




  1. Automation: Simplify repetitive tasks like compiling code or running tests.


  2. Dependency Management: Ensure that only the necessary parts of your project are rebuilt, saving time.


  3. Portability: Share build instructions across team members to maintain consistency.


  4. Customizable: Define custom commands for deployment, cleaning, or other project-specific tasks.










Anatomy of a Makefile



A Makefile consists of targets, dependencies, and recipes:





  1. Target



    The target is the name of the task to be executed. It can represent a file to be created or a label for a custom task.




  2. Dependencies



    Dependencies are files or targets that must exist or be up-to-date before the target is executed.




  3. Recipe



    The recipe is the command or set of commands to execute. These commands must be indented with a tab (not spaces).





Basic Syntax:




CODE
target: dependencies
<TAB> command












Example



Directory Structure




CODE
project/
|-- main.c
|-- utils.c
|-- utils.h
|-- Makefile






Makefile




CODE
# Variables
CC = gcc
CFLAGS = -Wall -g

# Targets
all: program

program: main.o utils.o
$(CC) $(CFLAGS) -o program main.o utils.o

main.o: main.c utils.h
$(CC) $(CFLAGS) -c main.c

utils.o: utils.c utils.h
$(CC) $(CFLAGS) -c utils.c

clean:
rm -f *.o program








  • Variables:





    • CC: Compiler to use (e.g., gcc).


    • CFLAGS: Compiler flags like warnings (-Wall) and debugging (-g).








  • Targets:





    • all: Default target. It depends on program.


    • program: Builds the final executable using main.o and utils.o.


    • main.o and utils.o: Object files compiled from their respective .c files.


    • clean: A custom target to delete generated files.








  • Dependencies:





    • main.o depends on main.c and utils.h, so changes in these files will trigger a recompilation.








  • Commands:




    • Commands like gcc and rm are executed in the shell.














Features of Makefile




  1. Implicit Rules



Make can infer rules, so you don’t always need to specify them explicitly. For example, if you omit the main.o rule, make can deduce how to compile main.c into main.o.




  1. Phony Targets



Use .PHONY to define targets that don’t create files:




CODE
.PHONY: clean
clean:
rm -f *.o program







  1. Wildcards



Automate file selection with wildcards:




CODE
SRCS = $(wildcard *.c)
OBJS = $(SRCS:.c=.o)







  1. Conditional Statements



Add conditional logic:




CODE
ifeq ($(DEBUG), 1)
CFLAGS += -DDEBUG
endif


Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
The Gemini desktop app is now available for Windows
1 Quelle
Anytype Announces Next-Generation Anytwo Platform
1 Quelle
Windows 11 just dropped the tool ransomware abused, Microsoft says don’t restore WMIC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Makefile

Thematisch verwandte Begriffe: Makefile · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...