From e5f30c2294b31b9042b43ea876b6063fea4dec29 Mon Sep 17 00:00:00 2001 From: Julian Blake Kongslie Date: Sat, 25 Jun 2022 19:19:01 -0700 Subject: Reorganize Makefile. --- Makefile | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index c8286f5..91a92e4 100644 --- a/Makefile +++ b/Makefile @@ -6,38 +6,46 @@ CXX ?= g++ CXXFLAGS := -Wall -Werror -std=c++20 -fPIC -iquote . ${OPTIMIZE} ${DEBUG} -libname = $(shell realpath --canonicalize-missing --relative-to . build/$(dir $(1))/lib$(notdir $(1))) - -PARTS := $(shell find * -type d -\( -name build -prune -o -name tools -prune -o -print -\)) -PARTARS := -PARTSOS := +.DEFAULT: issim -MAINOBJS := $(patsubst %.cpp, build/%.o, $(wildcard *.cpp)) -MAINOBJS += build/git-tag.o - -HEADERS := $(find -type f -name \*.h) - -.DEFAULT: issim issim-static +libname = $(shell realpath --canonicalize-missing --relative-to . build/$(dir $(1))/lib$(notdir $(1))) define mklib = ifneq ($(wildcard $(1)/*.cpp),) -$(call libname, $(1).a): $(patsubst %.cpp, build/%.o, $(wildcard $(1)/*.cpp)) +$$(info Component $(call libname,$(1))) + +$(call libname,$(1).a): $(patsubst %.cpp,build/%.o,$(wildcard $(1)/*.cpp)) @mkdir -p $$(dir $$@) $${AR} cr $$@ $$+ -$(call libname, $(1).so): $(patsubst %.cpp, build/%.o, $(wildcard $(1)/*.cpp)) +$(call libname,$(1).so): $(patsubst %.cpp,build/%.o,$(wildcard $(1)/*.cpp)) @mkdir -p $$(dir $$@) $${CXX} $${CXXFLAGS} -shared -o $$@ $$+ -PARTARS += $(call libname, $(1).a) -PARTSOS += $(call libname, $(1).so) +PARTARS += $(call libname,$(1).a) +PARTSOS += $(call libname,$(1).so) + +else + +$$(info Header-only component $(1)) endif endef +PARTS := $(shell find * -type d -\( -name build -prune -o -name tools -prune -o -print -\)) +PARTARS := +PARTSOS := + +$(foreach part,${PARTS},$(eval $(call mklib,${part}))) + +MAINOBJS := $(patsubst %.cpp,build/%.o,$(wildcard *.cpp)) +MAINOBJS += build/git-tag.o + +$(info ) + issim: build/issim-dynamic @ln -sf $< $@ .PHONY: issim @@ -73,7 +81,5 @@ build/%.o: build/%.cpp @mkdir -p $(dir $@) ${CXX} ${CXXFLAGS} -MMD -c -o $@ $< -$(foreach part, ${PARTS}, $(eval $(call mklib, ${part}))) - .SUFFIXES: .SECONDARY: -- cgit v1.2.3