diff --git a/doc/index.rst b/doc/index.rst index bd66056..064669b 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -12,6 +12,5 @@ Welcome to a lesson about `make`! motivation.md rules.md - other_makefiles.md exercise.md resources.md diff --git a/doc/other_makefiles.md b/doc/other_makefiles.md deleted file mode 100644 index 50ff60f..0000000 --- a/doc/other_makefiles.md +++ /dev/null @@ -1,90 +0,0 @@ -# Separating Source and Binary - -A makefile separating source and binary that can be executed from the source tree: -```makefile -SOURCE_DIR:=/test/source_dir/examples/separate-binaries -BINARY_DIR:=/test/binary_dir/mp3_player_out - -#$(call source-dir-to-binary-dir, directory-list) -source-dir-to-binary-dir = $(addprefix $(BINARY_DIR)/, $1) - -#$(call source-to-object, source-file-list) -source-to-object = $(call source-dir-to-binary-dir, \ - $(subst .c, .o,$(filter %.c,$1) - -#$(subdirectory) -subdirectory = $(patsubst %/module.mk,%, \ - $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))) - -#$(call make-library, library-name, source-file-list) -define make-library - libraries += $(BINARY_DIR)/$1 - sources += $2 - -$(BINARY_DIR)/$1: $(call source-dir-to-binary-dir, \ - $(subst .c,.o,$(filter %c,$2)) - $(AR) $(ARFLAGS) $$@ $$^ -endef - -# $(call generated-source, source-file-list) -generated-source = $(filter %.c, $1) - -# $(compile-rules) -define compile-rules - $(foreach f, $(local_src),\ - $(call one-compile-rule,$(call source-to-object,$f),$f)) -endef - -# $(call one-compile-rule, binary-file, source-files) -define one-compile-rule - $1: $(call generated-source,$2) - $(COMPILE.c) -o $$@ $$< - - $(subst .o,.d,$1): $(call generated-source,$2) - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -M $$< | \ - $(SED) 's,\($$(notdir $$*)\.o\) *:,$$(dir $$@)\1 $$@: ,' > $$@.tmp - $(MV) $$@.tmp $$@ -endef - -modules := lib/codec lib/db lib/ui app/player -programs := -libraries := -sources := - -objects = $(call source-to-object,$(sources)) -dependencies = $(subst .o,.d,$(objects)) - -include_dirs := $(BINARY_DIRS)/lib lib include -CPPFLAGS += $(addprefix -I, $(include_dirs)) -vpath %.h $(include_dirs) - -MKDIR := mkdir -p -MV := mv -f -RM := rm -f -SED := sed -TEST := test - -create-output-directories := \ - $(shell for f in $(call source-dir-to-binary-dir,$(modules)); \ - do \ - $(TEST) -d $$f || $(MKDIR) $$f; \ - done) - -all: - -include $(addsuffix /module.mk,$(modules)) - -.PHONY: all -all: $(programs) - -.PHONY: libraries -libraries: $(libraries) - -.PHONY: clean -clean: - $(RM) -r $(BINARY_DIR) - -ifneq "$(MAKECMDGOALS)" "clean" - include $(dependencies) -endif -```