Skip to content

Commit

Permalink
Simple scheme for installation targets
Browse files Browse the repository at this point in the history
- each directory has now INSTALL_BIN/LIB/DOC variables where you can
  specify which targets from this directory should be marked for
  installation
- there is now an option to add at the top level file 'final.mk' which
  will be included after all rules are read and processed - you can use
  there all variables which are defined in the project (examples show
  how this file can be used for specifying installation targets).
  • Loading branch information
aostruszka committed May 16, 2012
1 parent 8d24b0c commit 6a1ae99
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ include $(MK)/header.mk
include $(TOP)/Rules.top
include $(MK)/footer.mk

# Optional final makefile where you can specify additional targets
-include $(TOP)/final.mk

# This is just a convenience - to let you know when make has stopped
# interpreting make files and started their execution.
$(info Rules generated...)
2 changes: 2 additions & 0 deletions ex1/Dir_1/Rules.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
TARGETS := dir1_lib.a
SUBDIRS := Dir_1a Dir_1b

INSTALL_LIB := $(TARGETS)

dir1_lib.a_DEPS = dir_1_file1.o dir_1_file2.o dir_1_file3.o $(SUBDIRS_TGTS)
2 changes: 2 additions & 0 deletions ex1/Dir_2/Rules.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
TARGETS := dir2_lib.a
SUBDIRS := Dir_2a Dir_2b Dir_ex

INSTALL_LIB := $(TARGETS)

dir2_lib.a_DEPS = dir_2_file1.o dir_2_file2.o \
$(TARGETS_$(d)/Dir_2a) $(TARGETS_$(d)/Dir_2b)
2 changes: 2 additions & 0 deletions ex1/Dir_3/Rules.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
TARGETS := libdir3.$(SOEXT)

INSTALL_LIB := $(TARGETS)

libdir3.$(SOEXT)_DEPS := dir_3_file1.o dir_3_file2.o

# You should not forget about that when you create shared library
Expand Down
1 change: 1 addition & 0 deletions ex1/Readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some documentation that needs to be installed for ex1
3 changes: 3 additions & 0 deletions ex1/Rules.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
TARGETS := app.exe cli.exe
SUBDIRS := Dir_1 Dir_2 Dir_3

INSTALL_BIN := $(TARGETS)
INSTALL_DOC := Readme.txt

app.exe_DEPS = top_a.o top_b.o main.o $(SUBDIRS_TGTS)
app.exe_LIBS = -lm
# Let's use DEFAULT_MAKECMD for app.exe
Expand Down
30 changes: 30 additions & 0 deletions ex1/final.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Just a simple example how final.mk can be used for 'install' targets
# You can refer here to any variable defined in the project tree since
# it is included after all rules has been read and processed.
#
# Variables of particular interest:
# INSTALL_BIN_$(dir) - binaries to be installed from directory 'dir'
# INSTALL_LIB_$(dir) - same for libraries
# INSTALL_DOC_$(dir) - and for documentation

BIN_DIR := /tmp/test-ex1/bin
LIB_DIR := /tmp/test-ex1/lib
DOC_DIR := /tmp/test-ex1/share/doc/ex1

INSTALL := install
INSTALL_DATA := install -m 644

install: install-bin install-lib install-doc

install-bin : $(call get_subtree,INSTALL_BIN,$(TOP))
$(INSTALL) -d $(BIN_DIR)
$(INSTALL) -t $(BIN_DIR) $^

install-lib : $(call get_subtree,INSTALL_LIB,$(TOP))
$(INSTALL) -d $(LIB_DIR)
$(INSTALL) -t $(LIB_DIR) $(filter-out %.a,$^)
$(INSTALL) -t $(LIB_DIR) -m 644 $(filter %.a,$^)

install-doc: $(call get_subtree,INSTALL_DOC,$(TOP))
$(INSTALL) -d $(DOC_DIR)
$(INSTALL_DATA) -t $(DOC_DIR) $^
11 changes: 11 additions & 0 deletions mk/footer.mk
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ else
TARGETS_$(d) := $(OBJS_$(d))
endif

INSTALL_BIN_$(d) := $(addprefix $(OBJPATH)/,$(INSTALL_BIN))
INSTALL_LIB_$(d) := $(addprefix $(OBJPATH)/,$(INSTALL_LIB))
# Documentation is a bit special since it usually is not generated and
# if it is then most probably not in OBJDIR so I'm prefixing it with
# current directory iff it is not absolute path
INSTALL_DOC_$(d) := $(filter /%,$(INSTALL_DOC)) $(addprefix $(d)/,$(filter-out /%,$(INSTALL_DOC)))

########################################################################
# Inclusion of subdirectories rules - only after this line one can #
# refer to subdirectory targets and so on. #
########################################################################
$(foreach sd,$(SUBDIRS),$(eval $(call include_subdir_rules,$(sd))))

.PHONY: dir_$(d) clean_$(d) clean_extra_$(d) clean_tree_$(d) dist_clean_$(d)
Expand Down
4 changes: 4 additions & 0 deletions mk/header.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ OBJS :=
CLEAN :=
TARGETS :=
SUBDIRS :=

INSTALL_BIN :=
INSTALL_LIB :=
INSTALL_DOC :=

0 comments on commit 6a1ae99

Please sign in to comment.