изучаю make

This commit is contained in:
2026-01-02 23:20:14 +05:00
parent caaf23399d
commit 0b1551edc5
5 changed files with 80 additions and 0 deletions

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "libraries/lwcell"]
path = libraries/lwcell
url = https://github.com/MaJerle/lwcell

1
libraries/lwcell Submodule

Submodule libraries/lwcell added at 422e7ab289

70
makefile Normal file
View File

@@ -0,0 +1,70 @@
CC = gcc
CFLAGS = -Wall -Wextra -std=c11
LIBRARIES= -L ./libraries/lwcell/build -l lwcell.so -lm
INCLUDES = -I ./source -I ./libraries/lwcell/include
# define variable for our dependencies' Makefiles.
# we use find to grab only the top level Makefiles and also some convenient ignores.
DEPENDENCIES = $(shell find ./deps -maxdepth 2 -name Makefile -printf '%h\n' | grep -v 'unittest' | grep -v '^.$$')
SOURCES = $(shell find ./source -name '*.c')
SRC = source
OBJ = objects
BIN = bin
TARGET = root
PREFIX ?= /usr/local
# Debug
ifeq ($(DEBUG), 1)
CFLAGS += -DDEBUG=1 -ggdb
endif
# Release
ifeq ($(RELEASE), 1)
CFLAGS += -O2
endif
# Shared
ifeq ($(SHARED), 1)
SOURCES=$(shell find ./$(SRC)/libraries -name '*.c')
TARGET=my_lib
endif
OBJECTS = $(addprefix $(OBJ)/,$(SOURCES:%.c=%.o))
.PHONY: all
all: dependencies source
.PHONY: dependencies
dependencies:
git -C ./libraries/lwcell pull
.PHONY: source
source: $(OBJECTS)
@mkdir -p $(BIN)
ifeq ($(SHARED), 1)
$(CC) -shared -fPIC -o $(BIN)/$(TARGET).so $^ $(LIBRARIES)
ar -rcs $(BIN)/$(TARGET).a $^
else
$(CC) $(CFLAGS) $(LIBRARIES) $^ -o $(BIN)/$(TARGET)
endif
# $(CC) -o $(TARGET) $(OBJECTS) $(CFLAGS)
$(OBJ)/%.o: %.c
@mkdir -p $(dir $@)
$(CC) -c -o $@ $< $(CFLAGS) $(INCLUDES)
.PHONY: clean
clean:
@rm -rf $(OBJ)/* 2> /dev/null
@rm -f $(BIN)/* 2> /dev/null
# .PHONY: install
# install:
# install $(TARGET) $(PREFIX)/bin
# .PHONY: uninstall
# uninstall:
# @rm -f $(PREFIX)/bin/$(TARGET) 2> /dev/null

6
source/main.c Normal file
View File

@@ -0,0 +1,6 @@
#include <stdio.h>
int main() {
printf("Hello World!\n");
return 0;
}

BIN
source/test Executable file

Binary file not shown.