Skip to content

Commit

Permalink
Fix Linux release packages (#23)
Browse files Browse the repository at this point in the history
* Sources should be in /usr/src/fly, not /usr/src

* Build both static and shared libraries
  • Loading branch information
trflynn89 authored Mar 15, 2019
1 parent c888c95 commit 9646e62
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 39 deletions.
4 changes: 3 additions & 1 deletion build/nix/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
43 changes: 21 additions & 22 deletions build/nix/compile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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))))

Expand Down
4 changes: 2 additions & 2 deletions build/nix/flags.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

Expand Down
6 changes: 4 additions & 2 deletions build/nix/release.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
9 changes: 3 additions & 6 deletions build/nix/target.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions fly/files.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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))
5 changes: 1 addition & 4 deletions test/build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9646e62

Please sign in to comment.