Demo static lib

This commit is contained in:
Imbus 2024-04-10 10:39:10 +02:00
parent ea34f7635b
commit 0eb4680c48
5 changed files with 51 additions and 3 deletions

1
libadd/add.c Normal file
View file

@ -0,0 +1 @@
int add(int a, int b) { return a + b; }

6
libadd/include/add.h Normal file
View file

@ -0,0 +1,6 @@
#ifndef ADD_H
#define ADD_H
int add(int a, int b);
#endif // ADD_H

34
libadd/makefile Normal file
View file

@ -0,0 +1,34 @@
# Makefile for the add library
# Builds a static library from the add.c file
# Library name
LIB = libadd.a
# Compiler
CC = gcc
# Compiler flags
CFLAGS = -Wall -Werror -Wextra -pedantic
CFLAGS += -std=c99 -O3
# Source file
SRC = add.c
# Object file
OBJ = $(SRC:.c=.o)
# Build the library
$(LIB): $(OBJ)
ar rcs $(LIB) $(OBJ)
# Build the object file
$(OBJ): $(SRC)
$(CC) $(CFLAGS) -c $(SRC)
format:
clang-format -i *.c include/*.h
# Clean the object files
clean:
rm -f $(OBJ)
rm -f $(LIB)