From bcceab5af4a32fa2ab7473873ccf8dc088fa54a5 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 28 May 2010 16:41:43 +0000 Subject: [PATCH] 2010-05-28 18:28 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * utils/hbmk2/hbmk2.prg + Added untested, experimental support for -reqpkg=/reqpkgs= (.hbp/.hbc) options. F.e. '-reqpkg=libcurl' option causes hbmk2 to query library, library path and include path information from 'pkg-config' tool and if not found using '*-config' script, and to automatically pass these information to C compiler/linker. In addition, it will automatically add a macro named HBMK2_HAS_LIBCURL to C compiler cmdline, so that the sources get to know that this package was found. ; NOTE: Nothing is finalized, it is still a question how to setup obligatory and optional components, current implementation is rather a mixture, but anyway pls feel free to test it. It's also a question how to merge this method with the -inctrypath/-reqheader one. Later we can consider adopting extra C flags, too, and it can be extended to know about more package detection methods (even platform dependent ones can be used if they adhere to more or less the same principle of 'pkgname->IN incpaths/libpaths/libs->OUT') Thanks to Tamas Tevesz for sparking the idea. --- harbour/ChangeLog | 22 +++++ harbour/utils/hbmk2/hbmk2.prg | 156 ++++++++++++++++++++++++---------- 2 files changed, 135 insertions(+), 43 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 967d5d6725..ca66cf75dc 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,28 @@ past entries belonging to author(s): Viktor Szakats. */ +2010-05-28 18:28 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) + * utils/hbmk2/hbmk2.prg + + Added untested, experimental support for -reqpkg=/reqpkgs= + (.hbp/.hbc) options. F.e. '-reqpkg=libcurl' option causes + hbmk2 to query library, library path and include path + information from 'pkg-config' tool and if not found using + '*-config' script, and to automatically pass these information + to C compiler/linker. In addition, it will automatically add + a macro named HBMK2_HAS_LIBCURL to C compiler cmdline, so + that the sources get to know that this package was found. + ; NOTE: Nothing is finalized, it is still a question how to + setup obligatory and optional components, current + implementation is rather a mixture, but anyway pls + feel free to test it. It's also a question how to merge + this method with the -inctrypath/-reqheader one. + Later we can consider adopting extra C flags, too, + and it can be extended to know about more package + detection methods (even platform dependent ones can + be used if they adhere to more or less the same + principle of 'pkgname->IN incpaths/libpaths/libs->OUT') + Thanks to Tamas Tevesz for sparking the idea. + 2010-05-28 17:31 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * src/common/hbver.c + Fine tuned SunPro version detection. diff --git a/harbour/utils/hbmk2/hbmk2.prg b/harbour/utils/hbmk2/hbmk2.prg index 3483bf1de1..579162ef19 100644 --- a/harbour/utils/hbmk2/hbmk2.prg +++ b/harbour/utils/hbmk2/hbmk2.prg @@ -318,59 +318,60 @@ REQUEST hbmk_KEYW #define _HBMK_lHBCPPMM 60 #define _HBMK_aVAR 61 #define _HBMK_hKEYHEADER 62 +#define _HBMK_aREQPKG 63 /* TODO */ -#define _HBMK_lCreateLib 63 -#define _HBMK_lCreateDyn 64 -#define _HBMK_lCreateImpLib 65 +#define _HBMK_lCreateLib 64 +#define _HBMK_lCreateDyn 65 +#define _HBMK_lCreateImpLib 66 -#define _HBMK_lDynVM 66 +#define _HBMK_lDynVM 67 -#define _HBMK_lBLDFLGP 67 -#define _HBMK_lBLDFLGC 68 -#define _HBMK_lBLDFLGL 69 +#define _HBMK_lBLDFLGP 68 +#define _HBMK_lBLDFLGC 69 +#define _HBMK_lBLDFLGL 70 -#define _HBMK_cFIRST 70 -#define _HBMK_aPRG 71 -#define _HBMK_aC 72 -#define _HBMK_aCPP 73 -#define _HBMK_aRESSRC 74 -#define _HBMK_aRESCMP 75 -#define _HBMK_aOBJUSER 76 -#define _HBMK_aICON 77 -#define _HBMK_aIMPLIBSRC 78 -#define _HBMK_aDEF 79 -#define _HBMK_hDEPTS 80 +#define _HBMK_cFIRST 71 +#define _HBMK_aPRG 72 +#define _HBMK_aC 73 +#define _HBMK_aCPP 74 +#define _HBMK_aRESSRC 75 +#define _HBMK_aRESCMP 76 +#define _HBMK_aOBJUSER 77 +#define _HBMK_aICON 78 +#define _HBMK_aIMPLIBSRC 79 +#define _HBMK_aDEF 80 +#define _HBMK_hDEPTS 81 -#define _HBMK_aPO 81 -#define _HBMK_cHBL 82 -#define _HBMK_cHBLDir 83 -#define _HBMK_aLNG 84 -#define _HBMK_cPO 85 +#define _HBMK_aPO 82 +#define _HBMK_cHBL 83 +#define _HBMK_cHBLDir 84 +#define _HBMK_aLNG 85 +#define _HBMK_cPO 86 -#define _HBMK_aPLUGIN 86 -#define _HBMK_hPLUGINHRB 87 -#define _HBMK_hPLUGINVars 88 -#define _HBMK_aPLUGINPars 89 +#define _HBMK_aPLUGIN 87 +#define _HBMK_hPLUGINHRB 88 +#define _HBMK_hPLUGINVars 89 +#define _HBMK_aPLUGINPars 90 -#define _HBMK_lDEBUGTIME 90 -#define _HBMK_lDEBUGINC 91 -#define _HBMK_lDEBUGSTUB 92 -#define _HBMK_lDEBUGI18N 93 +#define _HBMK_lDEBUGTIME 91 +#define _HBMK_lDEBUGINC 92 +#define _HBMK_lDEBUGSTUB 93 +#define _HBMK_lDEBUGI18N 94 -#define _HBMK_cCCPATH 94 -#define _HBMK_cCCPREFIX 95 -#define _HBMK_cCCPOSTFIX 96 -#define _HBMK_cCCEXT 97 +#define _HBMK_cCCPATH 95 +#define _HBMK_cCCPREFIX 96 +#define _HBMK_cCCPOSTFIX 97 +#define _HBMK_cCCEXT 98 -#define _HBMK_cWorkDir 98 -#define _HBMK_nCmd_Esc 99 -#define _HBMK_nScr_Esc 100 -#define _HBMK_nErrorLevel 101 +#define _HBMK_cWorkDir 99 +#define _HBMK_nCmd_Esc 100 +#define _HBMK_nScr_Esc 101 +#define _HBMK_nErrorLevel 102 -#define _HBMK_cPROGDIR 102 -#define _HBMK_cPROGNAME 103 +#define _HBMK_cPROGDIR 103 +#define _HBMK_cPROGNAME 104 -#define _HBMK_MAX_ 103 +#define _HBMK_MAX_ 104 #ifndef _HBMK_EMBEDDED_ @@ -1914,7 +1915,7 @@ FUNCTION hbmk2( aArgs, /* @ */ lPause ) cParam := MacroProc( hbmk, SubStr( cParam, 3 ), aParam[ _PAR_cFileName ] ) IF ! Empty( cParam ) - AAdd( hbmk[ _HBMK_aLIBPATH ], PathSepToTarget( hbmk, DirDelPathSep( PathSepToSelf( PathProc( cParam, aParam[ _PAR_cFileName ] ) ) ) ) ) + AAdd( hbmk[ _HBMK_aLIBPATH ], PathSepToTarget( hbmk, DirDelPathSep( PathProc( PathSepToSelf( cParam ), aParam[ _PAR_cFileName ] ) ) ) ) ENDIF CASE Left( cParamL, Len( "-instpath=" ) ) == "-instpath=" .AND. ; @@ -2099,6 +2100,13 @@ FUNCTION hbmk2( aArgs, /* @ */ lPause ) ENDIF ENDIF + CASE Left( cParam, Len( "-reqpkg=" ) ) == "-reqpkg=" + + cParam := MacroProc( hbmk, SubStr( cParam, Len( "-reqpkg=" ) + 1 ), aParam[ _PAR_cFileName ] ) + IF ! Empty( cParam ) + AAdd( hbmk[ _HBMK_aREQPKG ], cParam ) + ENDIF + CASE Left( cParam, 1 ) $ cOptPrefix DO CASE @@ -2376,6 +2384,11 @@ FUNCTION hbmk2( aArgs, /* @ */ lPause ) ENDIF ENDIF + /* Process any package requirements */ + FOR EACH tmp IN hbmk[ _HBMK_aREQPKG ] + pkg_try_detection( hbmk, tmp ) + NEXT + IF ( ! lStopAfterInit .AND. ! lStopAfterHarbour ) .OR. hbmk[ _HBMK_lCreateImpLib ] IF hbmk[ _HBMK_cGT ] != NIL .AND. hbmk[ _HBMK_cGT ] == hbmk[ _HBMK_cGTDEFAULT ] @@ -5748,6 +5761,58 @@ STATIC FUNCTION deplst_add( hDeps, cList ) RETURN .T. +/* Try '*-config' and 'pkg-config *' detection */ +STATIC FUNCTION pkg_try_detection( hbmk, cName ) + LOCAL cStdOut + LOCAL cItem + + LOCAL lFound := .F. + + cStdOut := "" + hb_processRun( "pkg-config --libs --cflags " + cName,, @cStdOut ) + IF Empty( cStdOut ) + hb_processRun( cName + "-config --libs --cflags",, @cStdOut ) + ENDIF + + IF ! Empty( cStdOut ) + FOR EACH cItem IN hb_ATokens( cStdOut,, .T. ) + IF ! Empty( cItem ) + lFound := .T. + DO CASE + CASE Left( cItem, Len( "-l" ) ) == "-l" + IF _IS_AUTOLIBSYSPRE( cItem ) + AAdd( hbmk[ _HBMK_aLIBUSERSYSPRE ], PathSepToTarget( hbmk, cItem ) ) + ELSE + AAdd( hbmk[ _HBMK_aLIBUSER ], PathSepToTarget( hbmk, cItem ) ) + ENDIF + CASE Left( cItem, Len( "-l" ) ) == "-L" + AAdd( hbmk[ _HBMK_aLIBPATH ], PathSepToTarget( hbmk, DirDelPathSep( PathSepToSelf( cItem ) ) ) ) + CASE Left( cItem, Len( "-l" ) ) == "-I" + AAdd( hbmk[ _HBMK_aINCPATH ], PathSepToTarget( hbmk, DirDelPathSep( PathSepToSelf( cItem ) ) ) ) + ENDCASE + ENDIF + NEXT + IF lFound + AAdd( hbmk[ _HBMK_aOPTC ], "-DHBMK2_HAS_" + StrToDefine( cName ) ) + ENDIF + ENDIF + + RETURN lFound + +STATIC FUNCTION StrToDefine( cString ) + LOCAL cDefine := "" + LOCAL c + + FOR EACH c IN Upper( cString ) + IF c $ "- " + cDefine += "_" + ELSEIF IsDigit( c ) .OR. hb_asciiIsAlpha( c ) .OR. c == "_" + cDefine += c + ENDIF + NEXT + + RETURN cDefine + STATIC FUNCTION AMerge( aDst, aSrc ) LOCAL item @@ -7117,6 +7182,11 @@ STATIC FUNCTION HBC_ProcessOne( hbmk, cFileName, nNestingLevel ) AAddNewNotEmpty( hbmk[ _HBMK_aPLUGINPars ], PathSepToTarget( hbmk, MacroProc( hbmk, StrStripQuote( cItem ), cFileName ), 2 ) ) NEXT + CASE Lower( Left( cLine, Len( "reqpkgs=" ) ) ) == "reqpkgs=" ; cLine := SubStr( cLine, Len( "reqpkgs=" ) + 1 ) + FOR EACH cItem IN hb_ATokens( cLine,, .T. ) + AAddNewNotEmpty( hbmk[ _HBMK_aREQPKG ], MacroProc( hbmk, StrStripQuote( cItem ), cFileName ) ) + NEXT + CASE Lower( Left( cLine, Len( "psources=" ) ) ) == "psources=" ; cLine := SubStr( cLine, Len( "psources=" ) + 1 ) FOR EACH cItem IN hb_ATokens( cLine,, .T. ) cItem := MacroProc( hbmk, StrStripQuote( cItem ), cFileName )