Demo static lib
This commit is contained in:
parent
ea34f7635b
commit
0eb4680c48
5 changed files with 51 additions and 3 deletions
1
libadd/add.c
Normal file
1
libadd/add.c
Normal file
|
@ -0,0 +1 @@
|
||||||
|
int add(int a, int b) { return a + b; }
|
6
libadd/include/add.h
Normal file
6
libadd/include/add.h
Normal 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
34
libadd/makefile
Normal 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)
|
9
makefile
9
makefile
|
@ -1,4 +1,4 @@
|
||||||
# Compiler and assembler
|
#dd Compiler and assembler
|
||||||
CC = gcc
|
CC = gcc
|
||||||
AS = as
|
AS = as
|
||||||
LD = ld
|
LD = ld
|
||||||
|
@ -20,6 +20,7 @@ CFLAGS += -Wno-unused-local-typedefs
|
||||||
CFLAGS += -Wno-unused-const-variable
|
CFLAGS += -Wno-unused-const-variable
|
||||||
CFLAGS += -Wno-unused-macros
|
CFLAGS += -Wno-unused-macros
|
||||||
CFLAGS += -O3
|
CFLAGS += -O3
|
||||||
|
CFLAGS += -Ilibadd/include
|
||||||
CFLAGS += -g
|
CFLAGS += -g
|
||||||
|
|
||||||
GITHASH = $(shell git rev-parse --short HEAD)
|
GITHASH = $(shell git rev-parse --short HEAD)
|
||||||
|
@ -36,6 +37,9 @@ OBJS := $(patsubst src/%.c,build/%.o,$(SRCS))
|
||||||
|
|
||||||
all: $(TARGET)
|
all: $(TARGET)
|
||||||
|
|
||||||
|
libadd/libadd.a:
|
||||||
|
$(MAKE) -C libadd
|
||||||
|
|
||||||
# For convenience
|
# For convenience
|
||||||
run: $(TARGET)
|
run: $(TARGET)
|
||||||
@./$(TARGET)
|
@./$(TARGET)
|
||||||
|
@ -45,7 +49,7 @@ mkbuilddir:
|
||||||
@mkdir -p build
|
@mkdir -p build
|
||||||
|
|
||||||
# Link the object files into the target binary
|
# Link the object files into the target binary
|
||||||
$(TARGET): $(OBJS)
|
$(TARGET): $(OBJS) libadd/libadd.a
|
||||||
@$(CC) $(CFLAGS) -o $@ $^
|
@$(CC) $(CFLAGS) -o $@ $^
|
||||||
@echo -e "LD \t$^"
|
@echo -e "LD \t$^"
|
||||||
|
|
||||||
|
@ -67,6 +71,7 @@ clean:
|
||||||
rm -r build
|
rm -r build
|
||||||
rm -f build/*.o
|
rm -f build/*.o
|
||||||
rm -f $(TARGET)*
|
rm -f $(TARGET)*
|
||||||
|
$(MAKE) -C libadd clean --no-print-directory
|
||||||
|
|
||||||
# Create a signed release
|
# Create a signed release
|
||||||
tar: $(TARGET_TAR)
|
tar: $(TARGET_TAR)
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
#include <add.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int main(int argc, const char **argv) {
|
int main(int argc, const char **argv) {
|
||||||
printf("Hello, World!\n");
|
printf("Hello, World!\n");
|
||||||
|
printf("add(1, 2) = %d\n", add(1, 2));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue