Browse Source

Build bundled libelf and link statically if needed

Bryan Drewery 12 years ago
parent
commit
4548b89f64

+ 10 - 0
.gitignore

@@ -25,3 +25,13 @@ cscope.in.out
 cscope.out
 cscope.out
 cscope.po.out
 cscope.po.out
 tags
 tags
+/lib/libelf/Makefile
+/lib/libelf/config.cache
+/lib/libelf/config.h
+/lib/libelf/config.status
+/lib/libelf/lib/Makefile
+/lib/libelf/lib/stamp-h
+/lib/libelf/lib/sys_elf.h
+/lib/libelf/po/Makefile
+/lib/libelf/stamp-h
+/lib/libelf/lib/*.os

+ 11 - 3
build/autotools/configure.ac

@@ -73,6 +73,7 @@ AC_CACHE_SAVE
 
 
 # Checks for system libraries
 # Checks for system libraries
 EGG_CHECK_LIBS
 EGG_CHECK_LIBS
+CHECK_LIBELF
 
 
 # Checks for header files
 # Checks for header files
 AC_HEADER_DIRENT
 AC_HEADER_DIRENT
@@ -263,7 +264,14 @@ if [ $? -ne 0 ]; then
 fi
 fi
 ]
 ]
 
 
-echo ""
-echo ""
+echo
+echo
 echo "------------ Configuring BDLIB ------------"
 echo "------------ Configuring BDLIB ------------"
-test -f lib/bdlib/configure && cd lib/bdlib && CXX="$CXX" ./configure
+[[ -f lib/bdlib/configure ]] && ( cd lib/bdlib && CXX="$CXX" ./configure )
+
+if [[ -n "${LIBELF_BUNDLED}" ]] && [[ -f lib/libelf/configure ]]; then
+  echo
+  echo
+  echo "------------ Configuring LIBELF ------------"
+  ( cd lib/libelf && CC="$CC" CXX="$CXX" ./configure )
+fi

+ 103 - 3
configure

@@ -639,6 +639,8 @@ TCLLIBFN
 TCLLIB
 TCLLIB
 SSL_LIBS
 SSL_LIBS
 SSL_INCLUDES
 SSL_INCLUDES
+LIBELF_LIB
+LIBELF_BUNDLED
 DEBCXXFLAGS
 DEBCXXFLAGS
 CCDEBUG
 CCDEBUG
 STATIC
 STATIC
@@ -5038,6 +5040,97 @@ fi
 
 
 
 
 
 
+  LIBELF_DIR="\$(top_srcdir)/lib/libelf/lib"
+  LIBELF_LIB="${LIBELF_DIR}/libelf.a"
+  LIBELF_BUNDLED="${LIBELF_LIB}"
+  LIBELF_INCLUDE="-I${LIBELF_DIR}"
+
+  for ac_header in gelf.h libelf.h
+do :
+  as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
+ac_fn_cxx_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
+if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
+  cat >>build/confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+    ac_fn_cxx_check_type "$LINENO" "Elf_Note" "ac_cv_type_Elf_Note" "
+#include \"gelf.h\"
+#include \"libelf.h\"
+
+
+"
+if test "x$ac_cv_type_Elf_Note" = xyes; then :
+
+cat >>build/confdefs.h <<_ACEOF
+#define HAVE_ELF_NOTE 1
+_ACEOF
+
+
+
+$as_echo "#define HAVE_GELF_H 1" >>build/confdefs.h
+
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gelf_getehdr in -lelf" >&5
+$as_echo_n "checking for gelf_getehdr in -lelf... " >&6; }
+if ${ac_cv_lib_elf_gelf_getehdr+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lelf  $LIBS"
+cat build/confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end build/confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char gelf_getehdr ();
+int
+main ()
+{
+return gelf_getehdr ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_link "$LINENO"; then :
+  ac_cv_lib_elf_gelf_getehdr=yes
+else
+  ac_cv_lib_elf_gelf_getehdr=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_elf_gelf_getehdr" >&5
+$as_echo "$ac_cv_lib_elf_gelf_getehdr" >&6; }
+if test "x$ac_cv_lib_elf_gelf_getehdr" = xyes; then :
+
+
+$as_echo "#define HAVE_LIBELF 1" >>build/confdefs.h
+
+        LIBELF_LIB="-Wl,-Bstatic -lelf -Wl,-Bdynamic"
+        LIBELF_BUNDLED=
+        LIBELF_INCLUDE=
+
+fi
+
+fi
+
+
+fi
+
+done
+
+
+  CPPFLAGS="${CPPFLAGS} ${LIBELF_INCLUDE}"
+
+
+
+
+
 # Checks for header files
 # Checks for header files
 ac_header_dirent=no
 ac_header_dirent=no
 for ac_hdr in dirent.h sys/ndir.h sys/dir.h ndir.h; do
 for ac_hdr in dirent.h sys/ndir.h sys/dir.h ndir.h; do
@@ -10148,7 +10241,14 @@ if [ $? -ne 0 ]; then
 fi
 fi
 
 
 
 
-echo ""
-echo ""
+echo
+echo
 echo "------------ Configuring BDLIB ------------"
 echo "------------ Configuring BDLIB ------------"
-test -f lib/bdlib/configure && cd lib/bdlib && CXX="$CXX" ./configure
+[ -f lib/bdlib/configure ] && ( cd lib/bdlib && CXX="$CXX" ./configure )
+
+if [ -n "${LIBELF_BUNDLED}" ] && [ -f lib/libelf/configure ]; then
+  echo
+  echo
+  echo "------------ Configuring LIBELF ------------"
+  ( cd lib/libelf && CC="$CC" CXX="$CXX" ./configure )
+fi

+ 13 - 1
lib/Makefile.in

@@ -8,16 +8,18 @@ VPATH = @srcdir@
 
 
 #include $(top_srcdir)/build/build.mk
 #include $(top_srcdir)/build/build.mk
 
 
-.PHONY: default clean distclean normal debug general buildcheck notice notice_debug build units
+.PHONY: default clean distclean normal debug general buildcheck notice notice_debug build units libelf libelf_notice
 
 
 default: normal
 default: normal
 
 
 clean:
 clean:
 	-+@cd bdlib && $(MAKE) clean
 	-+@cd bdlib && $(MAKE) clean
+	-+@test -f libelf/Makefile && cd libelf && $(MAKE) clean
 	@rm -f *.a
 	@rm -f *.a
 
 
 distclean: clean
 distclean: clean
 	-+@cd bdlib && $(MAKE) distclean
 	-+@cd bdlib && $(MAKE) distclean
+	-+@test -f libelf/Makefile && cd libelf && $(MAKE) distclean
 
 
 notice:
 notice:
 	@echo "[*] Making libraries"
 	@echo "[*] Making libraries"
@@ -31,11 +33,21 @@ debug: general notice_debug build.debug
 
 
 general:
 general:
 
 
+libelf_notice:
+	@echo "[*] Building libelf"
+
+$(top_srcdir)/lib/libelf/lib/libelf.a: libelf_notice
+	+@cd libelf/lib && $(MAKE) libelf.a
+
+libelf: @LIBELF_BUNDLED@
+
 build:
 build:
 	+@cd bdlib && $(MAKE) bdlib
 	+@cd bdlib && $(MAKE) bdlib
+	+@$(MAKE) libelf
 
 
 build.debug:
 build.debug:
 	+@cd bdlib && $(MAKE) debug
 	+@cd bdlib && $(MAKE) debug
+	+@$(MAKE) libelf
 
 
 buildcheck: build
 buildcheck: build
 
 

+ 1 - 0
lib/libelf/lib/libelf/byteswap.h

@@ -0,0 +1 @@
+../byteswap.h

+ 1 - 0
lib/libelf/lib/libelf/elf_repl.h

@@ -0,0 +1 @@
+../elf_repl.h

+ 1 - 0
lib/libelf/lib/libelf/errors.h

@@ -0,0 +1 @@
+../errors.h

+ 1 - 0
lib/libelf/lib/libelf/ext_types.h

@@ -0,0 +1 @@
+../ext_types.h

+ 1 - 0
lib/libelf/lib/libelf/gelf.h

@@ -0,0 +1 @@
+../gelf.h

+ 1 - 0
lib/libelf/lib/libelf/libelf.h

@@ -0,0 +1 @@
+../libelf.h

+ 1 - 0
lib/libelf/lib/libelf/nlist.h

@@ -0,0 +1 @@
+../nlist.h

+ 1 - 0
lib/libelf/lib/libelf/private.h

@@ -0,0 +1 @@
+../private.h

+ 1 - 0
lib/libelf/lib/libelf/sys_elf.h

@@ -0,0 +1 @@
+../sys_elf.h

+ 1 - 0
lib/libelf/lib/libelf/verdef.h

@@ -0,0 +1 @@
+../verdef.h

+ 1 - 0
lib/libelf/lib/libelf/verneed.h

@@ -0,0 +1 @@
+../verneed.h

+ 2 - 2
src/Makefile.in

@@ -100,12 +100,12 @@ stringfix: stringfix.c common.h config.h eggdrop.h
 	@$(STRIP) $@@EXEEXT@
 	@$(STRIP) $@@EXEEXT@
 
 
 #../$(EGGEXEC): build_msg $(OBJS) mycrypto compatability
 #../$(EGGEXEC): build_msg $(OBJS) mycrypto compatability
-../$(EGGEXEC): build_msg $(OBJS) mycrypto compatability ../lib/bdlib/src/libbdlib.a
+../$(EGGEXEC): build_msg $(OBJS) mycrypto compatability ../lib/bdlib/src/libbdlib.a @LIBELF_BUNDLED@
 	@echo "[*] Linking"
 	@echo "[*] Linking"
 	@echo ""
 	@echo ""
 	@echo "Linking wraith... $(EGGBUILD)"
 	@echo "Linking wraith... $(EGGBUILD)"
 	@echo ""
 	@echo ""
-	$(LD) -o ../$(EGGEXEC) $(OBJS) $(MODOBJS) compat/*.o crypto/*.o ../lib/bdlib/src/libbdlib.a $(LIBS)
+	$(LD) -o ../$(EGGEXEC) $(OBJS) $(MODOBJS) compat/*.o crypto/*.o ../lib/bdlib/src/libbdlib.a $(LIBS) @LIBELF_LIB@
 #	$(LD) -o ../$(EGGEXEC) $(OBJS) $(MODOBJS) $(LIBS) compat/*.o crypto/*.o
 #	$(LD) -o ../$(EGGEXEC) $(OBJS) $(MODOBJS) $(LIBS) compat/*.o crypto/*.o
 	@$(STRIP) ../$(EGGEXEC)
 	@$(STRIP) ../$(EGGEXEC)
 	@$(OBJCOPY) ../$(EGGEXEC)
 	@$(OBJCOPY) ../$(EGGEXEC)

+ 12 - 0
src/config.h.in

@@ -36,6 +36,9 @@
    */
    */
 #undef HAVE_DIRENT_H
 #undef HAVE_DIRENT_H
 
 
+/* Define to 1 if the system has the type `Elf_Note'. */
+#undef HAVE_ELF_NOTE
+
 /* Define to 1 if you have the <fcntl.h> header file. */
 /* Define to 1 if you have the <fcntl.h> header file. */
 #undef HAVE_FCNTL_H
 #undef HAVE_FCNTL_H
 
 
@@ -45,6 +48,9 @@
 /* Define to 1 if you have the `fsync' function. */
 /* Define to 1 if you have the `fsync' function. */
 #undef HAVE_FSYNC
 #undef HAVE_FSYNC
 
 
+/* Define to 1 if you have the <gelf.h> header file. */
+#undef HAVE_GELF_H
+
 /* Define to 1 if you have the `getpagesize' function. */
 /* Define to 1 if you have the `getpagesize' function. */
 #undef HAVE_GETPAGESIZE
 #undef HAVE_GETPAGESIZE
 
 
@@ -69,6 +75,12 @@
 /* Define to 1 if you have the `dl' library (-ldl). */
 /* Define to 1 if you have the `dl' library (-ldl). */
 #undef HAVE_LIBDL
 #undef HAVE_LIBDL
 
 
+/* Define to 1 if you have the 'elf' library (-lelf). */
+#undef HAVE_LIBELF
+
+/* Define to 1 if you have the <libelf.h> header file. */
+#undef HAVE_LIBELF_H
+
 /* Define to 1 if you have the `nsl' library (-lnsl). */
 /* Define to 1 if you have the `nsl' library (-lnsl). */
 #undef HAVE_LIBNSL
 #undef HAVE_LIBNSL