--- gforth/libcc.fs 2008/08/09 20:44:03 1.53 +++ gforth/libcc.fs 2009/10/17 20:57:33 1.60 @@ -135,6 +135,7 @@ \ : delete-file 2drop 0 ; require struct.fs +require mkdir.fs \ c-function-ft word body: struct @@ -218,24 +219,19 @@ end-struct list% node list-next @ repeat ; -\ linked libraries - -list% - cell% 2* field c-lib-string -end-struct c-lib% - -variable c-libs \ linked list of library names (without "lib") +2variable c-libs \ library names in a string (without "lib") : add-lib ( c-addr u -- ) \ gforth \G Add library lib@i{string} to the list of libraries, where -\G @i{string} is represented by @i{c-addr u}. - c-lib% %size allocate throw dup >r - c-lib-string 2! - r> c-libs list-insert ; - -: append-l ( c-addr1 u1 node -- c-addr2 u2 ) - \ append " -l" to string1 - >r s" -l" append r> c-lib-string 2@ append ; + \G @i{string} is represented by @i{c-addr u}. + c-libs 2@ d0= IF 0 allocate throw 0 c-libs 2! THEN + c-libs 2@ s" -l" append 2swap append c-libs 2! ; + +: add-libpath ( c-addr u -- ) \ gforth +\G Add path @i{string} to the list of library search pathes, where + \G @i{string} is represented by @i{c-addr u}. + c-libs 2@ d0= IF 0 allocate throw 0 c-libs 2! THEN + c-libs 2@ s" -L" append 2swap append c-libs 2! ; \ C prefix lines @@ -255,6 +251,9 @@ variable c-prefix-lines-end c-prefix-lin : print-c-prefix-lines ( -- ) c-prefix-lines @ ['] print-c-prefix-line list-map ; +: free-c-prefix-lines ( -- ) + c-prefix-lines @ off c-prefix-lines @ c-prefix-lines-end ! ; + : save-c-prefix-line ( c-addr u -- ) c-source-file-id @ ?dup-if >r 2dup r> write-line throw @@ -431,7 +430,7 @@ create gen-wrapped-types dup { descriptor } count { ret } count 2dup { d: pars } chars + count { d: c-name } ." void " lib-modulename 2@ type ." _LTX_" descriptor wrapper-function-name 2dup type drop free throw - .\" (void)\n" + .\" (GFORTH_ARGS)\n" .\" {\n Cell MAYBE_UNUSED *sp = gforth_SP;\n Float MAYBE_UNUSED *fp = gforth_FP;\n " pars c-name 2over count-stacks ret gen-wrapped-stmt .\" ;\n" ?dup-if @@ -496,7 +495,7 @@ create gen-wrapped-types lib-filename 2@ s" .c" s+ 2dup w/o create-file throw dup c-source-file-id ! ['] print-c-prefix-lines swap outfile-execute - drop free throw ; + drop free-c-prefix-lines free throw ; : c-named-library-name ( c-addr u -- ) \ set up filenames for a (possibly new) library; c-addr u is the @@ -505,13 +504,15 @@ create gen-wrapped-types open-wrappers dup if lib-handle-addr @ ! else + libcc-named-dir $1ff mkdir-parents drop drop c-library-name-create endif ; : c-tmp-library-name ( c-addr u -- ) \ set up filenames for a new library; c-addr u is the basename of \ the library - libcc-tmp-dir prepend-dirname c-library-name-setup c-library-name-create ; + libcc-tmp-dir 2dup $1ff mkdir-parents drop + prepend-dirname c-library-name-setup c-library-name-create ; : lib-handle ( -- addr ) lib-handle-addr @ @ ; @@ -553,19 +554,19 @@ DEFER compile-wrapper-function ( -- ) lib-handle 0= if c-source-file close-file throw 0 c-source-file-id ! - [ libtool-command s" --silent --mode=compile --tag=CC " s+ - libtool-cc append s" -I " append - s" includedir" getenv append ] sliteral + [ libtool-command s" --silent --mode=compile " s+ + libtool-cc append s" -I '" append + s" includedir" getenv append s" '" append ] sliteral s" -O -c " s+ lib-filename 2@ append s" .c -o " append lib-filename 2@ append s" .lo" append ( c-addr u ) - \ cr 2dup type + \ 2dup type cr 2dup system drop free throw $? abort" libtool compile failed" - [ libtool-command s" --silent --mode=link --tag=CC " s+ - libtool-cc append s" -module -rpath " s+ ] sliteral + [ libtool-command s" --silent --mode=link " s+ + libtool-cc append libtool-flags append s" -module -rpath " s+ ] sliteral lib-filename 2@ dirname replace-rpath s+ s" " append lib-filename 2@ append s" .lo -o " append lib-filename 2@ append s" .la" append ( c-addr u ) - c-libs @ ['] append-l list-map + c-libs 2@ append \ 2dup type cr 2dup system drop free throw $? abort" libtool link failed" open-wrappers dup 0= if @@ -619,7 +620,7 @@ DEFER compile-wrapper-function ( -- ) c-source-file-id @ if compile-wrapper-function endif - 0 c-libs ! ; + 0. c-libs 2! ; clear-libs : c-library-incomplete ( -- )