--- gforth/libcc.fs 2008/07/27 10:34:06 1.51 +++ 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 +2variable c-libs \ library names in a string (without "lib") -list% - cell% 2* field c-lib-string -end-struct c-lib% - -variable c-libs \ linked list of library names (without "lib") - -: add-lib ( c-addr u -- ) +: 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 @@ -284,7 +283,6 @@ const+ d \ double const+ r \ float const+ func \ C function pointer const+ void -const+ file \ C file pointer drop set-current @@ -301,7 +299,7 @@ set-current parse-libcc-type dup 0< -32 and throw swap c! ; : type-letter ( n -- c ) - chars s" nadrfvF" drop + c@ ; + chars s" nadrfv" drop + c@ ; \ count-stacks @@ -330,7 +328,6 @@ create count-stacks-types ' count-stacks-r , ' count-stacks-func , ' count-stacks-void , -' count-stacks-a , : count-stacks ( pars -- fp-change sp-change ) \ pars is an addr u pair @@ -358,9 +355,6 @@ create count-stacks-types : gen-par-void ( fp-depth1 sp-depth1 -- fp-depth2 sp-depth2 ) -32 throw ; -: gen-par-file ( fp-depth1 sp-depth1 -- fp-depth2 sp-depth2 ) - ." (FILE *)(" gen-par-n ." )" ; - create gen-par-types ' gen-par-n , ' gen-par-a , @@ -368,7 +362,6 @@ create gen-par-types ' gen-par-r , ' gen-par-func , ' gen-par-void , -' gen-par-file , : gen-par ( fp-depth1 sp-depth1 partype -- fp-depth2 sp-depth2 ) cells gen-par-types + @ execute ; @@ -413,7 +406,6 @@ create gen-wrapped-types ' gen-wrapped-r , ' gen-wrapped-func , ' gen-wrapped-void , -' gen-wrapped-a , : gen-wrapped-stmt ( pars c-name fp-change1 sp-change1 ret -- fp-change sp-change ) cells gen-wrapped-types + @ execute ; @@ -438,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 @@ -503,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 @@ -512,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 @ @ ; @@ -560,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 @@ -621,12 +615,12 @@ DEFER compile-wrapper-function ( -- ) defer lastxt dup c-function-rt lastxt c-function-ft lastxt swap defer! ; -: clear-libs ( -- ) +: clear-libs ( -- ) \ gforth \G Clear the list of libs c-source-file-id @ if compile-wrapper-function endif - 0 c-libs ! ; + 0. c-libs 2! ; clear-libs : c-library-incomplete ( -- )