Last active
November 29, 2022 14:50
-
-
Save rahulgpt/0efb0fceaa43b10277595601c88eb954 to your computer and use it in GitHub Desktop.
Makefile to compile c files in the project with autovar.
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
CC = gcc | |
CFLAGS = -Wall | |
OBJDIR = out | |
SRCS = $(wildcard *.c */*.c) | |
OB = $(notdir $(patsubst %.c,%.o,$(SRCS))) | |
OBJS = $(addprefix $(OBJDIR)/,$(OB)) | |
all: main | |
# Check evaluated values | |
debug: | |
@echo 'SRCS: "$(SRCS)"' | |
@echo 'OB: "$(OB)"' | |
@echo 'OBJS: "$(OBJS)"' | |
main: $(OBJS) | |
$(CC) $(CFLAGS) -o $@ $^ | |
# Compile with static lib | |
# main: main.o libex.a | |
# $(CC) $(CFLAGS) -o $@ $^ -L. -lex | |
*/%.o: %.c | |
$(CC) $(CFLAGS) -c -o $@ $< | |
*/%.o: */%.c | |
$(CC) $(CFLAGS) -c -o $@ $< | |
libex.a: $(OBJS) | |
ar -rcs libex.a $^ | |
.PHONY: clean all | |
clean: | |
rm -rf *.o */*.o main libex.a | |
# Change libex to your lib name | |
# Use debug rule to check the eval values | |
# Compile all of the o files into a static lib with "libex.a" rule | |
# Compile all of the c files into out with the "all" rule |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment