Add Makefile

This commit is contained in:
Alexander Popov 2024-01-28 00:50:57 +03:00
commit 08bccaf7af
Signed by: iiiypuk
GPG Key ID: E47FE0AB36CD5ED6
8 changed files with 120 additions and 0 deletions

20
.editorconfig Normal file
View File

@ -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

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
example_binary
*.o

24
LICENSE Normal file
View File

@ -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 <https://unlicense.org>

48
Makefile Normal file
View File

@ -0,0 +1,48 @@
# 2024 by Alexander Popov <iiiypuk@fastmail.fm>
# Имя исполняемого файла
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)

0
README.md Normal file
View File

3
lib.c Normal file
View File

@ -0,0 +1,3 @@
#include "lib.h"
int calc_num(int a, int b) { return a + b; }

6
lib.h Normal file
View File

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

17
main.cc Normal file
View File

@ -0,0 +1,17 @@
#include <iostream>
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;
}