close
Skip to content

Update makefile#299

Open
Nikita-Presnov wants to merge 1 commit intohufrea:mainfrom
Nikita-Presnov:makefileupdate
Open

Update makefile#299
Nikita-Presnov wants to merge 1 commit intohufrea:mainfrom
Nikita-Presnov:makefileupdate

Conversation

@Nikita-Presnov
Copy link
Copy Markdown

@Nikita-Presnov Nikita-Presnov commented Jun 18, 2025

Более совершенный мейкфайл для прокта, который

  • кидает двоичные файлы в отельную папочку
  • пересобирает проект приизменении хедеров
  • добавлена команда uninstall
  • в перспективе может подбирать файлы автоматически

Сам файл изначально писался для прошивок микроконтроллеров, но был адаптирован для консольных улит без зависимостей

Хотя я всё же счтаю что cmake был бы целесообразнее

Comment thread Makefile
CP = $(TOOLCHAIN_PATH)/objcopy
SZ = $(TOOLCHAIN_PATH)/size -d -G
else
CC = gcc
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Классно. А как свой компилятор задать?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 TOOLCHAIN_PATH же
2 перезалью

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TOOLCHAIN_PATH не поможет с clang

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Мммм, шланг
ок, сделаем

@dartvader316
Copy link
Copy Markdown
Contributor

Just my opinion:

  1. Too much GNU Make only constructs like wildcards, addprefix, vpath, etc... They are not part of POSIX Make and will break BSD make.
  2. The Makefile itself looks like it was poorly copied from some C++ project because there too much unnecessary C++ constructs.
  3. Dedicated build folder is matter of taste, although i can try to add support for it if necessary.
  4. TOOLCHAIN_PATH is useless when you can just use CC=/usr/local/bin/clang make or make CC=/usr/local/bin/clang, for example.

@Nikita-Presnov
Copy link
Copy Markdown
Author

1. Too much GNU Make only constructs like wildcards, addprefix, vpath, etc... They are not part of [POSIX Make](https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/utilities/make.html) and will break BSD make.

It works also with mingw-make. But I understood.

2. The Makefile itself looks like it was poorly copied from some C++ project because there too much unnecessary C++ constructs.

Where? I created in for C. Looks like chicane.

3. Dedicated build folder is matter of taste, although i can try to add support for it if necessary.

Yes. And I think this matters more than the style of the makefile code for a small project.

Also, the version relevant for the project is not rebuilt when the headers are changed, this is what this implementation was made for. But it seems there is a simpler way. Perhaps I was then solving a number of other problems.

objects := build/main.o build/bla.o

build/app: $(objects)
  $(CC) -o $@ $^

build/%.o: src/%.c
  $(CC) $(CFLAGS) -MMD -c -o $@ $<

-include $(objects:%.o=%.d)
4. TOOLCHAIN_PATH is useless when you can just use `CC=/usr/local/bin/clang make` or  `make CC=/usr/local/bin/clang`, for example.

Understood.

@dartvader316
Copy link
Copy Markdown
Contributor

It works also with mingw-make

Mingw is literally port of GNU tools for Windows.

Where? I created in for C. Looks like chicane.

Line 34 defines macro with C++ compiler, CXX prefix from CXX_FILES usually used to refer to C++, LFLAGS even being commented defines options that are not relevant to the project.

Also, the version relevant for the project is not rebuilt when the headers are changed, this is what this implementation was made for.

It does rebuild on headers change. Current Makefile in Line 25 defines header files as dependency for object files, so makefile should rebuild everything when their modification time is newer than others.
This is reproducible for me:
screenshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants