]> git.cameronkatri.com Git - ldid.git/commitdiff
Improve makefile (#16)
authorTeutates <103068388+Teutates@users.noreply.github.com>
Thu, 7 Jul 2022 19:48:07 +0000 (15:48 -0400)
committerGitHub <noreply@github.com>
Thu, 7 Jul 2022 19:48:07 +0000 (15:48 -0400)
.github/workflows/build.yml
Makefile

index 014443365ed8453168df2de62d7c900781ed2b45..2630fc4d4feee6864e673feddad7885ccfdb573b 100644 (file)
@@ -78,7 +78,7 @@ jobs:
         echo "RANLIB=${TRIPLE}-gcc-ranlib" >> $GITHUB_ENV
         echo "CFLAGS=-Os -fPIC -fno-pie -no-pie -static -flto -ffunction-sections -fdata-sections" >> $GITHUB_ENV
         echo "CXXFLAGS=-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
+        echo "LDFLAGS=-Os -fPIC -fno-pie -no-pie -static -Wl,--gc-sections -Wl,-strip-all -flto -ffunction-sections -fdata-sections" >> $GITHUB_ENV
 
     - name: build libplist
       run: |
@@ -88,8 +88,8 @@ jobs:
         ./configure --host=${TRIPLE} --prefix=/usr --without-cython --enable-static --disable-shared
         make -j$(nproc)
 
-        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
+        echo "LIBPLIST_INCLUDES=-I${DEP_PATH}/libplist-${LIBPLIST_VERSION}/include" >> $GITHUB_ENV
+        echo "LIBPLIST_LIBS=${DEP_PATH}/libplist-${LIBPLIST_VERSION}/src/.libs/libplist-2.0.a" >> $GITHUB_ENV
 
     - name: build openssl
       run: |
@@ -101,16 +101,13 @@ jobs:
         ./config --prefix=/usr --static -static no-module ${PLATFORM}
         make -j$(nproc) build_generated libcrypto.a
 
-        echo "CPPFLAGS=${CPPFLAGS} -I${DEP_PATH}/openssl-${OPENSSL_VERSION}/include" >> $GITHUB_ENV
-        echo "LIBCRYPTO_LIB=${DEP_PATH}/openssl-${OPENSSL_VERSION}/libcrypto.a" >> $GITHUB_ENV
+        echo "LIBCRYPTO_INCLUDES=-I${DEP_PATH}/openssl-${OPENSSL_VERSION}/include" >> $GITHUB_ENV
+        echo "LIBCRYPTO_LIBS=${DEP_PATH}/openssl-${OPENSSL_VERSION}/libcrypto.a" >> $GITHUB_ENV
 
     - name: build
       run: |
-        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}"
+          LDFLAGS="-static -static-libstdc++ ${LDFLAGS}"
         ${TRIPLE}-strip ldid
 
     - uses: actions/upload-artifact@v1
@@ -190,8 +187,8 @@ jobs:
         ./configure --host=${HOST_ARCH}-apple-darwin --without-cython --enable-static --disable-shared
         make -j$(sysctl -n hw.ncpu)
 
-        echo "CXXFLAGS=${CXXFLAGS} -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
+        echo "LIBPLIST_INCLUDES=-I${DEP_PATH}/libplist-${LIBPLIST_VERSION}/include" >> $GITHUB_ENV
+        echo "LIBPLIST_LIBS=${DEP_PATH}/libplist-${LIBPLIST_VERSION}/src/.libs/libplist-2.0.a" >> $GITHUB_ENV
 
     - name: build openssl
       run: |
@@ -201,16 +198,14 @@ jobs:
         ./config --prefix=/usr no-shared no-module darwin64-${ARCH}-cc
         make -j$(sysctl -n hw.ncpu) build_generated libcrypto.a
 
-        echo "CXXFLAGS=${CXXFLAGS} -I${DEP_PATH}/openssl-${OPENSSL_VERSION}/include" >> $GITHUB_ENV
-        echo "LIBCRYPTO_LIB=${DEP_PATH}/openssl-${OPENSSL_VERSION}/libcrypto.a" >> $GITHUB_ENV
+        echo "LIBCRYPTO_INCLUDES=${CXXFLAGS} -I${DEP_PATH}/openssl-${OPENSSL_VERSION}/include" >> $GITHUB_ENV
+        echo "LIBCRYPTO_LIBS=${DEP_PATH}/openssl-${OPENSSL_VERSION}/libcrypto.a" >> $GITHUB_ENV
 
     - name: build
       run: |
-        export LDID_VERSION=$(echo "$(git describe --tags --abbrev=0)")
         make -j$(sysctl -n hw.ncpu) \
-          CXXFLAGS="-std=c++11 ${CXXFLAGS} -flto=thin" \
-          VERSION="${LDID_VERSION}" \
-          LIBS="${LIBPLIST_LIB} ${LIBCRYPTO_LIB}"
+          CXXFLAGS="-flto=thin ${CXXFLAGS}" \
+          LDFLAGS="-flto=thin"
         strip ldid
 
     - uses: actions/upload-artifact@v1
index d0419b19e33386a1d04ddf473adedb3d0753ea2f..e528faf49239dfe2a0fd0e8be76ddff5e2be824d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,11 +1,15 @@
-VERSION  ?= 2.1.5
+ifneq (,$(wildcard .git))
+VERSION  ?= $(shell git describe --tags)
+else
+VERSION  ?= 2.1.5-procursus3
+endif
 
 CC       ?= cc
 CXX      ?= c++
 INSTALL  ?= install
 LN       ?= ln
 
-CXXFLAGS ?= -std=c++11 -O2 -pipe
+CXXFLAGS ?= -O2 -pipe
 LDFLAGS  ?=
 
 PREFIX   ?= /usr/local
@@ -14,17 +18,28 @@ BINDIR   ?= $(PREFIX)/bin
 MANDIR   ?= $(PREFIX)/share/man
 
 SRC      := ldid.cpp
-LIBS     ?= -lcrypto -lplist-2.0
+LIBS     ?=
+
+LIBPLIST_INCLUDES  ?= $(shell pkg-config --cflags libplist-2.0)
+LIBPLIST_LIBS      ?= $(shell pkg-config --libs libplist-2.0)
+
+ifeq ($(shell uname -s),FreeBSD)
+LIBCRYPTO_INCLUDES ?= -I/usr/include
+LIBCRYPTO_LIBS     ?= -L/usr/lib -lcrypto
+else
+LIBCRYPTO_INCLUDES ?= $(shell pkg-config --cflags libcrypto)
+LIBCRYPTO_LIBS     ?= $(shell pkg-config --libs libcrypto)
+endif
 
 MANPAGE_LANGS := zh_TW zh_CN
 
 all: ldid
 
 %.cpp.o: %.cpp
-       $(CXX) -c $(CXXFLAGS) $(CPPFLAGS) -I. -DLDID_VERSION=\"$(VERSION)\" $< -o $@
+       $(CXX) -c -std=c++11 $(CXXFLAGS) $(LIBCRYPTO_INCLUDES) $(LIBPLIST_INCLUDES) $(CPPFLAGS) -I. -DLDID_VERSION=\"$(VERSION)\" $< -o $@
 
 ldid: $(SRC:%=%.o)
-       $(CXX) $(CXXFLAGS) -o ldid $^ $(LDFLAGS) $(LIBS)
+       $(CXX) -o ldid $^ $(LDFLAGS) $(LIBCRYPTO_LIBS) $(LIBPLIST_LIBS) $(LIBS)
 
 install: all
        $(INSTALL) -d $(DESTDIR)$(BINDIR)/