Last active
April 23, 2022 05:53
-
-
Save snim2/1419118 to your computer and use it in GitHub Desktop.
Makefile for multiple single file C programs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Minimal Makefile which compiles multiple C files into individual executables. | |
# | |
# | |
# - Sarah Mount, November 2011 | |
# | |
CC=gcc | |
RM=rm | |
CFLAGS=-c -Wall -O3 | |
LDFLAGS=-lm | |
SOURCES=$(wildcard *.c) | |
OBJECTS=$(SOURCES:.c=.o) | |
EXECS=$(SOURCES:%.c=%) | |
.PHONY: all | |
all: $(OBJECTS) $(EXECS) | |
.c.o: | |
$(CC) $(CFLAGS) $< -o $@ | |
.o.: | |
$(CC) $^ $(LDFLAGS) -o $@ | |
.PHONY: clean | |
clean: | |
-@ $(RM) *.o | |
-@ $(RM) $(EXECS) |
I'm trying to compile this project, but it's more complicated and I'm still getting better at writing makefiles. Do you think your makefile will help me compile it?
https://github.com/assaabloy-ppi/salt-channel-c/tree/master/examples
This Makefile is designed for situations where you have a number of .c
files and each of them needs to be compiled into a single executable, without any .h
files. It doesn't look like your code fits that model, so you would need to make some changes first.
Oh, I understand. So nothing else to embarrass with it. Well thank you
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great, this is exactly what I was looking for!