]> git.cameronkatri.com Git - ldid.git/commitdiff
ci: use lto and gc-sections
author1Conan <7620342+1Conan@users.noreply.github.com>
Wed, 19 Jan 2022 04:12:59 +0000 (23:12 -0500)
committerCameron Katri <me@cameronkatri.com>
Wed, 19 Jan 2022 04:14:23 +0000 (23:14 -0500)
.github/workflows/build.yml
Makefile

index 43c6e9a42c85501e253f6f122493e1b7fe876fc1..fd82d0738252ecf296124f14a182b02ced9822dd 100644 (file)
@@ -4,7 +4,14 @@ on:
     paths:
       - '*.c'
       - '*.cpp'
+      - '.github/workflows/*'
+      - 'Makefile'
   pull_request:
+    paths:
+      - '*.c'
+      - '*.cpp'
+      - '.github/workflows/*'
+      - 'Makefile'
   workflow_dispatch:
   release:
     types:
@@ -69,7 +76,11 @@ jobs:
         echo "${HOME}/${TOOLCHAIN}/bin" >> $GITHUB_PATH
         echo "CC=sccache ${TRIPLE}-gcc" >> $GITHUB_ENV
         echo "CXX=sccache ${TRIPLE}-g++" >> $GITHUB_ENV
-        echo "CFLAGS=-Os -static" >> $GITHUB_ENV
+        echo "AR=${TRIPLE}-gcc-ar" >> $GITHUB_ENV
+        echo "NM=${TRIPLE}-gcc-nm" >> $GITHUB_ENV
+        echo "RANLIB=${TRIPLE}-gcc-ranlib" >> $GITHUB_ENV
+        echo "CFLAGS=-Os -fPIC -fno-pie -no-pie -static -flto -ffunction-sections -fdata-sections" >> $GITHUB_ENV
+        echo "LDFLAGS=-Wl,--gc-sections -Wl,-strip-all -flto" >> $GITHUB_ENV
 
     - name: build libplist
       run: |
@@ -79,7 +90,7 @@ jobs:
         ./configure --host=${TRIPLE} --prefix=/usr --without-cython --enable-static --disable-shared
         make -j$(nproc)
 
-        echo "CFLAGS=${CFLAGS} -I${DEP_PATH}/libplist-${LIBPLIST_VERSION}/include" >> $GITHUB_ENV
+        echo "CPPFLAGS=${CPPFLAGS} -I${DEP_PATH}/libplist-${LIBPLIST_VERSION}/include" >> $GITHUB_ENV
         echo "LIBPLIST_LIB=${DEP_PATH}/libplist-${LIBPLIST_VERSION}/src/.libs/libplist-2.0.a" >> $GITHUB_ENV
 
     - name: build openssl
@@ -103,7 +114,7 @@ jobs:
         ./config --prefix=/usr --static -static ${PLATFORM}
         make -j$(nproc) build_generated libcrypto.a
 
-        echo "CFLAGS=${CFLAGS} -I${DEP_PATH}/openssl-${OPENSSL_VERSION}/include" >> $GITHUB_ENV
+        echo "CPPFLAGS=${CPPFLAGS} -I${DEP_PATH}/openssl-${OPENSSL_VERSION}/include" >> $GITHUB_ENV
         echo "LIBCRYPTO_LIB=${DEP_PATH}/openssl-${OPENSSL_VERSION}/libcrypto.a" >> $GITHUB_ENV
 
     - name: build
@@ -111,6 +122,7 @@ jobs:
         export LDID_VERSION=$(echo "$(git describe --tags --abbrev=0)")
         make -j$(nproc) \
           VERSION="${LDID_VERSION}" \
+          LDFLAGS="-static -static-libstdc++ ${LDFLAGS}" \
           LIBS="${LIBPLIST_LIB} ${LIBCRYPTO_LIB}"
         ${TRIPLE}-strip ldid
 
index 6efccc4a479b36db328c5731b51a312b9fb5dff0..12b22c9db32663935edae7156af66c5f2a004a65 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@ INSTALL  ?= install
 LN       ?= ln
 
 CFLAGS   ?= -O2 -pipe
-CXXFLAGS ?= $(CFLAGS)
+CXXFLAGS ?= $(CFLAGS) -std=c++11
 LDFLAGS  ?=
 
 PREFIX   ?= /usr/local
@@ -20,13 +20,13 @@ LIBS     ?= -lcrypto -lplist-2.0
 all: ldid
 
 %.c.o: %.c
-       $(CC) -c $(CFLAGS) -I. $< -o $@
+       $(CC) -c $(CFLAGS) $(CPPFLAGS) -I. $< -o $@
 
 %.cpp.o: %.cpp
-       $(CXX) -c -std=c++11 $(CXXFLAGS) -I. -DLDID_VERSION=\"$(VERSION)\" $< -o $@
+       $(CXX) -c $(CXXFLAGS) $(CPPFLAGS) -I. -DLDID_VERSION=\"$(VERSION)\" $< -o $@
 
 ldid: $(SRC:%=%.o)
-       $(CXX) $^ $(LDFLAGS) $(LIBS) -o ldid
+       $(CXX) $(CXXFLAGS) -o ldid $^ $(LDFLAGS) $(LIBS)
 
 install: all
        $(INSTALL) -D -m755 ldid $(DESTDIR)$(BINDIR)/ldid