From 9646e622b1d4f129b57c6466cf154a545ae347c7 Mon Sep 17 00:00:00 2001 From: Tim Flynn Date: Fri, 15 Mar 2019 12:40:52 -0400 Subject: [PATCH] Fix Linux release packages (#23) * Sources should be in /usr/src/fly, not /usr/src * Build both static and shared libraries --- build/nix/Makefile | 4 +++- build/nix/compile.mk | 43 +++++++++++++++++++++---------------------- build/nix/flags.mk | 4 ++-- build/nix/release.mk | 6 ++++-- build/nix/target.mk | 9 +++------ fly/files.mk | 4 ++-- test/build/Makefile | 5 +---- 7 files changed, 36 insertions(+), 39 deletions(-) diff --git a/build/nix/Makefile b/build/nix/Makefile index 28de40f05..747b137d4 100644 --- a/build/nix/Makefile +++ b/build/nix/Makefile @@ -12,7 +12,9 @@ $(eval $(call ADD_TARGET, libfly, fly, LIB)) # Test targets $(eval $(call ADD_TARGET, libfly_unit_tests, test, TEST)) -$(eval $(call ADD_TARGET, libfly_qt5_example, test/qt5, QT5)) +ifeq ($(qt5), 1) + $(eval $(call ADD_TARGET, libfly_qt5_example, test/qt5, QT5)) +endif # Import the build system include build.mk diff --git a/build/nix/compile.mk b/build/nix/compile.mk index e41d22ed4..925db213f 100644 --- a/build/nix/compile.mk +++ b/build/nix/compile.mk @@ -29,7 +29,7 @@ define BIN_RULES t := $$(strip $(1)) -MAKEFILES_$(d) := $(BUILD_ROOT)/flags.mk $(d)/*.mk +MAKEFILES_$(d) := $(BUILD_ROOT)/flags.mk $(wildcard $(d)/*.mk) $(2): OBJS := $$(OBJ_$$(t)) $(2): CFLAGS := $(CFLAGS_$(d)) $(CFLAGS) @@ -88,39 +88,37 @@ $(2)/%.rcc.cpp: $(d)/%.qrc $$(MAKEFILES_$(d)) endef -# Link a library target from a set of object files. +# Link static and shared libraries targets from a set of object files. # # $(1) = The target's name. -# $(2) = The path to the target output binary. define LIB_RULES t := $$(strip $(1)) -MAKEFILES_$(d) := $(BUILD_ROOT)/flags.mk $(d)/*.mk +MAKEFILES_$(d) := $(BUILD_ROOT)/flags.mk $(wildcard $(d)/*.mk) -$(2): OBJS := $$(OBJ_$$(t)) -$(2): CFLAGS := $(CFLAGS_$(d)) $(CFLAGS) -$(2): CXXFLAGS := $(CXXFLAGS_$(d)) $(CXXFLAGS) -$(2): LDFLAGS := $(LDFLAGS_$(d)) $(LDFLAGS) +%.a %.so.$(VERSION): OBJS := $$(OBJ_$$(t)) +%.a %.so.$(VERSION): CFLAGS := $(CFLAGS_$(d)) $(CFLAGS) +%.a %.so.$(VERSION): CXXFLAGS := $(CXXFLAGS_$(d)) $(CXXFLAGS) +%.a %.so.$(VERSION): LDFLAGS := $(LDFLAGS_$(d)) $(LDFLAGS) -$(2): $$(OBJ_$$(t)) $$(GEN_$$(t)) $$(MAKEFILES_$(d)) +%.a: $$(OBJ_$$(t)) $$(GEN_$$(t)) $$(MAKEFILES_$(d)) @mkdir -p $$(@D) + @echo "[Static $$(subst $(CURDIR)/,,$$@)]" + $(STATIC) -ifeq ($(release),1) +%.so.$(VERSION): $$(OBJ_$$(t)) $$(GEN_$$(t)) $$(MAKEFILES_$(d)) + @mkdir -p $$(@D) @echo "[Shared $$(subst $(CURDIR)/,,$$@)]" $(SHARED_CXX) $(STRIP) -else - @echo "[Static $$(subst $(CURDIR)/,,$$@)]" - $(STATIC) -endif endef # Build a release package. # # $(1) = The target's name. -# $(2) = The path to the target output binary or library. +# $(2) = The path to the target output binary or libraries. # $(3) = The path to the target release package. define PKG_RULES @@ -147,7 +145,7 @@ endef # $(1) = Path to directory where object files should be placed. define OBJ_RULES -MAKEFILES_$(d) := $(BUILD_ROOT)/flags.mk $(d)/*.mk +MAKEFILES_$(d) := $(BUILD_ROOT)/flags.mk $(wildcard $(d)/*.mk) $(1)/%.o: CFLAGS := $(CFLAGS_$(d)) $(CFLAGS) $(1)/%.o: CXXFLAGS := $(CXXFLAGS_$(d)) $(CXXFLAGS) @@ -180,7 +178,7 @@ endef # # $(1) = The target's name. # $(2) = The path to the target root directory. -# $(3) = The path to the target output library. +# $(3) = The path to the target output libraries. # $(4) = The path to the target release package. define DEFINE_BIN_RULES @@ -219,7 +217,7 @@ endef # # $(1) = The target's name. # $(2) = The path to the target root directory. -# $(3) = The path to the target output library. +# $(3) = The path to the target output libraries. # $(4) = The path to the target release package. define DEFINE_QT5_RULES @@ -255,14 +253,15 @@ $$(eval $$(call POP_DIR)) endef -# Define the rules to build a library target. The files.mk should define: +# Define the rules to build static and shared library targets. The files.mk +# should define: # # SRC_DIRS_$(d) = The source directories to include in the build. -# SRC_$(d) = The sources to be built in the target library. +# SRC_$(d) = The sources to be built in the target libraries. # # $(1) = The target's name. # $(2) = The path to the target root directory. -# $(3) = The path to the target output library. +# $(3) = The path to the target output libraries. # $(4) = The path to the target release package. define DEFINE_LIB_RULES @@ -278,7 +277,7 @@ $$(foreach dir, $$(SRC_DIRS_$$(d)), \ $$(eval $$(call DEFINE_SRC_RULES, $(1), $$(dir)))) # Define the compile rules -$$(eval $$(call LIB_RULES, $(1), $(3))) +$$(eval $$(call LIB_RULES, $(1))) $$(eval $$(call PKG_RULES, $(1), $(3), $(4))) $$(eval $$(call OBJ_RULES, $$(OBJ_DIR_$$(d)))) diff --git a/build/nix/flags.mk b/build/nix/flags.mk index f90be1580..a4a340be9 100644 --- a/build/nix/flags.mk +++ b/build/nix/flags.mk @@ -12,7 +12,7 @@ LDFLAGS := -L$(LIB_DIR) -fuse-ld=gold LDLIBS := # Compiler flags for both C and C++ files -CF_ALL := -MMD -MP +CF_ALL := -MMD -MP -fPIC CF_ALL += -Wall -Wextra -Werror CF_ALL += -I$(SOURCE_ROOT) -I$(GEN_DIR) @@ -28,7 +28,7 @@ CF_ALL += -I$(SOURCE_ROOT)/test/googletest/googletest # debug builds - but only use address sanitizer on 64-bit builds: # https://github.com/google/sanitizers/issues/954 ifeq ($(release), 1) - CF_ALL += -O2 -fPIC + CF_ALL += -O2 else CF_ALL += -O0 -g --coverage diff --git a/build/nix/release.mk b/build/nix/release.mk index e7748026f..4559989b8 100644 --- a/build/nix/release.mk +++ b/build/nix/release.mk @@ -109,10 +109,11 @@ endef # $(1) = The target's name. # $(2) = The path to the directory. # $(3) = Header file extension. +# $(4) = Header file destination. define ADD_REL_INC $(eval $(call SET_REL_VAR, $(1))) -$(eval $(call ADD_REL_CMD, $(1), rsync -am --include='$(strip $(3))' -f 'hide$(COMMA)! */' $(2) $(REL_INC_DIR_$(t)))) +$(eval $(call ADD_REL_CMD, $(1), rsync -am --include='$(strip $(3))' -f 'hide$(COMMA)! */' $(2)/ $(REL_INC_DIR_$(t))/$(strip $(4)))) endef @@ -121,9 +122,10 @@ endef # $(1) = The target's name. # $(2) = The path to the directory. # $(3) = Source file extension. +# $(4) = Source file destination. define ADD_REL_SRC $(eval $(call SET_REL_VAR, $(1))) -$(eval $(call ADD_REL_CMD, $(1), rsync -am --include='$(strip $(3))' -f 'hide$(COMMA)! */' $(2) $(REL_SRC_DIR_$(t)))) +$(eval $(call ADD_REL_CMD, $(1), rsync -am --include='$(strip $(3))' -f 'hide$(COMMA)! */' $(2)/ $(REL_SRC_DIR_$(t))/$(strip $(4)))) endef diff --git a/build/nix/target.mk b/build/nix/target.mk index 9d8acf57f..33d63bbfa 100644 --- a/build/nix/target.mk +++ b/build/nix/target.mk @@ -23,11 +23,8 @@ ifeq ($$(TARGET_TYPE_$$(t)), BIN) else ifeq ($$(TARGET_TYPE_$$(t)), QT5) TARGET_FILE_$$(t) := $(BIN_DIR)/$$(t) else ifeq ($$(TARGET_TYPE_$$(t)), LIB) - ifeq ($(release), 1) - TARGET_FILE_$$(t) := $(LIB_DIR)/$$(t).so.$(VERSION) - else - TARGET_FILE_$$(t) := $(LIB_DIR)/$$(t).a - endif + TARGET_FILE_$$(t) := $(LIB_DIR)/$$(t).so.$(VERSION) + TARGET_FILE_$$(t) += $(LIB_DIR)/$$(t).a else $$(error Target type $$(TARGET_TYPE_$$(t)) not supported) endif @@ -36,7 +33,7 @@ endif TARGET_PACKAGE_$$(t) := $(ETC_DIR)/$$(t)-nix-$(VERSION).$(arch).tar.bz2 TARGET_PACKAGES += $$(TARGET_PACKAGE_$$(t)) -# Define the make goal to build the target +# Define the make goal to build the targets $$(t): $$(TARGET_FILE_$$(t)) $$(TARGET_PACKAGE_$$(t)) # Define the compilation goals for the target diff --git a/fly/files.mk b/fly/files.mk index 1b3cdd1ee..f46a617e3 100644 --- a/fly/files.mk +++ b/fly/files.mk @@ -14,7 +14,7 @@ SRC_DIRS_$(d) := \ $(eval $(call ADD_REL_LIB, libfly)) # Add all header files to release package -$(eval $(call ADD_REL_INC, libfly, $(d), *.h)) +$(eval $(call ADD_REL_INC, libfly, $(d), *.h, fly)) # Add make system files to release package -$(eval $(call ADD_REL_SRC, libfly, $(BUILD_ROOT)/, *.mk)) +$(eval $(call ADD_REL_SRC, libfly, $(BUILD_ROOT), *.mk, fly)) diff --git a/test/build/Makefile b/test/build/Makefile index 2e87a9fbc..87642b4eb 100644 --- a/test/build/Makefile +++ b/test/build/Makefile @@ -9,11 +9,8 @@ VERSION = 1.0.0 # Import the build API include /usr/src/fly/api.mk -# Set default target -$(eval $(call SET_DEFAULT_TARGET, libflytest)) - # Main targets -$(eval $(call ADD_TARGET, libflytest, ., BIN)) +$(eval $(call ADD_TARGET, libfly_build_test, ., BIN)) # Import the build system include /usr/src/fly/build.mk