Skip to content

Commit

Permalink
Allow building programs in a different directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmsc committed Apr 23, 2024
1 parent 323186c commit 9fc7263
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
# with this program. If not, see <http://www.gnu.org/licenses/>
#

# Folder to place compiled programs
PROG_DIR=.

# Folder to place the build files
BUILD_DIR=obj


PROGS=\
mkatr\
lsatr\
Expand All @@ -40,10 +47,8 @@ SOURCES_lsatr=\
CFLAGS=-O2 -Wall
LDFLAGS=

BUILD_DIR=obj

# Default rule
all: $(PROGS)
all: $(PROGS:%=$(PROG_DIR)/%)

# Rule template
define PROG_template
Expand All @@ -53,7 +58,7 @@ define PROG_template
SOURCES+=$$(SOURCES_$(1))
OBJS+=$$(OBJS_$(1))
# Link rule
$(1): $$(OBJS_$(1))
$(PROG_DIR)/$(1): $$(OBJS_$(1))
$$(CC) $$(CFLAGS) $$(LDFLAGS) $$^ $$(LDLIBS) -o $$@
endef

Expand All @@ -70,7 +75,7 @@ clean:

.PHONY: distclean
distclean: clean
-rm -f $(PROGS)
-rm -f $(PROGS:%=$(PROG_DIR)/%)

# Create output dirs
$(BUILD_DIR):
Expand Down

0 comments on commit 9fc7263

Please sign in to comment.