commit 08bccaf7af2ac7db56a27da5ecf316072e6a4783 Author: Alexander Popov Date: Sun Jan 28 00:50:57 2024 +0300 Add Makefile diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..b0ba75a --- /dev/null +++ b/.editorconfig @@ -0,0 +1,20 @@ +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false + +[Makefile] +indent_style = tab +indent_size = 4 + +[{*.c,*.h,*.cpp,*.cc}] +indent_style = space +indent_size = 4 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f1b6bf8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +example_binary +*.o diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..fdddb29 --- /dev/null +++ b/LICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..24513c1 --- /dev/null +++ b/Makefile @@ -0,0 +1,48 @@ +# 2024 by Alexander Popov + +# Имя исполняемого файла +PROGRAM = example_binary + +# Компиляторы +CC = gcc +CXX = clang-16 + +# Флаги компиляции для исходных файлов C +CFLAGS = -O2 -Wall +# Флаги компиляции для исходных файлов C++ +CXXFLAGS = -std=c++17 -O2 -Wall +# Флаги для Си препроцессора (обычно включают пути к файлам и символы, определенные в командной строке), используемые C и C++ +CPPFLAGS = -g + +# Флаги компоновщика +LDFLAGS = -O2 -Wall -g + +# Библиотеки +LDLIBS = -lstdc++ + +# Файлы исходных кодов +SRC = lib.c main.cc +# Объектные файлы +OBJ = $(subst .cc,.o,$(SRC)) +OBJ := $(subst .c,.o,$(OBJ)) + +RM = rm -f + +# Правило по умолчанию +all: $(PROGRAM) + +# Сборка иисполняемого файла +$(PROGRAM): $(OBJ) + $(CXX) $(LDFLAGS) -o $@ $(OBJ) $(LDLIBS) + +# Сборка объектных файлов +lib.o: lib.c lib.h +main.o: main.cc lib.h + +# Очистка скомпилированных файлов +clean: + $(RM) $(OBJ) + +# Удаление программы +distclean: clean + $(RM) $(PROGRAM) diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/lib.c b/lib.c new file mode 100644 index 0000000..056cca2 --- /dev/null +++ b/lib.c @@ -0,0 +1,3 @@ +#include "lib.h" + +int calc_num(int a, int b) { return a + b; } diff --git a/lib.h b/lib.h new file mode 100644 index 0000000..6ab5169 --- /dev/null +++ b/lib.h @@ -0,0 +1,6 @@ +#ifndef LIB_H_ +#define LIB_H_ + +int calc_num(int a, int b); + +#endif // LIB_H_ diff --git a/main.cc b/main.cc new file mode 100644 index 0000000..ba6fe5b --- /dev/null +++ b/main.cc @@ -0,0 +1,17 @@ +#include + +extern "C" { +#include "lib.h" +} + +int main(int argc, char const *argv[]) { + int x, y, sum; + + x = 15; + y = 8; + sum = calc_num(x, y); + + std::cout << "Sum: " << sum << std::endl; + + return 0; +}