mbcrawfo / GenericMakefile

A generic makefile for use with small/medium C and C++ projects.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compile multiple executables

mspiropali opened this issue · comments

Hello, is there anyway i can extend your makefile to compile multiple executables in the src directory using shared code?
i.e
src
-->main1.c
-->main2.c
-->tool
---------->tool.c
----------->tool.h
after compiling we get main1 & main2 executables.

I think it should be possible. If you find the rule commented 'Link the executable', you'll need to make a copy of that rule for each executable. The rule all would then need to be updated to depend on each executable and make symlinks for them. The hard part will be filtering the object files during linking so that you don't get errors because of multiple main functions. For example the rule that links the program in main1.o needs to exclude main2.o. I don't know offhand if make has an easy syntax to say $(OBJECTS) exclude main.o. I suppose you could always use grep -v.