Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # C Standard MakeFile for Small Static Libraries and Project:To use with:1) Linux: sudo apt install make make clean make all2) windows # scoop install make make clean make all
- CC=gcc
- AR=ar
- AR_FLAGS=rcs
- SRC_DIR=src
- INCLUDE_DIR=include
- CFLAGS= -Wall -Wextra -Wpedantic -I$(INCLUDE_DIR) -MMD -std=c99 -lm
- # Use wildcard to find all .c files
- # in the SRC_DIR
- SOURCES := $(wildcard $(SRC_DIR)/*.c)
- OBJ_DIR=obj
- # Alternative syntax to generate object file
- # names from source file names
- OBJECTS := $(SOURCES:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
- DEPS_DIR=./deps
- # Include dependency files
- # generated by -MMD flag.
- DEPSFILES := $(OBJECTS:.o=.d)
- LIB_DIR=lib
- LIB=$(LIB_DIR)/libstencil.a
- all: $(LIB)
- # Include the dependency files
- -include $(DEPSFILES)
- $(LIB): $(OBJECTS)
- mkdir -p $(LIB_DIR)
- $(AR) $(AR_FLAGS) $@ $(OBJECTS)
- # Pattern rule to generate object files
- # from source files
- $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
- mkdir -p $(OBJ_DIR)
- $(CC) $(CFLAGS) -c $< -o $@
- clean:
- rm -rf $(OBJ_DIR) $(LIB_DIR)
- .PHONY: all clean
- # Move the dependency files after object files are created
- post-build:
- mkdir -p $(DEPS_DIR)
- mv $(DEPSFILES) $(DEPS_DIR)
- # Ensure that 'post-build' is run after the
- # library is built
- $(LIB): post-build
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement