12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382 |
- /*
- * Generate include file dependencies
- *
- * Copyright 1996, 2013, 2020 Alexandre Julliard
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- */
- #include "config.h"
- #define NO_LIBWINE_PORT
- #include "wine/port.h"
- #include <assert.h>
- #include <ctype.h>
- #include <errno.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdarg.h>
- #include <signal.h>
- #include <string.h>
- #ifdef HAVE_UNISTD_H
- # include <unistd.h>
- #endif
- #include "wine/list.h"
- struct strarray
- {
- unsigned int count; /* strings in use */
- unsigned int size; /* total allocated size */
- const char **str;
- };
- enum incl_type
- {
- INCL_NORMAL, /* #include "foo.h" */
- INCL_SYSTEM, /* #include <foo.h> */
- INCL_IMPORT, /* idl import "foo.idl" */
- INCL_IMPORTLIB, /* idl importlib "foo.tlb" */
- INCL_CPP_QUOTE, /* idl cpp_quote("#include \"foo.h\"") */
- INCL_CPP_QUOTE_SYSTEM /* idl cpp_quote("#include <foo.h>") */
- };
- struct dependency
- {
- int line; /* source line where this header is included */
- enum incl_type type; /* type of include */
- char *name; /* header name */
- };
- struct file
- {
- struct list entry;
- char *name; /* full file name relative to cwd */
- void *args; /* custom arguments for makefile rule */
- unsigned int flags; /* flags (see below) */
- unsigned int deps_count; /* files in use */
- unsigned int deps_size; /* total allocated size */
- struct dependency *deps; /* all header dependencies */
- };
- struct incl_file
- {
- struct list entry;
- struct file *file;
- char *name;
- char *filename;
- char *basename; /* base target name for generated files */
- char *sourcename; /* source file name for generated headers */
- struct incl_file *included_by; /* file that included this one */
- int included_line; /* line where this file was included */
- enum incl_type type; /* type of include */
- int use_msvcrt; /* put msvcrt headers in the search path? */
- struct incl_file *owner;
- unsigned int files_count; /* files in use */
- unsigned int files_size; /* total allocated size */
- struct incl_file **files;
- struct strarray dependencies; /* file dependencies */
- };
- #define FLAG_GENERATED 0x000001 /* generated file */
- #define FLAG_INSTALL 0x000002 /* file to install */
- #define FLAG_IDL_PROXY 0x000100 /* generates a proxy (_p.c) file */
- #define FLAG_IDL_CLIENT 0x000200 /* generates a client (_c.c) file */
- #define FLAG_IDL_SERVER 0x000400 /* generates a server (_s.c) file */
- #define FLAG_IDL_IDENT 0x000800 /* generates an ident (_i.c) file */
- #define FLAG_IDL_REGISTER 0x001000 /* generates a registration (_r.res) file */
- #define FLAG_IDL_TYPELIB 0x002000 /* generates a typelib (.tlb) file */
- #define FLAG_IDL_REGTYPELIB 0x004000 /* generates a registered typelib (_t.res) file */
- #define FLAG_IDL_HEADER 0x008000 /* generates a header (.h) file */
- #define FLAG_RC_PO 0x010000 /* rc file contains translations */
- #define FLAG_C_IMPLIB 0x020000 /* file is part of an import library */
- #define FLAG_C_UNIX 0x040000 /* file is part of a Unix library */
- #define FLAG_SFD_FONTS 0x080000 /* sfd file generated bitmap fonts */
- static const struct
- {
- unsigned int flag;
- const char *ext;
- } idl_outputs[] =
- {
- { FLAG_IDL_TYPELIB, ".tlb" },
- { FLAG_IDL_REGTYPELIB, "_t.res" },
- { FLAG_IDL_CLIENT, "_c.c" },
- { FLAG_IDL_IDENT, "_i.c" },
- { FLAG_IDL_PROXY, "_p.c" },
- { FLAG_IDL_SERVER, "_s.c" },
- { FLAG_IDL_REGISTER, "_r.res" },
- { FLAG_IDL_HEADER, ".h" }
- };
- #define HASH_SIZE 997
- static struct list files[HASH_SIZE];
- static const struct strarray empty_strarray;
- enum install_rules { INSTALL_LIB, INSTALL_DEV, NB_INSTALL_RULES };
- /* variables common to all makefiles */
- static struct strarray linguas;
- static struct strarray dll_flags;
- static struct strarray target_flags;
- static struct strarray msvcrt_flags;
- static struct strarray extra_cflags;
- static struct strarray extra_cross_cflags;
- static struct strarray cpp_flags;
- static struct strarray lddll_flags;
- static struct strarray libs;
- static struct strarray enable_tests;
- static struct strarray cmdline_vars;
- static struct strarray subdirs;
- static struct strarray disabled_dirs;
- static struct strarray cross_import_libs;
- static struct strarray delay_import_libs;
- static struct strarray top_install_lib;
- static struct strarray top_install_dev;
- static const char *root_src_dir;
- static const char *tools_dir;
- static const char *tools_ext;
- static const char *exe_ext;
- static const char *dll_ext;
- static const char *man_ext;
- static const char *crosstarget;
- static const char *crossdebug;
- static const char *fontforge;
- static const char *convert;
- static const char *flex;
- static const char *bison;
- static const char *ar;
- static const char *ranlib;
- static const char *rsvg;
- static const char *icotool;
- static const char *dlltool;
- static const char *msgfmt;
- static const char *ln_s;
- static const char *sed_cmd;
- static const char *delay_load_flag;
- struct makefile
- {
- /* values determined from input makefile */
- struct strarray vars;
- struct strarray include_paths;
- struct strarray include_args;
- struct strarray define_args;
- struct strarray programs;
- struct strarray scripts;
- struct strarray imports;
- struct strarray delayimports;
- struct strarray extradllflags;
- struct strarray install_lib;
- struct strarray install_dev;
- struct strarray extra_targets;
- struct strarray extra_imports;
- struct list sources;
- struct list includes;
- const char *src_dir;
- const char *obj_dir;
- const char *parent_dir;
- const char *module;
- const char *testdll;
- const char *sharedlib;
- const char *staticlib;
- const char *staticimplib;
- const char *importlib;
- int disabled;
- int use_msvcrt;
- int is_cross;
- int is_win16;
- int is_exe;
- /* values generated at output time */
- struct strarray in_files;
- struct strarray ok_files;
- struct strarray pot_files;
- struct strarray clean_files;
- struct strarray distclean_files;
- struct strarray uninstall_files;
- struct strarray object_files;
- struct strarray crossobj_files;
- struct strarray unixobj_files;
- struct strarray res_files;
- struct strarray font_files;
- struct strarray c2man_files;
- struct strarray debug_files;
- struct strarray dlldata_files;
- struct strarray implib_objs;
- struct strarray all_targets;
- struct strarray phony_targets;
- struct strarray dependencies;
- struct strarray install_rules[NB_INSTALL_RULES];
- };
- static struct makefile *top_makefile;
- static struct makefile **submakes;
- static const char separator[] = "### Dependencies";
- static const char *output_makefile_name = "Makefile";
- static const char *input_file_name;
- static const char *output_file_name;
- static const char *temp_file_name;
- static int relative_dir_mode;
- static int input_line;
- static int output_column;
- static FILE *output_file;
- static const char Usage[] =
- "Usage: makedep [options] [directories]\n"
- "Options:\n"
- " -R from to Compute the relative path between two directories\n"
- " -fxxx Store output in file 'xxx' (default: Makefile)\n";
- #ifndef __GNUC__
- #define __attribute__(x)
- #endif
- static void fatal_error( const char *msg, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
- static void fatal_perror( const char *msg, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
- static void output( const char *format, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
- static char *strmake( const char* fmt, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
- /*******************************************************************
- * fatal_error
- */
- static void fatal_error( const char *msg, ... )
- {
- va_list valist;
- va_start( valist, msg );
- if (input_file_name)
- {
- fprintf( stderr, "%s:", input_file_name );
- if (input_line) fprintf( stderr, "%d:", input_line );
- fprintf( stderr, " error: " );
- }
- else fprintf( stderr, "makedep: error: " );
- vfprintf( stderr, msg, valist );
- va_end( valist );
- exit(1);
- }
- /*******************************************************************
- * fatal_perror
- */
- static void fatal_perror( const char *msg, ... )
- {
- va_list valist;
- va_start( valist, msg );
- if (input_file_name)
- {
- fprintf( stderr, "%s:", input_file_name );
- if (input_line) fprintf( stderr, "%d:", input_line );
- fprintf( stderr, " error: " );
- }
- else fprintf( stderr, "makedep: error: " );
- vfprintf( stderr, msg, valist );
- perror( " " );
- va_end( valist );
- exit(1);
- }
- /*******************************************************************
- * cleanup_files
- */
- static void cleanup_files(void)
- {
- if (temp_file_name) unlink( temp_file_name );
- if (output_file_name) unlink( output_file_name );
- }
- /*******************************************************************
- * exit_on_signal
- */
- static void exit_on_signal( int sig )
- {
- exit( 1 ); /* this will call the atexit functions */
- }
- /*******************************************************************
- * xmalloc
- */
- static void *xmalloc( size_t size )
- {
- void *res;
- if (!(res = malloc (size ? size : 1)))
- fatal_error( "Virtual memory exhausted.\n" );
- return res;
- }
- /*******************************************************************
- * xrealloc
- */
- static void *xrealloc (void *ptr, size_t size)
- {
- void *res;
- assert( size );
- if (!(res = realloc( ptr, size )))
- fatal_error( "Virtual memory exhausted.\n" );
- return res;
- }
- /*******************************************************************
- * xstrdup
- */
- static char *xstrdup( const char *str )
- {
- char *res = strdup( str );
- if (!res) fatal_error( "Virtual memory exhausted.\n" );
- return res;
- }
- /*******************************************************************
- * strmake
- */
- static char *strmake( const char* fmt, ... )
- {
- int n;
- size_t size = 100;
- va_list ap;
- for (;;)
- {
- char *p = xmalloc (size);
- va_start(ap, fmt);
- n = vsnprintf (p, size, fmt, ap);
- va_end(ap);
- if (n == -1) size *= 2;
- else if ((size_t)n >= size) size = n + 1;
- else return xrealloc( p, n + 1 );
- free(p);
- }
- }
- /*******************************************************************
- * strendswith
- */
- static int strendswith( const char* str, const char* end )
- {
- size_t l = strlen( str );
- size_t m = strlen( end );
- return l >= m && strcmp(str + l - m, end) == 0;
- }
- /*******************************************************************
- * output
- */
- static void output( const char *format, ... )
- {
- int ret;
- va_list valist;
- va_start( valist, format );
- ret = vfprintf( output_file, format, valist );
- va_end( valist );
- if (ret < 0) fatal_perror( "output" );
- if (format[0] && format[strlen(format) - 1] == '\n') output_column = 0;
- else output_column += ret;
- }
- /*******************************************************************
- * strarray_add
- */
- static void strarray_add( struct strarray *array, const char *str )
- {
- if (array->count == array->size)
- {
- if (array->size) array->size *= 2;
- else array->size = 16;
- array->str = xrealloc( array->str, sizeof(array->str[0]) * array->size );
- }
- array->str[array->count++] = str;
- }
- /*******************************************************************
- * strarray_addall
- */
- static void strarray_addall( struct strarray *array, struct strarray added )
- {
- unsigned int i;
- for (i = 0; i < added.count; i++) strarray_add( array, added.str[i] );
- }
- /*******************************************************************
- * strarray_exists
- */
- static int strarray_exists( const struct strarray *array, const char *str )
- {
- unsigned int i;
- for (i = 0; i < array->count; i++) if (!strcmp( array->str[i], str )) return 1;
- return 0;
- }
- /*******************************************************************
- * strarray_add_uniq
- */
- static void strarray_add_uniq( struct strarray *array, const char *str )
- {
- if (!strarray_exists( array, str )) strarray_add( array, str );
- }
- /*******************************************************************
- * strarray_addall_uniq
- */
- static void strarray_addall_uniq( struct strarray *array, struct strarray added )
- {
- unsigned int i;
- for (i = 0; i < added.count; i++) strarray_add_uniq( array, added.str[i] );
- }
- /*******************************************************************
- * strarray_get_value
- *
- * Find a value in a name/value pair string array.
- */
- static const char *strarray_get_value( const struct strarray *array, const char *name )
- {
- int pos, res, min = 0, max = array->count / 2 - 1;
- while (min <= max)
- {
- pos = (min + max) / 2;
- if (!(res = strcmp( array->str[pos * 2], name ))) return array->str[pos * 2 + 1];
- if (res < 0) min = pos + 1;
- else max = pos - 1;
- }
- return NULL;
- }
- /*******************************************************************
- * strarray_set_value
- *
- * Define a value in a name/value pair string array.
- */
- static void strarray_set_value( struct strarray *array, const char *name, const char *value )
- {
- int i, pos, res, min = 0, max = array->count / 2 - 1;
- while (min <= max)
- {
- pos = (min + max) / 2;
- if (!(res = strcmp( array->str[pos * 2], name )))
- {
- /* redefining a variable replaces the previous value */
- array->str[pos * 2 + 1] = value;
- return;
- }
- if (res < 0) min = pos + 1;
- else max = pos - 1;
- }
- strarray_add( array, NULL );
- strarray_add( array, NULL );
- for (i = array->count - 1; i > min * 2 + 1; i--) array->str[i] = array->str[i - 2];
- array->str[min * 2] = name;
- array->str[min * 2 + 1] = value;
- }
- /*******************************************************************
- * strarray_set_qsort
- */
- static void strarray_qsort( struct strarray *array, int (*func)(const char **, const char **) )
- {
- if (array->count) qsort( array->str, array->count, sizeof(*array->str), (void *)func );
- }
- /*******************************************************************
- * output_filename
- */
- static void output_filename( const char *name )
- {
- if (output_column + strlen(name) + 1 > 100)
- {
- output( " \\\n" );
- output( " " );
- }
- else if (output_column) output( " " );
- output( "%s", name );
- }
- /*******************************************************************
- * output_filenames
- */
- static void output_filenames( struct strarray array )
- {
- unsigned int i;
- for (i = 0; i < array.count; i++) output_filename( array.str[i] );
- }
- /*******************************************************************
- * output_rm_filenames
- */
- static void output_rm_filenames( struct strarray array )
- {
- static const unsigned int max_cmdline = 30000; /* to be on the safe side */
- unsigned int i, len;
- if (!array.count) return;
- output( "\trm -f" );
- for (i = len = 0; i < array.count; i++)
- {
- if (len > max_cmdline)
- {
- output( "\n" );
- output( "\trm -f" );
- len = 0;
- }
- output_filename( array.str[i] );
- len += strlen( array.str[i] ) + 1;
- }
- output( "\n" );
- }
- /*******************************************************************
- * get_extension
- */
- static char *get_extension( char *filename )
- {
- char *ext = strrchr( filename, '.' );
- if (ext && strchr( ext, '/' )) ext = NULL;
- return ext;
- }
- /*******************************************************************
- * get_base_name
- */
- static const char *get_base_name( const char *name )
- {
- char *base;
- if (!strchr( name, '.' )) return name;
- base = strdup( name );
- *strrchr( base, '.' ) = 0;
- return base;
- }
- /*******************************************************************
- * replace_extension
- */
- static char *replace_extension( const char *name, const char *old_ext, const char *new_ext )
- {
- char *ret;
- size_t name_len = strlen( name );
- size_t ext_len = strlen( old_ext );
- if (name_len >= ext_len && !strcmp( name + name_len - ext_len, old_ext )) name_len -= ext_len;
- ret = xmalloc( name_len + strlen( new_ext ) + 1 );
- memcpy( ret, name, name_len );
- strcpy( ret + name_len, new_ext );
- return ret;
- }
- /*******************************************************************
- * replace_filename
- */
- static char *replace_filename( const char *path, const char *name )
- {
- const char *p;
- char *ret;
- size_t len;
- if (!path) return xstrdup( name );
- if (!(p = strrchr( path, '/' ))) return xstrdup( name );
- len = p - path + 1;
- ret = xmalloc( len + strlen( name ) + 1 );
- memcpy( ret, path, len );
- strcpy( ret + len, name );
- return ret;
- }
- /*******************************************************************
- * strarray_replace_extension
- */
- static struct strarray strarray_replace_extension( const struct strarray *array,
- const char *old_ext, const char *new_ext )
- {
- unsigned int i;
- struct strarray ret;
- ret.count = ret.size = array->count;
- ret.str = xmalloc( sizeof(ret.str[0]) * ret.size );
- for (i = 0; i < array->count; i++) ret.str[i] = replace_extension( array->str[i], old_ext, new_ext );
- return ret;
- }
- /*******************************************************************
- * replace_substr
- */
- static char *replace_substr( const char *str, const char *start, size_t len, const char *replace )
- {
- size_t pos = start - str;
- char *ret = xmalloc( pos + strlen(replace) + strlen(start + len) + 1 );
- memcpy( ret, str, pos );
- strcpy( ret + pos, replace );
- strcat( ret + pos, start + len );
- return ret;
- }
- /*******************************************************************
- * get_relative_path
- *
- * Determine where the destination path is located relative to the 'from' path.
- */
- static char *get_relative_path( const char *from, const char *dest )
- {
- const char *start;
- char *ret, *p;
- unsigned int dotdots = 0;
- /* a path of "." is equivalent to an empty path */
- if (!strcmp( from, "." )) from = "";
- for (;;)
- {
- while (*from == '/') from++;
- while (*dest == '/') dest++;
- start = dest; /* save start of next path element */
- if (!*from) break;
- while (*from && *from != '/' && *from == *dest) { from++; dest++; }
- if ((!*from || *from == '/') && (!*dest || *dest == '/')) continue;
- /* count remaining elements in 'from' */
- do
- {
- dotdots++;
- while (*from && *from != '/') from++;
- while (*from == '/') from++;
- }
- while (*from);
- break;
- }
- if (!start[0] && !dotdots) return NULL; /* empty path */
- ret = xmalloc( 3 * dotdots + strlen( start ) + 1 );
- for (p = ret; dotdots; dotdots--, p += 3) memcpy( p, "../", 3 );
- if (start[0]) strcpy( p, start );
- else p[-1] = 0; /* remove trailing slash */
- return ret;
- }
- /*******************************************************************
- * concat_paths
- */
- static char *concat_paths( const char *base, const char *path )
- {
- int i, len;
- char *ret;
- if (!base || !base[0]) return xstrdup( path && path[0] ? path : "." );
- if (!path || !path[0]) return xstrdup( base );
- if (path[0] == '/') return xstrdup( path );
- len = strlen( base );
- while (len && base[len - 1] == '/') len--;
- while (len && !strncmp( path, "..", 2 ) && (!path[2] || path[2] == '/'))
- {
- for (i = len; i > 0; i--) if (base[i - 1] == '/') break;
- if (i == len - 2 && !memcmp( base + i, "..", 2 )) break; /* we can't go up if we already have ".." */
- if (i != len - 1 || base[i] != '.')
- {
- path += 2;
- while (*path == '/') path++;
- }
- /* else ignore "." element */
- while (i > 0 && base[i - 1] == '/') i--;
- len = i;
- }
- if (!len && base[0] != '/') return xstrdup( path[0] ? path : "." );
- ret = xmalloc( len + strlen( path ) + 2 );
- memcpy( ret, base, len );
- ret[len++] = '/';
- strcpy( ret + len, path );
- return ret;
- }
- /*******************************************************************
- * obj_dir_path
- */
- static char *obj_dir_path( const struct makefile *make, const char *path )
- {
- return concat_paths( make->obj_dir, path );
- }
- /*******************************************************************
- * src_dir_path
- */
- static char *src_dir_path( const struct makefile *make, const char *path )
- {
- if (make->src_dir) return concat_paths( make->src_dir, path );
- return obj_dir_path( make, path );
- }
- /*******************************************************************
- * root_src_dir_path
- */
- static char *root_src_dir_path( const char *path )
- {
- return concat_paths( root_src_dir, path );
- }
- /*******************************************************************
- * tools_dir_path
- */
- static char *tools_dir_path( const struct makefile *make, const char *path )
- {
- if (tools_dir) return strmake( "%s/tools/%s", tools_dir, path );
- return strmake( "tools/%s", path );
- }
- /*******************************************************************
- * tools_path
- */
- static char *tools_path( const struct makefile *make, const char *name )
- {
- return strmake( "%s/%s%s", tools_dir_path( make, name ), name, tools_ext );
- }
- /*******************************************************************
- * strarray_addall_path
- */
- static void strarray_addall_path( struct strarray *array, const char *dir, struct strarray added )
- {
- unsigned int i;
- for (i = 0; i < added.count; i++) strarray_add( array, concat_paths( dir, added.str[i] ));
- }
- /*******************************************************************
- * get_line
- */
- static char *get_line( FILE *file )
- {
- static char *buffer;
- static size_t size;
- if (!size)
- {
- size = 1024;
- buffer = xmalloc( size );
- }
- if (!fgets( buffer, size, file )) return NULL;
- input_line++;
- for (;;)
- {
- char *p = buffer + strlen(buffer);
- /* if line is larger than buffer, resize buffer */
- while (p == buffer + size - 1 && p[-1] != '\n')
- {
- buffer = xrealloc( buffer, size * 2 );
- if (!fgets( buffer + size - 1, size + 1, file )) break;
- p = buffer + strlen(buffer);
- size *= 2;
- }
- if (p > buffer && p[-1] == '\n')
- {
- *(--p) = 0;
- if (p > buffer && p[-1] == '\r') *(--p) = 0;
- if (p > buffer && p[-1] == '\\')
- {
- *(--p) = 0;
- /* line ends in backslash, read continuation line */
- if (!fgets( p, size - (p - buffer), file )) return buffer;
- input_line++;
- continue;
- }
- }
- return buffer;
- }
- }
- /*******************************************************************
- * hash_filename
- */
- static unsigned int hash_filename( const char *name )
- {
- /* FNV-1 hash */
- unsigned int ret = 2166136261u;
- while (*name) ret = (ret * 16777619) ^ *name++;
- return ret % HASH_SIZE;
- }
- /*******************************************************************
- * add_file
- */
- static struct file *add_file( const char *name )
- {
- struct file *file = xmalloc( sizeof(*file) );
- memset( file, 0, sizeof(*file) );
- file->name = xstrdup( name );
- return file;
- }
- /*******************************************************************
- * add_dependency
- */
- static void add_dependency( struct file *file, const char *name, enum incl_type type )
- {
- /* enforce some rules for the Wine tree */
- if (!memcmp( name, "../", 3 ))
- fatal_error( "#include directive with relative path not allowed\n" );
- if (!strcmp( name, "config.h" ))
- {
- if (strendswith( file->name, ".h" ))
- fatal_error( "config.h must not be included by a header file\n" );
- if (file->deps_count)
- fatal_error( "config.h must be included before anything else\n" );
- }
- else if (!strcmp( name, "wine/port.h" ))
- {
- if (strendswith( file->name, ".h" ))
- fatal_error( "wine/port.h must not be included by a header file\n" );
- if (!file->deps_count) fatal_error( "config.h must be included before wine/port.h\n" );
- if (file->deps_count > 1)
- fatal_error( "wine/port.h must be included before everything except config.h\n" );
- if (strcmp( file->deps[0].name, "config.h" ))
- fatal_error( "config.h must be included before wine/port.h\n" );
- }
- if (file->deps_count >= file->deps_size)
- {
- file->deps_size *= 2;
- if (file->deps_size < 16) file->deps_size = 16;
- file->deps = xrealloc( file->deps, file->deps_size * sizeof(*file->deps) );
- }
- file->deps[file->deps_count].line = input_line;
- file->deps[file->deps_count].type = type;
- file->deps[file->deps_count].name = xstrdup( name );
- file->deps_count++;
- }
- /*******************************************************************
- * find_src_file
- */
- static struct incl_file *find_src_file( const struct makefile *make, const char *name )
- {
- struct incl_file *file;
- LIST_FOR_EACH_ENTRY( file, &make->sources, struct incl_file, entry )
- if (!strcmp( name, file->name )) return file;
- return NULL;
- }
- /*******************************************************************
- * find_include_file
- */
- static struct incl_file *find_include_file( const struct makefile *make, const char *name )
- {
- struct incl_file *file;
- LIST_FOR_EACH_ENTRY( file, &make->includes, struct incl_file, entry )
- if (!strcmp( name, file->name )) return file;
- return NULL;
- }
- /*******************************************************************
- * add_include
- *
- * Add an include file if it doesn't already exists.
- */
- static struct incl_file *add_include( struct makefile *make, struct incl_file *parent,
- const char *name, int line, enum incl_type type )
- {
- struct incl_file *include;
- if (parent->files_count >= parent->files_size)
- {
- parent->files_size *= 2;
- if (parent->files_size < 16) parent->files_size = 16;
- parent->files = xrealloc( parent->files, parent->files_size * sizeof(*parent->files) );
- }
- LIST_FOR_EACH_ENTRY( include, &make->includes, struct incl_file, entry )
- if (!parent->use_msvcrt == !include->use_msvcrt && !strcmp( name, include->name ))
- goto found;
- include = xmalloc( sizeof(*include) );
- memset( include, 0, sizeof(*include) );
- include->name = xstrdup(name);
- include->included_by = parent;
- include->included_line = line;
- include->type = type;
- include->use_msvcrt = parent->use_msvcrt;
- list_add_tail( &make->includes, &include->entry );
- found:
- parent->files[parent->files_count++] = include;
- return include;
- }
- /*******************************************************************
- * add_generated_source
- *
- * Add a generated source file to the list.
- */
- static struct incl_file *add_generated_source( struct makefile *make,
- const char *name, const char *filename )
- {
- struct incl_file *file;
- if ((file = find_src_file( make, name ))) return file; /* we already have it */
- file = xmalloc( sizeof(*file) );
- memset( file, 0, sizeof(*file) );
- file->file = add_file( name );
- file->name = xstrdup( name );
- file->basename = xstrdup( filename ? filename : name );
- file->filename = obj_dir_path( make, file->basename );
- file->file->flags = FLAG_GENERATED;
- file->use_msvcrt = make->use_msvcrt;
- list_add_tail( &make->sources, &file->entry );
- return file;
- }
- /*******************************************************************
- * parse_include_directive
- */
- static void parse_include_directive( struct file *source, char *str )
- {
- char quote, *include, *p = str;
- while (*p && isspace(*p)) p++;
- if (*p != '\"' && *p != '<' ) return;
- quote = *p++;
- if (quote == '<') quote = '>';
- include = p;
- while (*p && (*p != quote)) p++;
- if (!*p) fatal_error( "malformed include directive '%s'\n", str );
- *p = 0;
- add_dependency( source, include, (quote == '>') ? INCL_SYSTEM : INCL_NORMAL );
- }
- /*******************************************************************
- * parse_pragma_directive
- */
- static void parse_pragma_directive( struct file *source, char *str )
- {
- char *flag, *p = str;
- if (!isspace( *p )) return;
- while (*p && isspace(*p)) p++;
- p = strtok( p, " \t" );
- if (strcmp( p, "makedep" )) return;
- while ((flag = strtok( NULL, " \t" )))
- {
- if (!strcmp( flag, "depend" ))
- {
- while ((p = strtok( NULL, " \t" ))) add_dependency( source, p, INCL_NORMAL );
- return;
- }
- else if (!strcmp( flag, "install" )) source->flags |= FLAG_INSTALL;
- if (strendswith( source->name, ".idl" ))
- {
- if (!strcmp( flag, "header" )) source->flags |= FLAG_IDL_HEADER;
- else if (!strcmp( flag, "proxy" )) source->flags |= FLAG_IDL_PROXY;
- else if (!strcmp( flag, "client" )) source->flags |= FLAG_IDL_CLIENT;
- else if (!strcmp( flag, "server" )) source->flags |= FLAG_IDL_SERVER;
- else if (!strcmp( flag, "ident" )) source->flags |= FLAG_IDL_IDENT;
- else if (!strcmp( flag, "typelib" )) source->flags |= FLAG_IDL_TYPELIB;
- else if (!strcmp( flag, "register" )) source->flags |= FLAG_IDL_REGISTER;
- else if (!strcmp( flag, "regtypelib" )) source->flags |= FLAG_IDL_REGTYPELIB;
- }
- else if (strendswith( source->name, ".rc" ))
- {
- if (!strcmp( flag, "po" )) source->flags |= FLAG_RC_PO;
- }
- else if (strendswith( source->name, ".sfd" ))
- {
- if (!strcmp( flag, "font" ))
- {
- struct strarray *array = source->args;
- if (!array)
- {
- source->args = array = xmalloc( sizeof(*array) );
- *array = empty_strarray;
- source->flags |= FLAG_SFD_FONTS;
- }
- strarray_add( array, xstrdup( strtok( NULL, "" )));
- return;
- }
- }
- else
- {
- if (!strcmp( flag, "implib" )) source->flags |= FLAG_C_IMPLIB;
- if (!strcmp( flag, "unix" )) source->flags |= FLAG_C_UNIX;
- }
- }
- }
- /*******************************************************************
- * parse_cpp_directive
- */
- static void parse_cpp_directive( struct file *source, char *str )
- {
- while (*str && isspace(*str)) str++;
- if (*str++ != '#') return;
- while (*str && isspace(*str)) str++;
- if (!strncmp( str, "include", 7 ))
- parse_include_directive( source, str + 7 );
- else if (!strncmp( str, "import", 6 ) && strendswith( source->name, ".m" ))
- parse_include_directive( source, str + 6 );
- else if (!strncmp( str, "pragma", 6 ))
- parse_pragma_directive( source, str + 6 );
- }
- /*******************************************************************
- * parse_idl_file
- */
- static void parse_idl_file( struct file *source, FILE *file )
- {
- char *buffer, *include;
- input_line = 0;
- while ((buffer = get_line( file )))
- {
- char quote;
- char *p = buffer;
- while (*p && isspace(*p)) p++;
- if (!strncmp( p, "importlib", 9 ))
- {
- p += 9;
- while (*p && isspace(*p)) p++;
- if (*p++ != '(') continue;
- while (*p && isspace(*p)) p++;
- if (*p++ != '"') continue;
- include = p;
- while (*p && (*p != '"')) p++;
- if (!*p) fatal_error( "malformed importlib directive\n" );
- *p = 0;
- add_dependency( source, include, INCL_IMPORTLIB );
- continue;
- }
- if (!strncmp( p, "import", 6 ))
- {
- p += 6;
- while (*p && isspace(*p)) p++;
- if (*p != '"') continue;
- include = ++p;
- while (*p && (*p != '"')) p++;
- if (!*p) fatal_error( "malformed import directive\n" );
- *p = 0;
- add_dependency( source, include, INCL_IMPORT );
- continue;
- }
- /* check for #include inside cpp_quote */
- if (!strncmp( p, "cpp_quote", 9 ))
- {
- p += 9;
- while (*p && isspace(*p)) p++;
- if (*p++ != '(') continue;
- while (*p && isspace(*p)) p++;
- if (*p++ != '"') continue;
- if (*p++ != '#') continue;
- while (*p && isspace(*p)) p++;
- if (strncmp( p, "include", 7 )) continue;
- p += 7;
- while (*p && isspace(*p)) p++;
- if (*p == '\\' && p[1] == '"')
- {
- p += 2;
- quote = '"';
- }
- else
- {
- if (*p++ != '<' ) continue;
- quote = '>';
- }
- include = p;
- while (*p && (*p != quote)) p++;
- if (!*p || (quote == '"' && p[-1] != '\\'))
- fatal_error( "malformed #include directive inside cpp_quote\n" );
- if (quote == '"') p--; /* remove backslash */
- *p = 0;
- add_dependency( source, include, (quote == '>') ? INCL_CPP_QUOTE_SYSTEM : INCL_CPP_QUOTE );
- continue;
- }
- parse_cpp_directive( source, p );
- }
- }
- /*******************************************************************
- * parse_c_file
- */
- static void parse_c_file( struct file *source, FILE *file )
- {
- char *buffer;
- input_line = 0;
- while ((buffer = get_line( file )))
- {
- parse_cpp_directive( source, buffer );
- }
- }
- /*******************************************************************
- * parse_rc_file
- */
- static void parse_rc_file( struct file *source, FILE *file )
- {
- char *buffer, *include;
- input_line = 0;
- while ((buffer = get_line( file )))
- {
- char quote;
- char *p = buffer;
- while (*p && isspace(*p)) p++;
- if (p[0] == '/' && p[1] == '*') /* check for magic makedep comment */
- {
- p += 2;
- while (*p && isspace(*p)) p++;
- if (strncmp( p, "@makedep:", 9 )) continue;
- p += 9;
- while (*p && isspace(*p)) p++;
- quote = '"';
- if (*p == quote)
- {
- include = ++p;
- while (*p && *p != quote) p++;
- }
- else
- {
- include = p;
- while (*p && !isspace(*p) && *p != '*') p++;
- }
- if (!*p)
- fatal_error( "malformed makedep comment\n" );
- *p = 0;
- add_dependency( source, include, (quote == '>') ? INCL_SYSTEM : INCL_NORMAL );
- continue;
- }
- parse_cpp_directive( source, buffer );
- }
- }
- /*******************************************************************
- * parse_in_file
- */
- static void parse_in_file( struct file *source, FILE *file )
- {
- char *p, *buffer;
- /* make sure it gets rebuilt when the version changes */
- add_dependency( source, "config.h", INCL_SYSTEM );
- if (!strendswith( source->name, ".man.in" )) return; /* not a man page */
- input_line = 0;
- while ((buffer = get_line( file )))
- {
- if (strncmp( buffer, ".TH", 3 )) continue;
- if (!(p = strtok( buffer, " \t" ))) continue; /* .TH */
- if (!(p = strtok( NULL, " \t" ))) continue; /* program name */
- if (!(p = strtok( NULL, " \t" ))) continue; /* man section */
- source->args = xstrdup( p );
- return;
- }
- }
- /*******************************************************************
- * parse_sfd_file
- */
- static void parse_sfd_file( struct file *source, FILE *file )
- {
- char *p, *eol, *buffer;
- input_line = 0;
- while ((buffer = get_line( file )))
- {
- if (strncmp( buffer, "UComments:", 10 )) continue;
- p = buffer + 10;
- while (*p == ' ') p++;
- if (p[0] == '"' && p[1] && buffer[strlen(buffer) - 1] == '"')
- {
- p++;
- buffer[strlen(buffer) - 1] = 0;
- }
- while ((eol = strstr( p, "+AAoA" )))
- {
- *eol = 0;
- while (*p && isspace(*p)) p++;
- if (*p++ == '#')
- {
- while (*p && isspace(*p)) p++;
- if (!strncmp( p, "pragma", 6 )) parse_pragma_directive( source, p + 6 );
- }
- p = eol + 5;
- }
- while (*p && isspace(*p)) p++;
- if (*p++ != '#') return;
- while (*p && isspace(*p)) p++;
- if (!strncmp( p, "pragma", 6 )) parse_pragma_directive( source, p + 6 );
- return;
- }
- }
- static const struct
- {
- const char *ext;
- void (*parse)( struct file *file, FILE *f );
- } parse_functions[] =
- {
- { ".c", parse_c_file },
- { ".h", parse_c_file },
- { ".inl", parse_c_file },
- { ".l", parse_c_file },
- { ".m", parse_c_file },
- { ".rh", parse_c_file },
- { ".x", parse_c_file },
- { ".y", parse_c_file },
- { ".idl", parse_idl_file },
- { ".rc", parse_rc_file },
- { ".in", parse_in_file },
- { ".sfd", parse_sfd_file }
- };
- /*******************************************************************
- * load_file
- */
- static struct file *load_file( const char *name )
- {
- struct file *file;
- FILE *f;
- unsigned int i, hash = hash_filename( name );
- LIST_FOR_EACH_ENTRY( file, &files[hash], struct file, entry )
- if (!strcmp( name, file->name )) return file;
- if (!(f = fopen( name, "r" ))) return NULL;
- file = add_file( name );
- list_add_tail( &files[hash], &file->entry );
- input_file_name = file->name;
- input_line = 0;
- for (i = 0; i < sizeof(parse_functions) / sizeof(parse_functions[0]); i++)
- {
- if (!strendswith( name, parse_functions[i].ext )) continue;
- parse_functions[i].parse( file, f );
- break;
- }
- fclose( f );
- input_file_name = NULL;
- return file;
- }
- /*******************************************************************
- * open_include_path_file
- *
- * Open a file from a directory on the include path.
- */
- static struct file *open_include_path_file( const struct makefile *make, const char *dir,
- const char *name, char **filename )
- {
- char *src_path = concat_paths( dir, name );
- struct file *ret = load_file( src_path );
- if (ret) *filename = src_path;
- return ret;
- }
- /*******************************************************************
- * open_file_same_dir
- *
- * Open a file in the same directory as the parent.
- */
- static struct file *open_file_same_dir( const struct incl_file *parent, const char *name, char **filename )
- {
- char *src_path = replace_filename( parent->file->name, name );
- struct file *ret = load_file( src_path );
- if (ret) *filename = replace_filename( parent->filename, name );
- return ret;
- }
- /*******************************************************************
- * open_local_file
- *
- * Open a file in the source directory of the makefile.
- */
- static struct file *open_local_file( const struct makefile *make, const char *path, char **filename )
- {
- char *src_path = src_dir_path( make, path );
- struct file *ret = load_file( src_path );
- /* if not found, try parent dir */
- if (!ret && make->parent_dir)
- {
- free( src_path );
- path = strmake( "%s/%s", make->parent_dir, path );
- src_path = src_dir_path( make, path );
- ret = load_file( src_path );
- }
- if (ret) *filename = src_path;
- return ret;
- }
- /*******************************************************************
- * open_global_file
- *
- * Open a file in the top-level source directory.
- */
- static struct file *open_global_file( const struct makefile *make, const char *path, char **filename )
- {
- char *src_path = root_src_dir_path( path );
- struct file *ret = load_file( src_path );
- if (ret) *filename = src_path;
- return ret;
- }
- /*******************************************************************
- * open_global_header
- *
- * Open a file in the global include source directory.
- */
- static struct file *open_global_header( const struct makefile *make, const char *path, char **filename )
- {
- return open_global_file( make, strmake( "include/%s", path ), filename );
- }
- /*******************************************************************
- * open_src_file
- */
- static struct file *open_src_file( const struct makefile *make, struct incl_file *pFile )
- {
- struct file *file = open_local_file( make, pFile->name, &pFile->filename );
- if (!file) fatal_perror( "open %s", pFile->name );
- return file;
- }
- /*******************************************************************
- * open_include_file
- */
- static struct file *open_include_file( const struct makefile *make, struct incl_file *pFile )
- {
- struct file *file = NULL;
- char *filename;
- unsigned int i, len;
- errno = ENOENT;
- /* check for generated bison header */
- if (strendswith( pFile->name, ".tab.h" ) &&
- (file = open_local_file( make, replace_extension( pFile->name, ".tab.h", ".y" ), &filename )))
- {
- pFile->sourcename = filename;
- pFile->filename = obj_dir_path( make, pFile->name );
- return file;
- }
- /* check for corresponding idl file in source dir */
- if (strendswith( pFile->name, ".h" ) &&
- (file = open_local_file( make, replace_extension( pFile->name, ".h", ".idl" ), &filename )))
- {
- pFile->sourcename = filename;
- pFile->filename = obj_dir_path( make, pFile->name );
- return file;
- }
- /* check for corresponding tlb file in source dir */
- if (strendswith( pFile->name, ".tlb" ) &&
- (file = open_local_file( make, replace_extension( pFile->name, ".tlb", ".idl" ), &filename )))
- {
- pFile->sourcename = filename;
- pFile->filename = obj_dir_path( make, pFile->name );
- return file;
- }
- /* check for extra targets */
- if (strarray_exists( &make->extra_targets, pFile->name ))
- {
- pFile->sourcename = src_dir_path( make, pFile->name );
- pFile->filename = obj_dir_path( make, pFile->name );
- return NULL;
- }
- /* now try in source dir */
- if ((file = open_local_file( make, pFile->name, &pFile->filename ))) return file;
- /* check for corresponding idl file in global includes */
- if (strendswith( pFile->name, ".h" ) &&
- (file = open_global_header( make, replace_extension( pFile->name, ".h", ".idl" ), &filename )))
- {
- pFile->sourcename = filename;
- pFile->filename = strmake( "include/%s", pFile->name );
- return file;
- }
- /* check for corresponding .in file in global includes (for config.h.in) */
- if (strendswith( pFile->name, ".h" ) &&
- (file = open_global_header( make, replace_extension( pFile->name, ".h", ".h.in" ), &filename )))
- {
- pFile->sourcename = filename;
- pFile->filename = strmake( "include/%s", pFile->name );
- return file;
- }
- /* check for corresponding .x file in global includes */
- if (strendswith( pFile->name, "tmpl.h" ) &&
- (file = open_global_header( make, replace_extension( pFile->name, ".h", ".x" ), &filename )))
- {
- pFile->sourcename = filename;
- pFile->filename = strmake( "include/%s", pFile->name );
- return file;
- }
- /* check for corresponding .tlb file in global includes */
- if (strendswith( pFile->name, ".tlb" ) &&
- (file = open_global_header( make, replace_extension( pFile->name, ".tlb", ".idl" ), &filename )))
- {
- pFile->sourcename = filename;
- pFile->filename = strmake( "include/%s", pFile->name );
- return file;
- }
- /* check in global includes source dir */
- if ((file = open_global_header( make, pFile->name, &pFile->filename ))) return file;
- /* check in global msvcrt includes */
- if (pFile->use_msvcrt &&
- (file = open_global_header( make, strmake( "msvcrt/%s", pFile->name ), &pFile->filename )))
- return file;
- /* now search in include paths */
- for (i = 0; i < make->include_paths.count; i++)
- {
- const char *dir = make->include_paths.str[i];
- if (root_src_dir)
- {
- len = strlen( root_src_dir );
- if (!strncmp( dir, root_src_dir, len ) && (!dir[len] || dir[len] == '/'))
- {
- while (dir[len] == '/') len++;
- file = open_global_file( make, concat_paths( dir + len, pFile->name ), &pFile->filename );
- if (file) return file;
- }
- continue; /* ignore paths that don't point to the top source dir */
- }
- if (*dir != '/')
- {
- if ((file = open_include_path_file( make, dir, pFile->name, &pFile->filename )))
- return file;
- }
- }
- if (pFile->type == INCL_SYSTEM && pFile->use_msvcrt)
- {
- if (!strcmp( pFile->name, "stdarg.h" )) return NULL;
- fprintf( stderr, "%s:%d: error: system header %s cannot be used with msvcrt\n",
- pFile->included_by->file->name, pFile->included_line, pFile->name );
- exit(1);
- }
- if (pFile->type == INCL_SYSTEM) return NULL; /* ignore system files we cannot find */
- /* try in src file directory */
- if ((file = open_file_same_dir( pFile->included_by, pFile->name, &pFile->filename ))) return file;
- fprintf( stderr, "%s:%d: error: ", pFile->included_by->file->name, pFile->included_line );
- perror( pFile->name );
- pFile = pFile->included_by;
- while (pFile && pFile->included_by)
- {
- const char *parent = pFile->included_by->sourcename;
- if (!parent) parent = pFile->included_by->file->name;
- fprintf( stderr, "%s:%d: note: %s was first included here\n",
- parent, pFile->included_line, pFile->name );
- pFile = pFile->included_by;
- }
- exit(1);
- }
- /*******************************************************************
- * add_all_includes
- */
- static void add_all_includes( struct makefile *make, struct incl_file *parent, struct file *file )
- {
- unsigned int i;
- parent->files_count = 0;
- parent->files_size = file->deps_count;
- parent->files = xmalloc( parent->files_size * sizeof(*parent->files) );
- for (i = 0; i < file->deps_count; i++)
- {
- switch (file->deps[i].type)
- {
- case INCL_NORMAL:
- case INCL_IMPORT:
- add_include( make, parent, file->deps[i].name, file->deps[i].line, INCL_NORMAL );
- break;
- case INCL_IMPORTLIB:
- add_include( make, parent, file->deps[i].name, file->deps[i].line, INCL_IMPORTLIB );
- break;
- case INCL_SYSTEM:
- add_include( make, parent, file->deps[i].name, file->deps[i].line, INCL_SYSTEM );
- break;
- case INCL_CPP_QUOTE:
- case INCL_CPP_QUOTE_SYSTEM:
- break;
- }
- }
- }
- /*******************************************************************
- * parse_file
- */
- static void parse_file( struct makefile *make, struct incl_file *source, int src )
- {
- struct file *file = src ? open_src_file( make, source ) : open_include_file( make, source );
- if (!file) return;
- source->file = file;
- source->files_count = 0;
- source->files_size = file->deps_count;
- source->files = xmalloc( source->files_size * sizeof(*source->files) );
- if (file->flags & FLAG_C_UNIX) source->use_msvcrt = 0;
- else if (file->flags & FLAG_C_IMPLIB) source->use_msvcrt = 1;
- if (source->sourcename)
- {
- if (strendswith( source->sourcename, ".idl" ))
- {
- unsigned int i;
- if (strendswith( source->name, ".tlb" )) return; /* typelibs don't include anything */
- /* generated .h file always includes these */
- add_include( make, source, "rpc.h", 0, INCL_NORMAL );
- add_include( make, source, "rpcndr.h", 0, INCL_NORMAL );
- for (i = 0; i < file->deps_count; i++)
- {
- switch (file->deps[i].type)
- {
- case INCL_IMPORT:
- if (strendswith( file->deps[i].name, ".idl" ))
- add_include( make, source, replace_extension( file->deps[i].name, ".idl", ".h" ),
- file->deps[i].line, INCL_NORMAL );
- else
- add_include( make, source, file->deps[i].name, file->deps[i].line, INCL_NORMAL );
- break;
- case INCL_CPP_QUOTE:
- add_include( make, source, file->deps[i].name, file->deps[i].line, INCL_NORMAL );
- break;
- case INCL_CPP_QUOTE_SYSTEM:
- add_include( make, source, file->deps[i].name, file->deps[i].line, INCL_SYSTEM );
- break;
- case INCL_NORMAL:
- case INCL_SYSTEM:
- case INCL_IMPORTLIB:
- break;
- }
- }
- return;
- }
- if (strendswith( source->sourcename, ".y" ))
- return; /* generated .tab.h doesn't include anything */
- }
- add_all_includes( make, source, file );
- }
- /*******************************************************************
- * add_src_file
- *
- * Add a source file to the list.
- */
- static struct incl_file *add_src_file( struct makefile *make, const char *name )
- {
- struct incl_file *file;
- if ((file = find_src_file( make, name ))) return file; /* we already have it */
- file = xmalloc( sizeof(*file) );
- memset( file, 0, sizeof(*file) );
- file->name = xstrdup(name);
- file->use_msvcrt = make->use_msvcrt;
- list_add_tail( &make->sources, &file->entry );
- parse_file( make, file, 1 );
- return file;
- }
- /*******************************************************************
- * open_input_makefile
- */
- static FILE *open_input_makefile( const struct makefile *make )
- {
- FILE *ret;
- if (make->obj_dir)
- input_file_name = root_src_dir_path( obj_dir_path( make, strmake( "%s.in", output_makefile_name )));
- else
- input_file_name = output_makefile_name; /* always use output name for main Makefile */
- input_line = 0;
- if (!(ret = fopen( input_file_name, "r" ))) fatal_perror( "open" );
- return ret;
- }
- /*******************************************************************
- * get_make_variable
- */
- static const char *get_make_variable( const struct makefile *make, const char *name )
- {
- const char *ret;
- if ((ret = strarray_get_value( &cmdline_vars, name ))) return ret;
- if ((ret = strarray_get_value( &make->vars, name ))) return ret;
- if (top_makefile && (ret = strarray_get_value( &top_makefile->vars, name ))) return ret;
- return NULL;
- }
- /*******************************************************************
- * get_expanded_make_variable
- */
- static char *get_expanded_make_variable( const struct makefile *make, const char *name )
- {
- const char *var;
- char *p, *end, *expand, *tmp;
- var = get_make_variable( make, name );
- if (!var) return NULL;
- p = expand = xstrdup( var );
- while ((p = strchr( p, '$' )))
- {
- if (p[1] == '(')
- {
- if (!(end = strchr( p + 2, ')' ))) fatal_error( "syntax error in '%s'\n", expand );
- *end++ = 0;
- if (strchr( p + 2, ':' )) fatal_error( "pattern replacement not supported for '%s'\n", p + 2 );
- var = get_make_variable( make, p + 2 );
- tmp = replace_substr( expand, p, end - p, var ? var : "" );
- /* switch to the new string */
- p = tmp + (p - expand);
- free( expand );
- expand = tmp;
- }
- else if (p[1] == '{') /* don't expand ${} variables */
- {
- if (!(end = strchr( p + 2, '}' ))) fatal_error( "syntax error in '%s'\n", expand );
- p = end + 1;
- }
- else if (p[1] == '$')
- {
- p += 2;
- }
- else fatal_error( "syntax error in '%s'\n", expand );
- }
- /* consider empty variables undefined */
- p = expand;
- while (*p && isspace(*p)) p++;
- if (*p) return expand;
- free( expand );
- return NULL;
- }
- /*******************************************************************
- * get_expanded_make_var_array
- */
- static struct strarray get_expanded_make_var_array( const struct makefile *make, const char *name )
- {
- struct strarray ret = empty_strarray;
- char *value, *token;
- if ((value = get_expanded_make_variable( make, name )))
- for (token = strtok( value, " \t" ); token; token = strtok( NULL, " \t" ))
- strarray_add( &ret, token );
- return ret;
- }
- /*******************************************************************
- * get_expanded_file_local_var
- */
- static struct strarray get_expanded_file_local_var( const struct makefile *make, const char *file,
- const char *name )
- {
- char *p, *var = strmake( "%s_%s", file, name );
- for (p = var; *p; p++) if (!isalnum( *p )) *p = '_';
- return get_expanded_make_var_array( make, var );
- }
- /*******************************************************************
- * set_make_variable
- */
- static int set_make_variable( struct strarray *array, const char *assignment )
- {
- char *p, *name;
- p = name = xstrdup( assignment );
- while (isalnum(*p) || *p == '_') p++;
- if (name == p) return 0; /* not a variable */
- if (isspace(*p))
- {
- *p++ = 0;
- while (isspace(*p)) p++;
- }
- if (*p != '=') return 0; /* not an assignment */
- *p++ = 0;
- while (isspace(*p)) p++;
- strarray_set_value( array, name, p );
- return 1;
- }
- /*******************************************************************
- * parse_makefile
- */
- static struct makefile *parse_makefile( const char *path )
- {
- char *buffer;
- FILE *file;
- struct makefile *make = xmalloc( sizeof(*make) );
- memset( make, 0, sizeof(*make) );
- make->obj_dir = path;
- if (root_src_dir) make->src_dir = root_src_dir_path( make->obj_dir );
- file = open_input_makefile( make );
- while ((buffer = get_line( file )))
- {
- if (!strncmp( buffer, separator, strlen(separator) )) break;
- if (*buffer == '\t') continue; /* command */
- while (isspace( *buffer )) buffer++;
- if (*buffer == '#') continue; /* comment */
- set_make_variable( &make->vars, buffer );
- }
- fclose( file );
- input_file_name = NULL;
- return make;
- }
- /*******************************************************************
- * add_generated_sources
- */
- static void add_generated_sources( struct makefile *make )
- {
- unsigned int i;
- struct incl_file *source, *next, *file;
- struct strarray objs = get_expanded_make_var_array( make, "EXTRA_OBJS" );
- LIST_FOR_EACH_ENTRY_SAFE( source, next, &make->sources, struct incl_file, entry )
- {
- if (source->file->flags & FLAG_IDL_CLIENT)
- {
- file = add_generated_source( make, replace_extension( source->name, ".idl", "_c.c" ), NULL );
- add_dependency( file->file, replace_extension( source->name, ".idl", ".h" ), INCL_NORMAL );
- add_all_includes( make, file, file->file );
- }
- if (source->file->flags & FLAG_IDL_SERVER)
- {
- file = add_generated_source( make, replace_extension( source->name, ".idl", "_s.c" ), NULL );
- add_dependency( file->file, "wine/exception.h", INCL_NORMAL );
- add_dependency( file->file, replace_extension( source->name, ".idl", ".h" ), INCL_NORMAL );
- add_all_includes( make, file, file->file );
- }
- if (source->file->flags & FLAG_IDL_IDENT)
- {
- file = add_generated_source( make, replace_extension( source->name, ".idl", "_i.c" ), NULL );
- add_dependency( file->file, "rpc.h", INCL_NORMAL );
- add_dependency( file->file, "rpcndr.h", INCL_NORMAL );
- add_dependency( file->file, "guiddef.h", INCL_NORMAL );
- add_all_includes( make, file, file->file );
- }
- if (source->file->flags & FLAG_IDL_PROXY)
- {
- file = add_generated_source( make, "dlldata.o", "dlldata.c" );
- add_dependency( file->file, "objbase.h", INCL_NORMAL );
- add_dependency( file->file, "rpcproxy.h", INCL_NORMAL );
- add_all_includes( make, file, file->file );
- file = add_generated_source( make, replace_extension( source->name, ".idl", "_p.c" ), NULL );
- add_dependency( file->file, "objbase.h", INCL_NORMAL );
- add_dependency( file->file, "rpcproxy.h", INCL_NORMAL );
- add_dependency( file->file, "wine/exception.h", INCL_NORMAL );
- add_dependency( file->file, replace_extension( source->name, ".idl", ".h" ), INCL_NORMAL );
- add_all_includes( make, file, file->file );
- }
- if (source->file->flags & FLAG_IDL_TYPELIB)
- {
- add_generated_source( make, replace_extension( source->name, ".idl", ".tlb" ), NULL );
- }
- if (source->file->flags & FLAG_IDL_REGTYPELIB)
- {
- add_generated_source( make, replace_extension( source->name, ".idl", "_t.res" ), NULL );
- }
- if (source->file->flags & FLAG_IDL_REGISTER)
- {
- add_generated_source( make, replace_extension( source->name, ".idl", "_r.res" ), NULL );
- }
- if (source->file->flags & FLAG_IDL_HEADER)
- {
- add_generated_source( make, replace_extension( source->name, ".idl", ".h" ), NULL );
- }
- if (!source->file->flags && strendswith( source->name, ".idl" ))
- {
- add_generated_source( make, replace_extension( source->name, ".idl", ".h" ), NULL );
- }
- if (strendswith( source->name, ".x" ))
- {
- add_generated_source( make, replace_extension( source->name, ".x", ".h" ), NULL );
- }
- if (strendswith( source->name, ".y" ))
- {
- file = add_generated_source( make, replace_extension( source->name, ".y", ".tab.c" ), NULL );
- /* steal the includes list from the source file */
- file->files_count = source->files_count;
- file->files_size = source->files_size;
- file->files = source->files;
- source->files_count = source->files_size = 0;
- source->files = NULL;
- }
- if (strendswith( source->name, ".l" ))
- {
- file = add_generated_source( make, replace_extension( source->name, ".l", ".yy.c" ), NULL );
- /* steal the includes list from the source file */
- file->files_count = source->files_count;
- file->files_size = source->files_size;
- file->files = source->files;
- source->files_count = source->files_size = 0;
- source->files = NULL;
- }
- if (source->file->flags & FLAG_C_IMPLIB)
- {
- if (!make->staticimplib && make->importlib && *dll_ext)
- make->staticimplib = strmake( "lib%s.a", make->importlib );
- }
- if (strendswith( source->name, ".po" ))
- {
- if (!make->disabled)
- strarray_add_uniq( &linguas, replace_extension( source->name, ".po", "" ));
- }
- if (strendswith( source->name, ".spec" ))
- {
- char *obj = replace_extension( source->name, ".spec", "" );
- strarray_addall_uniq( &make->extra_imports,
- get_expanded_file_local_var( make, obj, "IMPORTS" ));
- }
- }
- if (make->testdll)
- {
- file = add_generated_source( make, "testlist.o", "testlist.c" );
- add_dependency( file->file, "wine/test.h", INCL_NORMAL );
- add_all_includes( make, file, file->file );
- }
- for (i = 0; i < objs.count; i++)
- {
- /* default to .c for unknown extra object files */
- if (strendswith( objs.str[i], ".o" ))
- {
- file = add_generated_source( make, objs.str[i], replace_extension( objs.str[i], ".o", ".c" ));
- if (make->module || make->staticlib) file->file->flags |= FLAG_C_UNIX;
- }
- else if (strendswith( objs.str[i], ".res" ))
- add_generated_source( make, replace_extension( objs.str[i], ".res", ".rc" ), NULL );
- else
- add_generated_source( make, objs.str[i], NULL );
- }
- }
- /*******************************************************************
- * create_dir
- */
- static void create_dir( const char *dir )
- {
- char *p, *path;
- p = path = xstrdup( dir );
- while ((p = strchr( p, '/' )))
- {
- *p = 0;
- if (mkdir( path, 0755 ) == -1 && errno != EEXIST) fatal_perror( "mkdir %s", path );
- *p++ = '/';
- while (*p == '/') p++;
- }
- if (mkdir( path, 0755 ) == -1 && errno != EEXIST) fatal_perror( "mkdir %s", path );
- free( path );
- }
- /*******************************************************************
- * create_file_directories
- *
- * Create the base directories of all the files.
- */
- static void create_file_directories( const struct makefile *make, struct strarray files )
- {
- struct strarray subdirs = empty_strarray;
- unsigned int i;
- char *dir;
- for (i = 0; i < files.count; i++)
- {
- if (!strchr( files.str[i], '/' )) continue;
- dir = obj_dir_path( make, files.str[i] );
- *strrchr( dir, '/' ) = 0;
- strarray_add_uniq( &subdirs, dir );
- }
- for (i = 0; i < subdirs.count; i++) create_dir( subdirs.str[i] );
- }
- /*******************************************************************
- * output_filenames_obj_dir
- */
- static void output_filenames_obj_dir( const struct makefile *make, struct strarray array )
- {
- unsigned int i;
- for (i = 0; i < array.count; i++) output_filename( obj_dir_path( make, array.str[i] ));
- }
- /*******************************************************************
- * get_dependencies
- */
- static void get_dependencies( struct incl_file *file, struct incl_file *source )
- {
- unsigned int i;
- if (!file->filename) return;
- if (file != source)
- {
- if (file->owner == source) return; /* already processed */
- if (file->type == INCL_IMPORTLIB &&
- !(source->file->flags & (FLAG_IDL_TYPELIB | FLAG_IDL_REGTYPELIB)))
- return; /* library is imported only when building a typelib */
- file->owner = source;
- strarray_add( &source->dependencies, file->filename );
- }
- for (i = 0; i < file->files_count; i++) get_dependencies( file->files[i], source );
- }
- /*******************************************************************
- * get_local_dependencies
- *
- * Get the local dependencies of a given target.
- */
- static struct strarray get_local_dependencies( const struct makefile *make, const char *name,
- struct strarray targets )
- {
- unsigned int i;
- struct strarray deps = get_expanded_file_local_var( make, name, "DEPS" );
- for (i = 0; i < deps.count; i++)
- {
- if (strarray_exists( &targets, deps.str[i] ))
- deps.str[i] = obj_dir_path( make, deps.str[i] );
- else
- deps.str[i] = src_dir_path( make, deps.str[i] );
- }
- return deps;
- }
- /*******************************************************************
- * get_static_lib
- *
- * Check if makefile builds the named static library and return the full lib path.
- */
- static const char *get_static_lib( const struct makefile *make, const char *name )
- {
- if (!make->staticlib) return NULL;
- if (strncmp( make->staticlib, "lib", 3 )) return NULL;
- if (strncmp( make->staticlib + 3, name, strlen(name) )) return NULL;
- if (strcmp( make->staticlib + 3 + strlen(name), ".a" )) return NULL;
- return obj_dir_path( make, make->staticlib );
- }
- /*******************************************************************
- * get_parent_makefile
- */
- static struct makefile *get_parent_makefile( struct makefile *make )
- {
- char *dir, *p;
- int i;
- if (!make->obj_dir) return NULL;
- dir = xstrdup( make->obj_dir );
- if (!(p = strrchr( dir, '/' ))) return NULL;
- *p = 0;
- for (i = 0; i < subdirs.count; i++)
- if (!strcmp( submakes[i]->obj_dir, dir )) return submakes[i];
- return NULL;
- }
- /*******************************************************************
- * needs_cross_lib
- */
- static int needs_cross_lib( const struct makefile *make )
- {
- const char *name;
- if (!crosstarget) return 0;
- if (make->importlib) name = make->importlib;
- else if (make->staticlib)
- {
- name = replace_extension( make->staticlib, ".a", "" );
- if (!strncmp( name, "lib", 3 )) name += 3;
- }
- else return 0;
- if (strarray_exists( &cross_import_libs, name )) return 1;
- if (delay_load_flag && strarray_exists( &delay_import_libs, name )) return 1;
- return 0;
- }
- /*******************************************************************
- * needs_delay_lib
- */
- static int needs_delay_lib( const struct makefile *make )
- {
- if (delay_load_flag) return 0;
- if (*dll_ext && !crosstarget) return 0;
- if (!make->importlib) return 0;
- return strarray_exists( &delay_import_libs, make->importlib );
- }
- /*******************************************************************
- * needs_implib_symlink
- */
- static int needs_implib_symlink( const struct makefile *make )
- {
- if (!make->module) return 0;
- if (!make->importlib) return 0;
- if (make->is_win16 && make->disabled) return 0;
- if (strncmp( make->obj_dir, "dlls/", 5 )) return 0;
- if (!strcmp( make->module, make->importlib )) return 0;
- if (!strchr( make->importlib, '.' ) &&
- !strncmp( make->module, make->importlib, strlen( make->importlib )) &&
- !strcmp( make->module + strlen( make->importlib ), ".dll" ))
- return 0;
- return 1;
- }
- /*******************************************************************
- * add_unix_libraries
- */
- static struct strarray add_unix_libraries( const struct makefile *make, struct strarray *deps )
- {
- struct strarray ret = empty_strarray;
- struct strarray all_libs = empty_strarray;
- unsigned int i, j;
- strarray_add( &all_libs, "-lwine_port" );
- strarray_addall( &all_libs, get_expanded_make_var_array( make, "EXTRALIBS" ));
- strarray_addall( &all_libs, libs );
- for (i = 0; i < all_libs.count; i++)
- {
- const char *lib = NULL;
- if (!strncmp( all_libs.str[i], "-l", 2 ))
- {
- const char *name = all_libs.str[i] + 2;
- for (j = 0; j < subdirs.count; j++)
- if ((lib = get_static_lib( submakes[j], name ))) break;
- }
- if (lib)
- {
- strarray_add( deps, lib );
- strarray_add( &ret, lib );
- }
- else strarray_add( &ret, all_libs.str[i] );
- }
- return ret;
- }
- /*******************************************************************
- * add_import_libs
- */
- static struct strarray add_import_libs( const struct makefile *make, struct strarray *deps,
- struct strarray imports, int delay, int is_unix )
- {
- struct strarray ret = empty_strarray;
- unsigned int i, j;
- int is_cross = make->is_cross && !is_unix;
- for (i = 0; i < imports.count; i++)
- {
- const char *name = get_base_name( imports.str[i] );
- const char *lib = NULL;
- /* skip module's own importlib, its object files will be linked directly */
- if (make->importlib && !strcmp( make->importlib, imports.str[i] )) continue;
- for (j = 0; j < subdirs.count; j++)
- {
- if (submakes[j]->importlib && !strcmp( submakes[j]->importlib, name ))
- {
- if (is_cross || !*dll_ext || submakes[j]->staticimplib)
- lib = obj_dir_path( submakes[j], strmake( "lib%s.a", name ));
- else
- {
- strarray_add( deps, strmake( "%s/lib%s.def", submakes[j]->obj_dir, name ));
- if (needs_implib_symlink( submakes[j] ))
- strarray_add( deps, strmake( "dlls/lib%s.def", name ));
- }
- break;
- }
- if ((lib = get_static_lib( submakes[j], name ))) break;
- }
- if (lib)
- {
- const char *ext = NULL;
- if (delay && !delay_load_flag && (is_cross || !*dll_ext)) ext = ".delay.a";
- else if (is_cross) ext = ".cross.a";
- if (ext) lib = replace_extension( lib, ".a", ext );
- strarray_add( deps, lib );
- strarray_add( &ret, lib );
- if (needs_implib_symlink( submakes[j] ))
- strarray_add( deps, strmake( "dlls/lib%s%s", name, ext ? ext : ".a" ));
- }
- else strarray_add( &ret, strmake( "-l%s", name ));
- }
- return ret;
- }
- /*******************************************************************
- * get_default_imports
- */
- static struct strarray get_default_imports( const struct makefile *make )
- {
- struct strarray ret = empty_strarray;
- if (strarray_exists( &make->extradllflags, "-nodefaultlibs" )) return ret;
- strarray_add( &ret, "winecrt0" );
- if (make->is_win16) strarray_add( &ret, "kernel" );
- strarray_add( &ret, "kernel32" );
- strarray_add( &ret, "ntdll" );
- return ret;
- }
- /*******************************************************************
- * add_crt_import
- */
- static const char *add_crt_import( const struct makefile *make, struct strarray *imports )
- {
- unsigned int i;
- const char *crt_dll = NULL;
- for (i = 0; i < imports->count; i++)
- {
- if (strncmp( imports->str[i], "msvcr", 5 ) && strncmp( imports->str[i], "ucrt", 4 )) continue;
- if (crt_dll) fatal_error( "More than one C runtime DLL imported: %s and %s\n", crt_dll, imports->str[i] );
- crt_dll = imports->str[i];
- }
- if (!crt_dll && !strarray_exists( &make->extradllflags, "-nodefaultlibs" ))
- {
- crt_dll = !make->testdll && !make->staticlib ? "ucrtbase" : "msvcrt";
- strarray_add( imports, crt_dll );
- }
- return crt_dll;
- }
- /*******************************************************************
- * add_install_rule
- */
- static void add_install_rule( struct makefile *make, const char *target,
- const char *file, const char *dest )
- {
- if (strarray_exists( &make->install_lib, target ) ||
- strarray_exists( &top_install_lib, make->obj_dir ) ||
- strarray_exists( &top_install_lib, obj_dir_path( make, target )))
- {
- strarray_add( &make->install_rules[INSTALL_LIB], file );
- strarray_add( &make->install_rules[INSTALL_LIB], dest );
- }
- else if (strarray_exists( &make->install_dev, target ) ||
- strarray_exists( &top_install_dev, make->obj_dir ) ||
- strarray_exists( &top_install_dev, obj_dir_path( make, target )))
- {
- strarray_add( &make->install_rules[INSTALL_DEV], file );
- strarray_add( &make->install_rules[INSTALL_DEV], dest );
- }
- }
- /*******************************************************************
- * get_include_install_path
- *
- * Determine the installation path for a given include file.
- */
- static const char *get_include_install_path( const char *name )
- {
- if (!strncmp( name, "wine/", 5 )) return name + 5;
- if (!strncmp( name, "msvcrt/", 7 )) return name;
- return strmake( "windows/%s", name );
- }
- /*******************************************************************
- * get_shared_library_name
- *
- * Determine possible names for a shared library with a version number.
- */
- static struct strarray get_shared_lib_names( const char *libname )
- {
- struct strarray ret = empty_strarray;
- const char *ext, *p;
- char *name, *first, *second;
- size_t len = 0;
- strarray_add( &ret, libname );
- for (p = libname; (p = strchr( p, '.' )); p++)
- if ((len = strspn( p + 1, "0123456789." ))) break;
- if (!len) return ret;
- ext = p + 1 + len;
- if (*ext && ext[-1] == '.') ext--;
- /* keep only the first group of digits */
- name = xstrdup( libname );
- first = name + (p - libname);
- if ((second = strchr( first + 1, '.' )))
- {
- strcpy( second, ext );
- strarray_add( &ret, xstrdup( name ));
- }
- /* now remove all digits */
- strcpy( first, ext );
- strarray_add( &ret, name );
- return ret;
- }
- /*******************************************************************
- * get_source_defines
- */
- static struct strarray get_source_defines( struct makefile *make, struct incl_file *source,
- const char *obj )
- {
- unsigned int i;
- struct strarray ret = empty_strarray;
- strarray_addall( &ret, make->include_args );
- if (source->use_msvcrt)
- strarray_add( &ret, strmake( "-I%s", root_src_dir_path( "include/msvcrt" )));
- for (i = 0; i < make->include_paths.count; i++)
- strarray_add( &ret, strmake( "-I%s", make->include_paths.str[i] ));
- strarray_addall( &ret, make->define_args );
- strarray_addall( &ret, get_expanded_file_local_var( make, obj, "EXTRADEFS" ));
- if ((source->file->flags & FLAG_C_UNIX) && *dll_ext) strarray_add( &ret, "-DWINE_UNIX_LIB" );
- return ret;
- }
- /*******************************************************************
- * get_debug_file
- */
- static const char *get_debug_file( struct makefile *make, const char *name )
- {
- const char *debug_file = NULL;
- if (!make->is_cross || !crossdebug) return NULL;
- if (!strcmp( crossdebug, "pdb" )) debug_file = strmake( "%s.pdb", get_base_name( name ));
- else if(!strncmp( crossdebug, "split", 5 )) debug_file = strmake( "%s.debug", name );
- if (debug_file) strarray_add( &make->debug_files, debug_file );
- return debug_file;
- }
- /*******************************************************************
- * output_winegcc_command
- */
- static void output_winegcc_command( struct makefile *make, int is_cross )
- {
- output( "\t%s -o $@", tools_path( make, "winegcc" ));
- output_filename( "--wine-objdir ." );
- if (tools_dir)
- {
- output_filename( "--winebuild" );
- output_filename( tools_path( make, "winebuild" ));
- }
- if (is_cross)
- {
- output_filename( "-b" );
- output_filename( crosstarget );
- output_filename( "--lib-suffix=.cross.a" );
- }
- else
- {
- output_filenames( target_flags );
- output_filenames( lddll_flags );
- }
- }
- /*******************************************************************
- * output_symlink_rule
- *
- * Output a rule to create a symlink.
- */
- static void output_symlink_rule( const char *src_name, const char *link_name )
- {
- const char *name;
- output( "\trm -f %s && ", link_name );
- /* dest path with a directory needs special handling if ln -s isn't supported */
- if (strcmp( ln_s, "ln -s" ) && ((name = strrchr( link_name, '/' ))))
- {
- char *dir = xstrdup( link_name );
- dir[name - link_name] = 0;
- output( "cd %s && %s %s %s\n", *dir ? dir : "/", ln_s, src_name, name + 1 );
- free( dir );
- }
- else
- {
- output( "%s %s %s\n", ln_s, src_name, link_name );
- }
- }
- /*******************************************************************
- * output_srcdir_symlink
- *
- * Output rule to create a symlink back to the source directory, for source files
- * that are needed at run-time.
- */
- static void output_srcdir_symlink( struct makefile *make, const char *obj )
- {
- char *src_file, *dst_file, *src_name;
- if (!make->src_dir) return;
- src_file = src_dir_path( make, obj );
- dst_file = obj_dir_path( make, obj );
- output( "%s: %s\n", dst_file, src_file );
- src_name = src_file;
- if (src_name[0] != '/' && make->obj_dir)
- src_name = concat_paths( get_relative_path( make->obj_dir, "" ), src_name );
- output_symlink_rule( src_name, dst_file );
- strarray_add( &make->all_targets, obj );
- }
- /*******************************************************************
- * output_install_commands
- */
- static void output_install_commands( struct makefile *make, struct strarray files )
- {
- unsigned int i;
- char *install_sh = root_src_dir_path( "tools/install-sh" );
- for (i = 0; i < files.count; i += 2)
- {
- const char *file = files.str[i];
- const char *dest = strmake( "$(DESTDIR)%s", files.str[i + 1] + 1 );
- switch (*files.str[i + 1])
- {
- case 'c': /* cross-compiled program */
- output( "\tSTRIPPROG=%s-strip %s -m 644 $(INSTALL_PROGRAM_FLAGS) %s %s\n",
- crosstarget, install_sh, obj_dir_path( make, file ), dest );
- output( "\t%s --builtin %s\n", tools_path( make, "winebuild" ), dest );
- break;
- case 'd': /* data file */
- output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
- install_sh, obj_dir_path( make, file ), dest );
- break;
- case 'D': /* data file in source dir */
- output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
- install_sh, src_dir_path( make, file ), dest );
- break;
- case 'p': /* program file */
- output( "\tSTRIPPROG=\"$(STRIP)\" %s $(INSTALL_PROGRAM_FLAGS) %s %s\n",
- install_sh, obj_dir_path( make, file ), dest );
- break;
- case 's': /* script */
- output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
- install_sh, obj_dir_path( make, file ), dest );
- break;
- case 'S': /* script in source dir */
- output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
- install_sh, src_dir_path( make, file ), dest );
- break;
- case 't': /* script in tools dir */
- output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
- install_sh, tools_dir_path( make, files.str[i] ), dest );
- break;
- case 'y': /* symlink */
- output_symlink_rule( files.str[i], dest );
- break;
- default:
- assert(0);
- }
- strarray_add( &make->uninstall_files, dest );
- }
- }
- /*******************************************************************
- * output_install_rules
- *
- * Rules are stored as a (file,dest) pair of values.
- * The first char of dest indicates the type of install.
- */
- static void output_install_rules( struct makefile *make, enum install_rules rules, const char *target )
- {
- unsigned int i;
- struct strarray files = make->install_rules[rules];
- struct strarray targets = empty_strarray;
- if (!files.count) return;
- for (i = 0; i < files.count; i += 2)
- {
- const char *file = files.str[i];
- switch (*files.str[i + 1])
- {
- case 'c': /* cross-compiled program */
- case 'd': /* data file */
- case 'p': /* program file */
- case 's': /* script */
- strarray_add_uniq( &targets, obj_dir_path( make, file ));
- break;
- case 't': /* script in tools dir */
- strarray_add_uniq( &targets, tools_dir_path( make, file ));
- break;
- }
- }
- output( "%s %s::", obj_dir_path( make, "install" ), obj_dir_path( make, target ));
- output_filenames( targets );
- output( "\n" );
- output_install_commands( make, files );
- strarray_add_uniq( &make->phony_targets, obj_dir_path( make, "install" ));
- strarray_add_uniq( &make->phony_targets, obj_dir_path( make, target ));
- }
- static int cmp_string_length( const char **a, const char **b )
- {
- int paths_a = 0, paths_b = 0;
- const char *p;
- for (p = *a; *p; p++) if (*p == '/') paths_a++;
- for (p = *b; *p; p++) if (*p == '/') paths_b++;
- if (paths_b != paths_a) return paths_b - paths_a;
- return strcmp( *a, *b );
- }
- /*******************************************************************
- * output_uninstall_rules
- */
- static void output_uninstall_rules( struct makefile *make )
- {
- static const char *dirs_order[] =
- { "$(includedir)", "$(mandir)", "$(fontdir)", "$(datadir)", "$(dlldir)" };
- struct strarray uninstall_dirs = empty_strarray;
- unsigned int i, j;
- if (!make->uninstall_files.count) return;
- output( "uninstall::\n" );
- output_rm_filenames( make->uninstall_files );
- strarray_add_uniq( &make->phony_targets, "uninstall" );
- if (!subdirs.count) return;
- for (i = 0; i < make->uninstall_files.count; i++)
- {
- char *dir = xstrdup( make->uninstall_files.str[i] );
- while (strchr( dir, '/' ))
- {
- *strrchr( dir, '/' ) = 0;
- strarray_add_uniq( &uninstall_dirs, xstrdup(dir) );
- }
- }
- strarray_qsort( &uninstall_dirs, cmp_string_length );
- output( "\t-rmdir" );
- for (i = 0; i < sizeof(dirs_order)/sizeof(dirs_order[0]); i++)
- {
- for (j = 0; j < uninstall_dirs.count; j++)
- {
- if (!uninstall_dirs.str[j]) continue;
- if (strncmp( uninstall_dirs.str[j] + strlen("$(DESTDIR)"), dirs_order[i], strlen(dirs_order[i]) ))
- continue;
- output_filename( uninstall_dirs.str[j] );
- uninstall_dirs.str[j] = NULL;
- }
- }
- for (j = 0; j < uninstall_dirs.count; j++)
- if (uninstall_dirs.str[j]) output_filename( uninstall_dirs.str[j] );
- output( "\n" );
- }
- /*******************************************************************
- * output_importlib_symlinks
- */
- static struct strarray output_importlib_symlinks( const struct makefile *make )
- {
- struct strarray ret = empty_strarray;
- const char *lib, *dst, *ext[4];
- int i, count = 0;
- ext[count++] = (*dll_ext && !make->implib_objs.count) ? "def" : "a";
- if (needs_delay_lib( make )) ext[count++] = "delay.a";
- if (needs_cross_lib( make )) ext[count++] = "cross.a";
- for (i = 0; i < count; i++)
- {
- lib = strmake( "lib%s.%s", make->importlib, ext[i] );
- dst = strmake( "dlls/%s", lib );
- output( "%s: %s\n", dst, obj_dir_path( make, lib ));
- output_symlink_rule( concat_paths( make->obj_dir + strlen("dlls/"), lib ), dst );
- strarray_add( &ret, dst );
- }
- return ret;
- }
- /*******************************************************************
- * output_po_files
- */
- static void output_po_files( const struct makefile *make )
- {
- const char *po_dir = src_dir_path( make, "po" );
- unsigned int i;
- if (linguas.count)
- {
- for (i = 0; i < linguas.count; i++)
- output_filename( strmake( "%s/%s.po", po_dir, linguas.str[i] ));
- output( ": %s/wine.pot\n", po_dir );
- output( "\tmsgmerge --previous -q $@ %s/wine.pot | msgattrib --no-obsolete -o $@.new && mv $@.new $@\n",
- po_dir );
- output( "po:" );
- for (i = 0; i < linguas.count; i++)
- output_filename( strmake( "%s/%s.po", po_dir, linguas.str[i] ));
- output( "\n" );
- }
- output( "%s/wine.pot:", po_dir );
- output_filenames( make->pot_files );
- output( "\n" );
- output( "\tmsgcat -o $@" );
- output_filenames( make->pot_files );
- output( "\n" );
- }
- /*******************************************************************
- * output_source_y
- */
- static void output_source_y( struct makefile *make, struct incl_file *source, const char *obj )
- {
- /* add source file dependency for parallel makes */
- char *header = strmake( "%s.tab.h", obj );
- if (find_include_file( make, header ))
- {
- output( "%s: %s\n", obj_dir_path( make, header ), source->filename );
- output( "\t%s -p %s_ -o %s.tab.c -d %s\n",
- bison, obj, obj_dir_path( make, obj ), source->filename );
- output( "%s.tab.c: %s %s\n", obj_dir_path( make, obj ),
- source->filename, obj_dir_path( make, header ));
- strarray_add( &make->clean_files, header );
- }
- else output( "%s.tab.c: %s\n", obj_dir_path( make, obj ), source->filename );
- output( "\t%s -p %s_ -o $@ %s\n", bison, obj, source->filename );
- }
- /*******************************************************************
- * output_source_l
- */
- static void output_source_l( struct makefile *make, struct incl_file *source, const char *obj )
- {
- output( "%s.yy.c: %s\n", obj_dir_path( make, obj ), source->filename );
- output( "\t%s -o$@ %s\n", flex, source->filename );
- }
- /*******************************************************************
- * output_source_h
- */
- static void output_source_h( struct makefile *make, struct incl_file *source, const char *obj )
- {
- if (source->file->flags & FLAG_GENERATED)
- strarray_add( &make->all_targets, source->name );
- else
- add_install_rule( make, source->name, source->name,
- strmake( "D$(includedir)/wine/%s", get_include_install_path( source->name ) ));
- }
- /*******************************************************************
- * output_source_rc
- */
- static void output_source_rc( struct makefile *make, struct incl_file *source, const char *obj )
- {
- struct strarray defines = get_source_defines( make, source, obj );
- const char *po_dir = NULL;
- unsigned int i;
- if (source->file->flags & FLAG_GENERATED) strarray_add( &make->clean_files, source->name );
- if (linguas.count && (source->file->flags & FLAG_RC_PO)) po_dir = "po";
- strarray_add( &make->res_files, strmake( "%s.res", obj ));
- if (source->file->flags & FLAG_RC_PO)
- {
- strarray_add( &make->pot_files, strmake( "%s.pot", obj ));
- output( "%s.pot ", obj_dir_path( make, obj ) );
- }
- output( "%s.res: %s", obj_dir_path( make, obj ), source->filename );
- output_filename( tools_path( make, "wrc" ));
- output_filenames( source->dependencies );
- output( "\n" );
- output( "\t%s -u -o $@", tools_path( make, "wrc" ) );
- if (make->is_win16) output_filename( "-m16" );
- else output_filenames( target_flags );
- output_filename( "--nostdinc" );
- if (po_dir) output_filename( strmake( "--po-dir=%s", po_dir ));
- output_filenames( defines );
- output_filename( source->filename );
- output( "\n" );
- if (po_dir)
- {
- output( "%s.res:", obj_dir_path( make, obj ));
- for (i = 0; i < linguas.count; i++)
- output_filename( strmake( "%s/%s.mo", po_dir, linguas.str[i] ));
- output( "\n" );
- }
- }
- /*******************************************************************
- * output_source_mc
- */
- static void output_source_mc( struct makefile *make, struct incl_file *source, const char *obj )
- {
- unsigned int i;
- char *obj_path = obj_dir_path( make, obj );
- strarray_add( &make->res_files, strmake( "%s.res", obj ));
- strarray_add( &make->pot_files, strmake( "%s.pot", obj ));
- output( "%s.pot %s.res: %s", obj_path, obj_path, source->filename );
- output_filename( tools_path( make, "wmc" ));
- output_filenames( source->dependencies );
- output( "\n" );
- output( "\t%s -u -o $@ %s", tools_path( make, "wmc" ), source->filename );
- if (linguas.count)
- {
- output_filename( "--po-dir=po" );
- output( "\n" );
- output( "%s.res:", obj_dir_path( make, obj ));
- for (i = 0; i < linguas.count; i++)
- output_filename( strmake( "po/%s.mo", linguas.str[i] ));
- }
- output( "\n" );
- }
- /*******************************************************************
- * output_source_res
- */
- static void output_source_res( struct makefile *make, struct incl_file *source, const char *obj )
- {
- strarray_add( &make->res_files, source->name );
- }
- /*******************************************************************
- * output_source_idl
- */
- static void output_source_idl( struct makefile *make, struct incl_file *source, const char *obj )
- {
- struct strarray defines = get_source_defines( make, source, obj );
- struct strarray targets = empty_strarray;
- char *dest;
- unsigned int i;
- if (!source->file->flags) source->file->flags |= FLAG_IDL_HEADER | FLAG_INSTALL;
- if (find_include_file( make, strmake( "%s.h", obj ))) source->file->flags |= FLAG_IDL_HEADER;
- for (i = 0; i < sizeof(idl_outputs) / sizeof(idl_outputs[0]); i++)
- {
- if (!(source->file->flags & idl_outputs[i].flag)) continue;
- dest = strmake( "%s%s", obj, idl_outputs[i].ext );
- if (!find_src_file( make, dest )) strarray_add( &make->clean_files, dest );
- strarray_add( &targets, dest );
- }
- if (source->file->flags & FLAG_IDL_PROXY) strarray_add( &make->dlldata_files, source->name );
- if (source->file->flags & FLAG_INSTALL)
- {
- add_install_rule( make, source->name, xstrdup( source->name ),
- strmake( "D$(includedir)/wine/%s.idl", get_include_install_path( obj ) ));
- if (source->file->flags & FLAG_IDL_HEADER)
- add_install_rule( make, source->name, strmake( "%s.h", obj ),
- strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj ) ));
- if (source->file->flags & FLAG_IDL_TYPELIB)
- add_install_rule( make, source->name, strmake( "%s.tlb", obj ),
- strmake( "d$(includedir)/wine/%s.tlb", get_include_install_path( obj ) ));
- }
- if (!targets.count) return;
- output_filenames_obj_dir( make, targets );
- output( ": %s\n", tools_path( make, "widl" ));
- output( "\t%s -o $@", tools_path( make, "widl" ) );
- output_filenames( target_flags );
- output_filename( "--nostdinc" );
- output_filenames( defines );
- output_filenames( get_expanded_make_var_array( make, "EXTRAIDLFLAGS" ));
- output_filenames( get_expanded_file_local_var( make, obj, "EXTRAIDLFLAGS" ));
- output_filename( source->filename );
- output( "\n" );
- output_filenames_obj_dir( make, targets );
- output( ": %s", source->filename );
- output_filenames( source->dependencies );
- output( "\n" );
- }
- /*******************************************************************
- * output_source_tlb
- */
- static void output_source_tlb( struct makefile *make, struct incl_file *source, const char *obj )
- {
- strarray_add( &make->all_targets, source->name );
- }
- /*******************************************************************
- * output_source_x
- */
- static void output_source_x( struct makefile *make, struct incl_file *source, const char *obj )
- {
- output( "%s.h: %s%s %s\n", obj_dir_path( make, obj ),
- tools_dir_path( make, "make_xftmpl" ), tools_ext, source->filename );
- output( "\t%s%s -H -o $@ %s\n",
- tools_dir_path( make, "make_xftmpl" ), tools_ext, source->filename );
- if (source->file->flags & FLAG_INSTALL)
- {
- add_install_rule( make, source->name, source->name,
- strmake( "D$(includedir)/wine/%s", get_include_install_path( source->name ) ));
- add_install_rule( make, source->name, strmake( "%s.h", obj ),
- strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj ) ));
- }
- }
- /*******************************************************************
- * output_source_sfd
- */
- static void output_source_sfd( struct makefile *make, struct incl_file *source, const char *obj )
- {
- unsigned int i;
- char *ttf_obj = strmake( "%s.ttf", obj );
- char *ttf_file = src_dir_path( make, ttf_obj );
- if (fontforge && !make->src_dir)
- {
- output( "%s: %s\n", ttf_file, source->filename );
- output( "\t%s -script %s %s $@\n",
- fontforge, root_src_dir_path( "fonts/genttf.ff" ), source->filename );
- if (!(source->file->flags & FLAG_SFD_FONTS)) strarray_add( &make->font_files, ttf_obj );
- }
- if (source->file->flags & FLAG_INSTALL)
- {
- add_install_rule( make, source->name, ttf_obj, strmake( "D$(fontdir)/%s", ttf_obj ));
- output_srcdir_symlink( make, ttf_obj );
- }
- if (source->file->flags & FLAG_SFD_FONTS)
- {
- struct strarray *array = source->file->args;
- for (i = 0; i < array->count; i++)
- {
- char *font = strtok( xstrdup(array->str[i]), " \t" );
- char *args = strtok( NULL, "" );
- strarray_add( &make->all_targets, xstrdup( font ));
- output( "%s: %s %s\n", obj_dir_path( make, font ),
- tools_path( make, "sfnt2fon" ), ttf_file );
- output( "\t%s -q -o $@ %s %s\n", tools_path( make, "sfnt2fon" ), ttf_file, args );
- add_install_rule( make, source->name, xstrdup(font), strmake( "d$(fontdir)/%s", font ));
- }
- }
- }
- /*******************************************************************
- * output_source_svg
- */
- static void output_source_svg( struct makefile *make, struct incl_file *source, const char *obj )
- {
- static const char * const images[] = { "bmp", "cur", "ico", NULL };
- unsigned int i;
- if (convert && rsvg && icotool && !make->src_dir)
- {
- for (i = 0; images[i]; i++)
- if (find_include_file( make, strmake( "%s.%s", obj, images[i] ))) break;
- if (images[i])
- {
- output( "%s.%s: %s\n", src_dir_path( make, obj ), images[i], source->filename );
- output( "\tCONVERT=\"%s\" ICOTOOL=\"%s\" RSVG=\"%s\" %s %s $@\n", convert, icotool, rsvg,
- root_src_dir_path( "tools/buildimage" ), source->filename );
- }
- }
- }
- /*******************************************************************
- * output_source_nls
- */
- static void output_source_nls( struct makefile *make, struct incl_file *source, const char *obj )
- {
- add_install_rule( make, source->name, source->name,
- strmake( "D$(nlsdir)/%s", source->name ));
- output_srcdir_symlink( make, strmake( "%s.nls", obj ));
- }
- /*******************************************************************
- * output_source_desktop
- */
- static void output_source_desktop( struct makefile *make, struct incl_file *source, const char *obj )
- {
- add_install_rule( make, source->name, source->name,
- strmake( "D$(datadir)/applications/%s", source->name ));
- }
- /*******************************************************************
- * output_source_po
- */
- static void output_source_po( struct makefile *make, struct incl_file *source, const char *obj )
- {
- output( "%s.mo: %s\n", obj_dir_path( make, obj ), source->filename );
- output( "\t%s -o $@ %s\n", msgfmt, source->filename );
- strarray_add( &make->all_targets, strmake( "%s.mo", obj ));
- }
- /*******************************************************************
- * output_source_in
- */
- static void output_source_in( struct makefile *make, struct incl_file *source, const char *obj )
- {
- unsigned int i;
- if (strendswith( obj, ".man" ) && source->file->args)
- {
- struct strarray symlinks;
- char *dir, *dest = replace_extension( obj, ".man", "" );
- char *lang = strchr( dest, '.' );
- char *section = source->file->args;
- if (lang)
- {
- *lang++ = 0;
- dir = strmake( "$(mandir)/%s/man%s", lang, section );
- }
- else dir = strmake( "$(mandir)/man%s", section );
- add_install_rule( make, dest, xstrdup(obj), strmake( "d%s/%s.%s", dir, dest, section ));
- symlinks = get_expanded_file_local_var( make, dest, "SYMLINKS" );
- for (i = 0; i < symlinks.count; i++)
- add_install_rule( make, symlinks.str[i], strmake( "%s.%s", dest, section ),
- strmake( "y%s/%s.%s", dir, symlinks.str[i], section ));
- free( dest );
- free( dir );
- }
- strarray_add( &make->in_files, xstrdup(obj) );
- strarray_add( &make->all_targets, xstrdup(obj) );
- output( "%s: %s\n", obj_dir_path( make, obj ), source->filename );
- output( "\t%s %s >$@ || (rm -f $@ && false)\n", sed_cmd, source->filename );
- output( "%s:", obj_dir_path( make, obj ));
- output_filenames( source->dependencies );
- output( "\n" );
- add_install_rule( make, obj, xstrdup( obj ), strmake( "d$(datadir)/wine/%s", obj ));
- }
- /*******************************************************************
- * output_source_spec
- */
- static void output_source_spec( struct makefile *make, struct incl_file *source, const char *obj )
- {
- struct strarray imports = get_expanded_file_local_var( make, obj, "IMPORTS" );
- struct strarray dll_flags = get_expanded_file_local_var( make, obj, "EXTRADLLFLAGS" );
- struct strarray all_libs, dep_libs = empty_strarray;
- char *dll_name, *obj_name, *output_file;
- const char *debug_file;
- if (!imports.count) imports = make->imports;
- else if (make->use_msvcrt) add_crt_import( make, &imports );
- if (!dll_flags.count) dll_flags = make->extradllflags;
- all_libs = add_import_libs( make, &dep_libs, imports, 0, 0 );
- add_import_libs( make, &dep_libs, get_default_imports( make ), 0, 0 ); /* dependencies only */
- dll_name = strmake( "%s.dll%s", obj, make->is_cross ? "" : dll_ext );
- obj_name = strmake( "%s%s", obj_dir_path( make, obj ), make->is_cross ? ".cross.o" : ".o" );
- output_file = obj_dir_path( make, dll_name );
- strarray_add( &make->clean_files, dll_name );
- strarray_add( &make->res_files, strmake( "%s.res", obj ));
- output( "%s.res: %s\n", obj_dir_path( make, obj ), obj_dir_path( make, dll_name ));
- output( "\techo \"%s.dll TESTDLL \\\"%s\\\"\" | %s -u -o $@\n", obj, output_file,
- tools_path( make, "wrc" ));
- output( "%s:", output_file);
- output_filename( source->filename );
- output_filename( obj_name );
- output_filenames( dep_libs );
- output_filename( tools_path( make, "winebuild" ));
- output_filename( tools_path( make, "winegcc" ));
- output( "\n" );
- output_winegcc_command( make, make->is_cross );
- output_filename( "-s" );
- output_filenames( dll_flags );
- output_filename( "-shared" );
- output_filename( source->filename );
- output_filename( obj_name );
- if ((debug_file = get_debug_file( make, output_file )))
- output_filename( strmake( "-Wl,--debug-file,%s", debug_file ));
- output_filenames( all_libs );
- output_filename( make->is_cross ? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
- output( "\n" );
- }
- /*******************************************************************
- * output_source_default
- */
- static void output_source_default( struct makefile *make, struct incl_file *source, const char *obj )
- {
- struct strarray defines = get_source_defines( make, source, obj );
- int is_dll_src = (make->testdll &&
- strendswith( source->name, ".c" ) &&
- find_src_file( make, replace_extension( source->name, ".c", ".spec" )));
- int need_cross = (crosstarget &&
- !(source->file->flags & FLAG_C_UNIX) &&
- (make->is_cross ||
- ((source->file->flags & FLAG_C_IMPLIB) &&
- (needs_cross_lib( make ) || needs_delay_lib( make ))) ||
- (make->staticlib && needs_cross_lib( make ))));
- int need_obj = ((*dll_ext || !make->staticlib || !(source->file->flags & FLAG_C_UNIX)) &&
- (!need_cross ||
- (source->file->flags & FLAG_C_IMPLIB) ||
- (make->module && make->staticlib)));
- if ((source->file->flags & FLAG_GENERATED) &&
- (!make->testdll || !strendswith( source->filename, "testlist.c" )))
- strarray_add( &make->clean_files, source->basename );
- if (source->file->flags & FLAG_C_IMPLIB) strarray_add( &make->implib_objs, strmake( "%s.o", obj ));
- if (need_obj)
- {
- if ((source->file->flags & FLAG_C_UNIX) && *dll_ext)
- strarray_add( &make->unixobj_files, strmake( "%s.o", obj ));
- else if (!is_dll_src && (!(source->file->flags & FLAG_C_IMPLIB) || (make->importlib && strarray_exists( &make->imports, make->importlib ))))
- strarray_add( &make->object_files, strmake( "%s.o", obj ));
- else
- strarray_add( &make->clean_files, strmake( "%s.o", obj ));
- output( "%s.o: %s\n", obj_dir_path( make, obj ), source->filename );
- output( "\t$(CC) -c -o $@ %s", source->filename );
- output_filenames( defines );
- if (make->module || make->staticlib || make->sharedlib || make->testdll)
- {
- output_filenames( dll_flags );
- if (source->use_msvcrt) output_filenames( msvcrt_flags );
- }
- output_filenames( extra_cflags );
- output_filenames( cpp_flags );
- output_filename( "$(CFLAGS)" );
- output( "\n" );
- }
- if (need_cross)
- {
- strarray_add( is_dll_src ? &make->clean_files : &make->crossobj_files, strmake( "%s.cross.o", obj ));
- output( "%s.cross.o: %s\n", obj_dir_path( make, obj ), source->filename );
- output( "\t$(CROSSCC) -c -o $@ %s", source->filename );
- output_filenames( defines );
- output_filenames( extra_cross_cflags );
- if (source->file->flags & FLAG_C_IMPLIB) output_filename( "-fno-builtin" );
- output_filenames( cpp_flags );
- output_filename( "$(CROSSCFLAGS)" );
- output( "\n" );
- }
- if (strendswith( source->name, ".c" ) && !(source->file->flags & FLAG_GENERATED))
- {
- strarray_add( &make->c2man_files, source->filename );
- if (make->testdll && !is_dll_src)
- {
- strarray_add( &make->ok_files, strmake( "%s.ok", obj ));
- output( "%s.ok:\n", obj_dir_path( make, obj ));
- output( "\t%s $(RUNTESTFLAGS) -T . -M %s -p %s%s %s && touch $@\n",
- root_src_dir_path( "tools/runtest" ), make->testdll,
- obj_dir_path( make, replace_extension( make->testdll, ".dll", "_test.exe" )),
- make->is_cross ? "" : dll_ext, obj );
- }
- }
- if (need_obj) output_filename( strmake( "%s.o", obj_dir_path( make, obj )));
- if (need_cross) output_filename( strmake( "%s.cross.o", obj_dir_path( make, obj )));
- output( ":" );
- output_filenames( source->dependencies );
- output( "\n" );
- }
- /* dispatch table to output rules for a single source file */
- static const struct
- {
- const char *ext;
- void (*fn)( struct makefile *make, struct incl_file *source, const char *obj );
- } output_source_funcs[] =
- {
- { "y", output_source_y },
- { "l", output_source_l },
- { "h", output_source_h },
- { "rh", output_source_h },
- { "inl", output_source_h },
- { "rc", output_source_rc },
- { "mc", output_source_mc },
- { "res", output_source_res },
- { "idl", output_source_idl },
- { "tlb", output_source_tlb },
- { "sfd", output_source_sfd },
- { "svg", output_source_svg },
- { "nls", output_source_nls },
- { "desktop", output_source_desktop },
- { "po", output_source_po },
- { "in", output_source_in },
- { "x", output_source_x },
- { "spec", output_source_spec },
- { NULL, output_source_default }
- };
- /*******************************************************************
- * has_object_file
- */
- static int has_object_file( struct makefile *make )
- {
- struct incl_file *source;
- int i;
- LIST_FOR_EACH_ENTRY( source, &make->sources, struct incl_file, entry )
- {
- char *ext = get_extension( source->name );
- if (!ext) fatal_error( "unsupported file type %s\n", source->name );
- ext++;
- for (i = 0; output_source_funcs[i].ext; i++)
- if (!strcmp( ext, output_source_funcs[i].ext )) break;
- if (!output_source_funcs[i].ext) return 1; /* default extension builds to an object file */
- }
- return 0;
- }
- /*******************************************************************
- * output_man_pages
- */
- static void output_man_pages( struct makefile *make )
- {
- if (make->c2man_files.count)
- {
- char *spec_file = src_dir_path( make, replace_extension( make->module, ".dll", ".spec" ));
- output( "manpages::\n" );
- output( "\t%s -w %s", root_src_dir_path( "tools/c2man.pl" ), spec_file );
- output_filename( strmake( "-R%s", root_src_dir_path( "" )));
- output_filename( strmake( "-I%s", root_src_dir_path( "include" )));
- output_filename( strmake( "-o documentation/man%s", man_ext ));
- output_filenames( make->c2man_files );
- output( "\n" );
- output( "htmlpages::\n" );
- output( "\t%s -Th -w %s", root_src_dir_path( "tools/c2man.pl" ), spec_file );
- output_filename( strmake( "-R%s", root_src_dir_path( "" )));
- output_filename( strmake( "-I%s", root_src_dir_path( "include" )));
- output_filename( "-o documentation/html" );
- output_filenames( make->c2man_files );
- output( "\n" );
- output( "sgmlpages::\n" );
- output( "\t%s -Ts -w %s", root_src_dir_path( "tools/c2man.pl" ), spec_file );
- output_filename( strmake( "-R%s", root_src_dir_path( "" )));
- output_filename( strmake( "-I%s", root_src_dir_path( "include" )));
- output_filename( "-o documentation/api-guide" );
- output_filenames( make->c2man_files );
- output( "\n" );
- output( "xmlpages::\n" );
- output( "\t%s -Tx -w %s", root_src_dir_path( "tools/c2man.pl" ), spec_file );
- output_filename( strmake( "-R%s", root_src_dir_path( "" )));
- output_filename( strmake( "-I%s", root_src_dir_path( "include" )));
- output_filename( "-o documentation/api-guide-xml" );
- output_filenames( make->c2man_files );
- output( "\n" );
- strarray_add( &make->phony_targets, "manpages" );
- strarray_add( &make->phony_targets, "htmlpages" );
- strarray_add( &make->phony_targets, "sgmlpages" );
- strarray_add( &make->phony_targets, "xmlpages" );
- }
- }
- /*******************************************************************
- * output_module
- */
- static void output_module( struct makefile *make )
- {
- struct strarray all_libs = empty_strarray;
- struct strarray dep_libs = empty_strarray;
- char *module_path = obj_dir_path( make, make->module );
- const char *debug_file = NULL;
- char *spec_file = NULL;
- unsigned int i;
- if (!make->is_exe) spec_file = src_dir_path( make, replace_extension( make->module, ".dll", ".spec" ));
- strarray_addall( &all_libs, add_import_libs( make, &dep_libs, make->delayimports, 1, 0 ));
- strarray_addall( &all_libs, add_import_libs( make, &dep_libs, make->imports, 0, 0 ));
- add_import_libs( make, &dep_libs, get_default_imports( make ), 0, 0 ); /* dependencies only */
- if (make->is_cross)
- {
- if (delay_load_flag)
- {
- for (i = 0; i < make->delayimports.count; i++)
- strarray_add( &all_libs, strmake( "%s%s%s", delay_load_flag, make->delayimports.str[i],
- strchr( make->delayimports.str[i], '.' ) ? "" : ".dll" ));
- }
- strarray_add( &make->all_targets, strmake( "%s", make->module ));
- add_install_rule( make, make->module, strmake( "%s", make->module ),
- strmake( "c$(dlldir)/%s", make->module ));
- debug_file = get_debug_file( make, module_path );
- output( "%s:", module_path );
- }
- else if (*dll_ext)
- {
- if (!make->use_msvcrt) strarray_addall( &all_libs, add_unix_libraries( make, &dep_libs ));
- for (i = 0; i < make->delayimports.count; i++)
- strarray_add( &all_libs, strmake( "-Wl,-delayload,%s%s", make->delayimports.str[i],
- strchr( make->delayimports.str[i], '.' ) ? "" : ".dll" ));
- strarray_add( &make->all_targets, strmake( "%s%s", make->module, dll_ext ));
- strarray_add( &make->all_targets, strmake( "%s.fake", make->module ));
- add_install_rule( make, make->module, strmake( "%s%s", make->module, dll_ext ),
- strmake( "p$(dlldir)/%s%s", make->module, dll_ext ));
- add_install_rule( make, make->module, strmake( "%s.fake", make->module ),
- strmake( "d$(dlldir)/fakedlls/%s", make->module ));
- output( "%s%s %s.fake:", module_path, dll_ext, module_path );
- }
- else
- {
- strarray_addall( &all_libs, add_unix_libraries( make, &dep_libs ));
- strarray_add( &make->all_targets, make->module );
- add_install_rule( make, make->module, make->module,
- strmake( "p$(%s)/%s", spec_file ? "dlldir" : "bindir", make->module ));
- debug_file = get_debug_file( make, module_path );
- output( "%s:", module_path );
- }
- if (spec_file) output_filename( spec_file );
- output_filenames_obj_dir( make, make->is_cross ? make->crossobj_files : make->object_files );
- output_filenames_obj_dir( make, make->res_files );
- output_filenames( dep_libs );
- output_filename( tools_path( make, "winebuild" ));
- output_filename( tools_path( make, "winegcc" ));
- output( "\n" );
- output_winegcc_command( make, make->is_cross );
- if (make->is_cross) output_filename( "-Wl,--wine-builtin" );
- if (spec_file)
- {
- output_filename( "-shared" );
- output_filename( spec_file );
- }
- output_filenames( make->extradllflags );
- output_filenames_obj_dir( make, make->is_cross ? make->crossobj_files : make->object_files );
- output_filenames_obj_dir( make, make->res_files );
- if (debug_file) output_filename( strmake( "-Wl,--debug-file,%s", debug_file ));
- output_filenames( all_libs );
- output_filename( make->is_cross ? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
- output( "\n" );
- if (make->unixobj_files.count)
- {
- struct strarray unix_imports = empty_strarray;
- struct strarray unix_libs = empty_strarray;
- struct strarray unix_deps = empty_strarray;
- char *ext, *unix_lib = xmalloc( strlen( make->module ) + strlen( dll_ext ) + 1 );
- strcpy( unix_lib, make->module );
- if ((ext = get_extension( unix_lib ))) *ext = 0;
- strcat( unix_lib, dll_ext );
- if (!strarray_exists( &make->extradllflags, "-nodefaultlibs" ))
- strarray_add( &unix_imports, "ntdll" );
- strarray_add( &unix_imports, "winecrt0" );
- strarray_addall( &unix_libs, add_import_libs( make, &unix_deps, unix_imports, 0, 1 ));
- strarray_addall( &unix_libs, add_unix_libraries( make, &unix_deps ));
- strarray_add( &make->all_targets, unix_lib );
- add_install_rule( make, make->module, unix_lib, strmake( "p$(dlldir)/%s", unix_lib ));
- output( "%s:", obj_dir_path( make, unix_lib ));
- if (spec_file) output_filename( spec_file );
- output_filenames_obj_dir( make, make->unixobj_files );
- output_filenames( unix_deps );
- output_filename( tools_path( make, "winebuild" ));
- output_filename( tools_path( make, "winegcc" ));
- output( "\n" );
- output_winegcc_command( make, 0 );
- output_filename( "-munix" );
- output_filename( "-shared" );
- if (spec_file) output_filename( spec_file );
- if (strarray_exists( &make->extradllflags, "-nodefaultlibs" )) output_filename( "-nodefaultlibs" );
- output_filenames_obj_dir( make, make->unixobj_files );
- output_filenames( unix_libs );
- output_filename( "$(LDFLAGS)" );
- output( "\n" );
- }
- if (spec_file && make->importlib)
- {
- char *importlib_path = obj_dir_path( make, strmake( "lib%s", make->importlib ));
- if (*dll_ext && !make->implib_objs.count)
- {
- strarray_add( &make->clean_files, strmake( "lib%s.def", make->importlib ));
- output( "%s.def: %s %s\n", importlib_path, tools_path( make, "winebuild" ), spec_file );
- output( "\t%s -w --def -o $@", tools_path( make, "winebuild" ) );
- output_filenames( target_flags );
- if (make->is_win16) output_filename( "-m16" );
- output_filename( "--export" );
- output_filename( spec_file );
- output( "\n" );
- add_install_rule( make, make->importlib,
- strmake( "lib%s.def", make->importlib ),
- strmake( "d$(dlldir)/lib%s.def", make->importlib ));
- }
- else
- {
- strarray_add( &make->clean_files, strmake( "lib%s.a", make->importlib ));
- if (!*dll_ext && needs_delay_lib( make ))
- {
- strarray_add( &make->clean_files, strmake( "lib%s.delay.a", make->importlib ));
- output( "%s.delay.a ", importlib_path );
- }
- output( "%s.a: %s %s", importlib_path, tools_path( make, "winebuild" ), spec_file );
- output_filenames_obj_dir( make, make->implib_objs );
- output( "\n" );
- output( "\t%s -w --implib -o $@", tools_path( make, "winebuild" ) );
- output_filenames( target_flags );
- if (make->is_win16) output_filename( "-m16" );
- output_filename( "--export" );
- output_filename( spec_file );
- output_filenames_obj_dir( make, make->implib_objs );
- output( "\n" );
- add_install_rule( make, make->importlib,
- strmake( "lib%s.a", make->importlib ),
- strmake( "d$(dlldir)/lib%s.a", make->importlib ));
- }
- if (crosstarget && (needs_cross_lib( make ) || needs_delay_lib( make )))
- {
- struct strarray cross_files = strarray_replace_extension( &make->implib_objs, ".o", ".cross.o" );
- if (needs_cross_lib( make ))
- {
- strarray_add( &make->clean_files, strmake( "lib%s.cross.a", make->importlib ));
- output_filename( strmake( "%s.cross.a", importlib_path ));
- }
- if (needs_delay_lib( make ))
- {
- strarray_add( &make->clean_files, strmake( "lib%s.delay.a", make->importlib ));
- output_filename( strmake( "%s.delay.a", importlib_path ));
- }
- output( ": %s %s", tools_path( make, "winebuild" ), spec_file );
- output_filenames_obj_dir( make, cross_files );
- output( "\n" );
- output( "\t%s -b %s -w --implib -o $@", tools_path( make, "winebuild" ), crosstarget );
- if (make->is_win16) output_filename( "-m16" );
- output_filename( "--export" );
- output_filename( spec_file );
- output_filenames_obj_dir( make, cross_files );
- output( "\n" );
- }
- if (needs_implib_symlink( make ))
- strarray_addall( &top_makefile->clean_files, output_importlib_symlinks( make ));
- }
- if (spec_file)
- output_man_pages( make );
- else if (*dll_ext && !make->is_win16 && strendswith( make->module, ".exe" ))
- {
- char *binary = replace_extension( make->module, ".exe", "" );
- add_install_rule( make, binary, "wineapploader", strmake( "t$(bindir)/%s", binary ));
- }
- }
- /*******************************************************************
- * output_static_lib
- */
- static void output_static_lib( struct makefile *make )
- {
- strarray_add( &make->all_targets, make->staticlib );
- output( "%s:", obj_dir_path( make, make->staticlib ));
- output_filenames_obj_dir( make, make->object_files );
- output_filenames_obj_dir( make, make->unixobj_files );
- output( "\n\trm -f $@\n" );
- output( "\t%s rc $@", ar );
- output_filenames_obj_dir( make, make->object_files );
- output_filenames_obj_dir( make, make->unixobj_files );
- output( "\n\t%s $@\n", ranlib );
- add_install_rule( make, make->staticlib, make->staticlib,
- strmake( "d$(dlldir)/%s", make->staticlib ));
- if (needs_cross_lib( make ))
- {
- char *name = replace_extension( make->staticlib, ".a", ".cross.a" );
- strarray_add( &make->all_targets, name );
- output( "%s: %s", obj_dir_path( make, name ), tools_path( make, "winebuild" ));
- output_filenames_obj_dir( make, make->crossobj_files );
- output( "\n" );
- output( "\t%s -b %s -w --staticlib -o $@", tools_path( make, "winebuild" ), crosstarget );
- output_filenames_obj_dir( make, make->crossobj_files );
- output( "\n" );
- }
- }
- /*******************************************************************
- * output_shared_lib
- */
- static void output_shared_lib( struct makefile *make )
- {
- unsigned int i;
- char *basename, *p;
- struct strarray names = get_shared_lib_names( make->sharedlib );
- struct strarray all_libs = empty_strarray;
- struct strarray dep_libs = empty_strarray;
- basename = xstrdup( make->sharedlib );
- if ((p = strchr( basename, '.' ))) *p = 0;
- strarray_addall( &dep_libs, get_local_dependencies( make, basename, make->in_files ));
- strarray_addall( &all_libs, get_expanded_file_local_var( make, basename, "LDFLAGS" ));
- strarray_addall( &all_libs, add_unix_libraries( make, &dep_libs ));
- output( "%s:", obj_dir_path( make, make->sharedlib ));
- output_filenames_obj_dir( make, make->object_files );
- output_filenames( dep_libs );
- output( "\n" );
- output( "\t$(CC) -o $@" );
- output_filenames_obj_dir( make, make->object_files );
- output_filenames( all_libs );
- output_filename( "$(LDFLAGS)" );
- output( "\n" );
- add_install_rule( make, make->sharedlib, make->sharedlib,
- strmake( "p$(libdir)/%s", make->sharedlib ));
- for (i = 1; i < names.count; i++)
- {
- output( "%s: %s\n", obj_dir_path( make, names.str[i] ), obj_dir_path( make, names.str[i-1] ));
- output_symlink_rule( names.str[i-1], obj_dir_path( make, names.str[i] ));
- add_install_rule( make, names.str[i], names.str[i-1],
- strmake( "y$(libdir)/%s", names.str[i] ));
- }
- strarray_addall( &make->all_targets, names );
- }
- /*******************************************************************
- * output_test_module
- */
- static void output_test_module( struct makefile *make )
- {
- char *testmodule = replace_extension( make->testdll, ".dll", "_test.exe" );
- char *stripped = replace_extension( make->testdll, ".dll", "_test-stripped.exe" );
- char *testres = replace_extension( make->testdll, ".dll", "_test.res" );
- struct strarray dep_libs = empty_strarray;
- struct strarray all_libs = add_import_libs( make, &dep_libs, make->imports, 0, 0 );
- struct makefile *parent = get_parent_makefile( make );
- const char *ext = make->is_cross ? "" : dll_ext;
- const char *parent_ext = parent && parent->is_cross ? "" : dll_ext;
- const char *debug_file;
- char *output_file;
- add_import_libs( make, &dep_libs, get_default_imports( make ), 0, 0 ); /* dependencies only */
- strarray_add( &make->all_targets, strmake( "%s%s", testmodule, ext ));
- strarray_add( &make->clean_files, strmake( "%s%s", stripped, ext ));
- output_file = strmake( "%s%s", obj_dir_path( make, testmodule ), ext );
- output( "%s:\n", output_file );
- output_winegcc_command( make, make->is_cross );
- output_filenames( make->extradllflags );
- output_filenames_obj_dir( make, make->is_cross ? make->crossobj_files : make->object_files );
- output_filenames_obj_dir( make, make->res_files );
- if ((debug_file = get_debug_file( make, output_file )))
- output_filename( strmake( "-Wl,--debug-file,%s", debug_file ));
- output_filenames( all_libs );
- output_filename( make->is_cross ? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
- output( "\n" );
- output( "%s%s:\n", obj_dir_path( make, stripped ), ext );
- output_winegcc_command( make, make->is_cross );
- output_filename( "-s" );
- output_filename( strmake( "-Wb,-F,%s", testmodule ));
- output_filenames( make->extradllflags );
- output_filenames_obj_dir( make, make->is_cross ? make->crossobj_files : make->object_files );
- output_filenames_obj_dir( make, make->res_files );
- output_filenames( all_libs );
- output_filename( make->is_cross ? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
- output( "\n" );
- output( "%s%s %s%s:", obj_dir_path( make, testmodule ), ext, obj_dir_path( make, stripped ), ext );
- output_filenames_obj_dir( make, make->is_cross ? make->crossobj_files : make->object_files );
- output_filenames_obj_dir( make, make->res_files );
- output_filenames( dep_libs );
- output_filename( tools_path( make, "winebuild" ));
- output_filename( tools_path( make, "winegcc" ));
- output( "\n" );
- output( "programs/winetest/%s: %s%s\n", testres, obj_dir_path( make, stripped ), ext );
- output( "\techo \"%s TESTRES \\\"%s%s\\\"\" | %s -u -o $@\n",
- testmodule, obj_dir_path( make, stripped ), ext, tools_path( make, "wrc" ));
- output_filenames_obj_dir( make, make->ok_files );
- output( ": %s%s", obj_dir_path( make, testmodule ), ext );
- if (parent) output( " %s%s", obj_dir_path( parent, make->testdll ), parent_ext );
- output( "\n" );
- output( "%s %s:", obj_dir_path( make, "check" ), obj_dir_path( make, "test" ));
- if (!make->disabled && parent && !parent->disabled) output_filenames_obj_dir( make, make->ok_files );
- output( "\n" );
- strarray_add_uniq( &make->phony_targets, obj_dir_path( make, "check" ));
- strarray_add_uniq( &make->phony_targets, obj_dir_path( make, "test" ));
- output( "%s::\n", obj_dir_path( make, "testclean" ));
- output( "\trm -f" );
- output_filenames_obj_dir( make, make->ok_files );
- output( "\n" );
- strarray_addall( &make->clean_files, make->ok_files );
- strarray_add_uniq( &make->phony_targets, obj_dir_path( make, "testclean" ));
- }
- /*******************************************************************
- * output_programs
- */
- static void output_programs( struct makefile *make )
- {
- unsigned int i, j;
- for (i = 0; i < make->programs.count; i++)
- {
- char *program_installed = NULL;
- char *program = strmake( "%s%s", make->programs.str[i], exe_ext );
- struct strarray deps = get_local_dependencies( make, make->programs.str[i], make->in_files );
- struct strarray all_libs = get_expanded_file_local_var( make, make->programs.str[i], "LDFLAGS" );
- struct strarray objs = get_expanded_file_local_var( make, make->programs.str[i], "OBJS" );
- struct strarray symlinks = get_expanded_file_local_var( make, make->programs.str[i], "SYMLINKS" );
- if (!objs.count) objs = make->object_files;
- if (!strarray_exists( &all_libs, "-nodefaultlibs" ))
- strarray_addall( &all_libs, add_unix_libraries( make, &deps ));
- output( "%s:", obj_dir_path( make, program ) );
- output_filenames_obj_dir( make, objs );
- output_filenames( deps );
- output( "\n" );
- output( "\t$(CC) -o $@" );
- output_filenames_obj_dir( make, objs );
- output_filenames( all_libs );
- output_filename( "$(LDFLAGS)" );
- output( "\n" );
- strarray_add( &make->all_targets, program );
- for (j = 0; j < symlinks.count; j++)
- {
- output( "%s: %s\n", obj_dir_path( make, symlinks.str[j] ), obj_dir_path( make, program ));
- output_symlink_rule( program, obj_dir_path( make, symlinks.str[j] ));
- }
- strarray_addall( &make->all_targets, symlinks );
- add_install_rule( make, program, program_installed ? program_installed : program,
- strmake( "p$(bindir)/%s", program ));
- for (j = 0; j < symlinks.count; j++)
- add_install_rule( make, symlinks.str[j], program,
- strmake( "y$(bindir)/%s%s", symlinks.str[j], exe_ext ));
- }
- }
- /*******************************************************************
- * output_subdirs
- */
- static void output_subdirs( struct makefile *make )
- {
- struct strarray all_targets = empty_strarray;
- struct strarray makefile_deps = empty_strarray;
- struct strarray clean_files = empty_strarray;
- struct strarray testclean_files = empty_strarray;
- struct strarray distclean_files = empty_strarray;
- struct strarray dependencies = empty_strarray;
- struct strarray install_lib_deps = empty_strarray;
- struct strarray install_dev_deps = empty_strarray;
- struct strarray tooldeps_deps = empty_strarray;
- struct strarray buildtest_deps = empty_strarray;
- unsigned int i;
- strarray_addall( &clean_files, make->clean_files );
- strarray_addall( &distclean_files, make->distclean_files );
- strarray_addall( &all_targets, make->all_targets );
- for (i = 0; i < subdirs.count; i++)
- {
- strarray_add( &makefile_deps, src_dir_path( submakes[i], strmake ( "%s.in", output_makefile_name )));
- strarray_addall_uniq( &make->phony_targets, submakes[i]->phony_targets );
- strarray_addall_uniq( &make->uninstall_files, submakes[i]->uninstall_files );
- strarray_addall_uniq( &dependencies, submakes[i]->dependencies );
- strarray_addall_path( &clean_files, submakes[i]->obj_dir, submakes[i]->clean_files );
- strarray_addall_path( &distclean_files, submakes[i]->obj_dir, submakes[i]->distclean_files );
- strarray_addall_path( &testclean_files, submakes[i]->obj_dir, submakes[i]->ok_files );
- strarray_addall_path( &make->pot_files, submakes[i]->obj_dir, submakes[i]->pot_files );
- if (submakes[i]->disabled) continue;
- strarray_addall_path( &all_targets, submakes[i]->obj_dir, submakes[i]->all_targets );
- if (!strcmp( submakes[i]->obj_dir, "tools" ) || !strncmp( submakes[i]->obj_dir, "tools/", 6 ))
- strarray_add( &tooldeps_deps, obj_dir_path( submakes[i], "all" ));
- if (submakes[i]->testdll)
- strarray_add( &buildtest_deps, obj_dir_path( submakes[i], "all" ));
- if (submakes[i]->install_rules[INSTALL_LIB].count)
- strarray_add( &install_lib_deps, obj_dir_path( submakes[i], "install-lib" ));
- if (submakes[i]->install_rules[INSTALL_DEV].count)
- strarray_add( &install_dev_deps, obj_dir_path( submakes[i], "install-dev" ));
- }
- strarray_addall( &dependencies, makefile_deps );
- output( "all:" );
- output_filenames( all_targets );
- output( "\n" );
- output( "Makefile:" );
- output_filenames( makefile_deps );
- output( "\n" );
- output_filenames( dependencies );
- output( ":\n" );
- if (install_lib_deps.count)
- {
- output( "install install-lib::" );
- output_filenames( install_lib_deps );
- output( "\n" );
- strarray_add_uniq( &make->phony_targets, "install" );
- strarray_add_uniq( &make->phony_targets, "install-lib" );
- }
- if (install_dev_deps.count)
- {
- output( "install install-dev::" );
- output_filenames( install_dev_deps );
- output( "\n" );
- strarray_add_uniq( &make->phony_targets, "install" );
- strarray_add_uniq( &make->phony_targets, "install-dev" );
- }
- output_uninstall_rules( make );
- if (buildtest_deps.count)
- {
- output( "buildtests:" );
- output_filenames( buildtest_deps );
- output( "\n" );
- strarray_add_uniq( &make->phony_targets, "buildtests" );
- }
- output( "check test:" );
- output_filenames( testclean_files );
- output( "\n" );
- strarray_add_uniq( &make->phony_targets, "check" );
- strarray_add_uniq( &make->phony_targets, "test" );
- output( "clean::\n");
- output_rm_filenames( clean_files );
- output( "testclean::\n");
- output_rm_filenames( testclean_files );
- output( "distclean::\n");
- output_rm_filenames( distclean_files );
- strarray_add_uniq( &make->phony_targets, "distclean" );
- strarray_add_uniq( &make->phony_targets, "testclean" );
- if (tooldeps_deps.count)
- {
- output( "__tooldeps__:" );
- output_filenames( tooldeps_deps );
- output( "\n" );
- strarray_add_uniq( &make->phony_targets, "__tooldeps__" );
- }
- if (get_expanded_make_variable( make, "GETTEXTPO_LIBS" )) output_po_files( make );
- if (make->phony_targets.count)
- {
- output( ".PHONY:" );
- output_filenames( make->phony_targets );
- output( "\n" );
- }
- }
- /*******************************************************************
- * output_sources
- */
- static void output_sources( struct makefile *make )
- {
- struct strarray all_targets = empty_strarray;
- struct incl_file *source;
- unsigned int i, j;
- strarray_add_uniq( &make->phony_targets, "all" );
- LIST_FOR_EACH_ENTRY( source, &make->sources, struct incl_file, entry )
- {
- char *obj = xstrdup( source->name );
- char *ext = get_extension( obj );
- if (!ext) fatal_error( "unsupported file type %s\n", source->name );
- *ext++ = 0;
- for (j = 0; output_source_funcs[j].ext; j++)
- if (!strcmp( ext, output_source_funcs[j].ext )) break;
- output_source_funcs[j].fn( make, source, obj );
- strarray_addall_uniq( &make->dependencies, source->dependencies );
- }
- /* special case for winetest: add resource files from other test dirs */
- if (make->obj_dir && !strcmp( make->obj_dir, "programs/winetest" ))
- {
- struct strarray tests = enable_tests;
- if (!tests.count)
- for (i = 0; i < subdirs.count; i++)
- if (submakes[i]->testdll && !submakes[i]->disabled)
- strarray_add( &tests, submakes[i]->testdll );
- for (i = 0; i < tests.count; i++)
- strarray_add( &make->res_files, replace_extension( tests.str[i], ".dll", "_test.res" ));
- }
- if (make->dlldata_files.count)
- {
- output( "%s: %s %s\n", obj_dir_path( make, "dlldata.c" ),
- tools_path( make, "widl" ), src_dir_path( make, "Makefile.in" ));
- output( "\t%s --dlldata-only -o $@", tools_path( make, "widl" ));
- output_filenames( make->dlldata_files );
- output( "\n" );
- }
- if (make->staticlib) output_static_lib( make );
- else if (make->module) output_module( make );
- else if (make->testdll) output_test_module( make );
- else if (make->sharedlib) output_shared_lib( make );
- else if (make->programs.count) output_programs( make );
- for (i = 0; i < make->scripts.count; i++)
- add_install_rule( make, make->scripts.str[i], make->scripts.str[i],
- strmake( "S$(bindir)/%s", make->scripts.str[i] ));
- for (i = 0; i < make->extra_targets.count; i++)
- if (strarray_exists( &make->dependencies, obj_dir_path( make, make->extra_targets.str[i] )))
- strarray_add( &make->clean_files, make->extra_targets.str[i] );
- else
- strarray_add( &make->all_targets, make->extra_targets.str[i] );
- if (!make->src_dir) strarray_add( &make->distclean_files, ".gitignore" );
- strarray_add( &make->distclean_files, "Makefile" );
- if (make->testdll) strarray_add( &make->distclean_files, "testlist.c" );
- if (!make->obj_dir)
- strarray_addall( &make->distclean_files, get_expanded_make_var_array( make, "CONFIGURE_TARGETS" ));
- else if (!strcmp( make->obj_dir, "po" ))
- strarray_add( &make->distclean_files, "LINGUAS" );
- strarray_addall( &make->clean_files, make->object_files );
- strarray_addall( &make->clean_files, make->crossobj_files );
- strarray_addall( &make->clean_files, make->unixobj_files );
- strarray_addall( &make->clean_files, make->res_files );
- strarray_addall( &make->clean_files, make->pot_files );
- strarray_addall( &make->clean_files, make->debug_files );
- strarray_addall( &make->clean_files, make->all_targets );
- if (make == top_makefile)
- {
- output_subdirs( make );
- return;
- }
- strarray_addall( &all_targets, make->all_targets );
- strarray_addall( &all_targets, make->font_files );
- if (all_targets.count)
- {
- output( "%s:", obj_dir_path( make, "all" ));
- output_filenames_obj_dir( make, all_targets );
- output( "\n" );
- strarray_add_uniq( &make->phony_targets, obj_dir_path( make, "all" ));
- }
- output_install_rules( make, INSTALL_LIB, "install-lib" );
- output_install_rules( make, INSTALL_DEV, "install-dev" );
- if (make->clean_files.count)
- {
- output( "%s::\n", obj_dir_path( make, "clean" ));
- output( "\trm -f" );
- output_filenames_obj_dir( make, make->clean_files );
- output( "\n" );
- strarray_add( &make->phony_targets, obj_dir_path( make, "clean" ));
- }
- }
- /*******************************************************************
- * create_temp_file
- */
- static FILE *create_temp_file( const char *orig )
- {
- char *name = xmalloc( strlen(orig) + 13 );
- unsigned int i, id = getpid();
- int fd;
- FILE *ret = NULL;
- for (i = 0; i < 100; i++)
- {
- sprintf( name, "%s.tmp%08x", orig, id );
- if ((fd = open( name, O_RDWR | O_CREAT | O_EXCL, 0666 )) != -1)
- {
- ret = fdopen( fd, "w" );
- break;
- }
- if (errno != EEXIST) break;
- id += 7777;
- }
- if (!ret) fatal_error( "failed to create output file for '%s'\n", orig );
- temp_file_name = name;
- return ret;
- }
- /*******************************************************************
- * rename_temp_file
- */
- static void rename_temp_file( const char *dest )
- {
- int ret = rename( temp_file_name, dest );
- if (ret == -1 && errno == EEXIST)
- {
- /* rename doesn't overwrite on windows */
- unlink( dest );
- ret = rename( temp_file_name, dest );
- }
- if (ret == -1) fatal_error( "failed to rename output file to '%s'\n", dest );
- temp_file_name = NULL;
- }
- /*******************************************************************
- * are_files_identical
- */
- static int are_files_identical( FILE *file1, FILE *file2 )
- {
- for (;;)
- {
- char buffer1[8192], buffer2[8192];
- int size1 = fread( buffer1, 1, sizeof(buffer1), file1 );
- int size2 = fread( buffer2, 1, sizeof(buffer2), file2 );
- if (size1 != size2) return 0;
- if (!size1) return feof( file1 ) && feof( file2 );
- if (memcmp( buffer1, buffer2, size1 )) return 0;
- }
- }
- /*******************************************************************
- * rename_temp_file_if_changed
- */
- static void rename_temp_file_if_changed( const char *dest )
- {
- FILE *file1, *file2;
- int do_rename = 1;
- if ((file1 = fopen( dest, "r" )))
- {
- if ((file2 = fopen( temp_file_name, "r" )))
- {
- do_rename = !are_files_identical( file1, file2 );
- fclose( file2 );
- }
- fclose( file1 );
- }
- if (!do_rename)
- {
- unlink( temp_file_name );
- temp_file_name = NULL;
- }
- else rename_temp_file( dest );
- }
- /*******************************************************************
- * output_linguas
- */
- static void output_linguas( const struct makefile *make )
- {
- const char *dest = obj_dir_path( make, "LINGUAS" );
- struct incl_file *source;
- output_file = create_temp_file( dest );
- output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
- LIST_FOR_EACH_ENTRY( source, &make->sources, struct incl_file, entry )
- if (strendswith( source->name, ".po" ))
- output( "%s\n", replace_extension( source->name, ".po", "" ));
- if (fclose( output_file )) fatal_perror( "write" );
- output_file = NULL;
- rename_temp_file_if_changed( dest );
- }
- /*******************************************************************
- * output_testlist
- */
- static void output_testlist( const struct makefile *make )
- {
- const char *dest = obj_dir_path( make, "testlist.c" );
- struct strarray files = empty_strarray;
- unsigned int i;
- for (i = 0; i < make->ok_files.count; i++)
- strarray_add( &files, replace_extension( make->ok_files.str[i], ".ok", "" ));
- output_file = create_temp_file( dest );
- output( "/* Automatically generated by make depend; DO NOT EDIT!! */\n\n" );
- output( "#define WIN32_LEAN_AND_MEAN\n" );
- output( "#include <windows.h>\n\n" );
- output( "#define STANDALONE\n" );
- output( "#include \"wine/test.h\"\n\n" );
- for (i = 0; i < files.count; i++) output( "extern void func_%s(void);\n", files.str[i] );
- output( "\n" );
- output( "const struct test winetest_testlist[] =\n" );
- output( "{\n" );
- for (i = 0; i < files.count; i++) output( " { \"%s\", func_%s },\n", files.str[i], files.str[i] );
- output( " { 0, 0 }\n" );
- output( "};\n" );
- if (fclose( output_file )) fatal_perror( "write" );
- output_file = NULL;
- rename_temp_file_if_changed( dest );
- }
- /*******************************************************************
- * output_gitignore
- */
- static void output_gitignore( const char *dest, struct strarray files )
- {
- int i;
- output_file = create_temp_file( dest );
- output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
- for (i = 0; i < files.count; i++)
- {
- if (!strchr( files.str[i], '/' )) output( "/" );
- output( "%s\n", files.str[i] );
- }
- if (fclose( output_file )) fatal_perror( "write" );
- output_file = NULL;
- rename_temp_file( dest );
- }
- /*******************************************************************
- * output_stub_makefile
- */
- static void output_stub_makefile( struct makefile *make )
- {
- struct strarray targets = empty_strarray;
- const char *make_var = strarray_get_value( &top_makefile->vars, "MAKE" );
- if (make_var) output( "MAKE = %s\n\n", make_var );
- output( "all:\n" );
- if (make->all_targets.count) strarray_add( &targets, "all" );
- if (make->install_rules[INSTALL_LIB].count || make->install_rules[INSTALL_DEV].count)
- strarray_add( &targets, "install" );
- if (make->install_rules[INSTALL_LIB].count) strarray_add( &targets, "install-lib" );
- if (make->install_rules[INSTALL_DEV].count) strarray_add( &targets, "install-dev" );
- if (make->clean_files.count) strarray_add( &targets, "clean" );
- if (make->ok_files.count)
- {
- strarray_add( &targets, "check" );
- strarray_add( &targets, "test" );
- strarray_add( &targets, "testclean" );
- }
- output_filenames( targets );
- output( ":\n" );
- output( "\t@cd %s && $(MAKE) %s/$@\n", get_relative_path( make->obj_dir, "" ), make->obj_dir );
- output( ".PHONY:" );
- output_filenames( targets );
- output( "\n" );
- }
- /*******************************************************************
- * output_dependencies
- */
- static void output_dependencies( struct makefile *make )
- {
- struct strarray ignore_files = empty_strarray;
- char buffer[1024];
- FILE *src_file;
- int i, found = 0;
- if (make->obj_dir) create_dir( make->obj_dir );
- output_file_name = obj_dir_path( make, output_makefile_name );
- output_file = create_temp_file( output_file_name );
- /* copy the contents of the source makefile */
- src_file = open_input_makefile( make );
- while (fgets( buffer, sizeof(buffer), src_file ) && !found)
- {
- if (fwrite( buffer, 1, strlen(buffer), output_file ) != strlen(buffer)) fatal_perror( "write" );
- found = !strncmp( buffer, separator, strlen(separator) );
- }
- if (fclose( src_file )) fatal_perror( "close" );
- input_file_name = NULL;
- if (!found) output( "\n%s (everything below this line is auto-generated; DO NOT EDIT!!)\n", separator );
- if (make == top_makefile)
- {
- for (i = 0; i < subdirs.count; i++) output_sources( submakes[i] );
- output_sources( make );
- }
- else output_stub_makefile( make );
- fclose( output_file );
- output_file = NULL;
- rename_temp_file( output_file_name );
- strarray_addall( &ignore_files, make->distclean_files );
- strarray_addall( &ignore_files, make->clean_files );
- if (make->testdll) output_testlist( make );
- if (make->obj_dir && !strcmp( make->obj_dir, "po" )) output_linguas( make );
- if (!make->src_dir) output_gitignore( obj_dir_path( make, ".gitignore" ), ignore_files );
- create_file_directories( make, ignore_files );
- output_file_name = NULL;
- }
- /*******************************************************************
- * load_sources
- */
- static void load_sources( struct makefile *make )
- {
- static const char *source_vars[] =
- {
- "SOURCES",
- "C_SRCS",
- "OBJC_SRCS",
- "RC_SRCS",
- "MC_SRCS",
- "IDL_SRCS",
- "BISON_SRCS",
- "LEX_SRCS",
- "HEADER_SRCS",
- "XTEMPLATE_SRCS",
- "SVG_SRCS",
- "FONT_SRCS",
- "IN_SRCS",
- "PO_SRCS",
- "MANPAGES",
- NULL
- };
- const char **var;
- unsigned int i;
- struct strarray value;
- struct incl_file *file;
- strarray_set_value( &make->vars, "top_srcdir", root_src_dir_path( "" ));
- strarray_set_value( &make->vars, "srcdir", src_dir_path( make, "" ));
- make->parent_dir = get_expanded_make_variable( make, "PARENTSRC" );
- make->module = get_expanded_make_variable( make, "MODULE" );
- make->testdll = get_expanded_make_variable( make, "TESTDLL" );
- make->sharedlib = get_expanded_make_variable( make, "SHAREDLIB" );
- make->staticlib = get_expanded_make_variable( make, "STATICLIB" );
- make->importlib = get_expanded_make_variable( make, "IMPORTLIB" );
- make->programs = get_expanded_make_var_array( make, "PROGRAMS" );
- make->scripts = get_expanded_make_var_array( make, "SCRIPTS" );
- make->imports = get_expanded_make_var_array( make, "IMPORTS" );
- make->delayimports = get_expanded_make_var_array( make, "DELAYIMPORTS" );
- make->extradllflags = get_expanded_make_var_array( make, "EXTRADLLFLAGS" );
- make->install_lib = get_expanded_make_var_array( make, "INSTALL_LIB" );
- make->install_dev = get_expanded_make_var_array( make, "INSTALL_DEV" );
- make->extra_targets = get_expanded_make_var_array( make, "EXTRA_TARGETS" );
- if (make->module && strendswith( make->module, ".a" )) make->staticlib = make->module;
- make->is_win16 = strarray_exists( &make->extradllflags, "-m16" );
- if ((make->module && make->staticlib) || make->testdll || make->is_win16)
- strarray_add_uniq( &make->extradllflags, "-mno-cygwin" );
- strarray_addall( &make->extradllflags, get_expanded_make_var_array( make, "APPMODE" ));
- make->disabled = make->obj_dir && strarray_exists( &disabled_dirs, make->obj_dir );
- make->use_msvcrt = strarray_exists( &make->extradllflags, "-mno-cygwin" );
- make->is_exe = strarray_exists( &make->extradllflags, "-mconsole" ) ||
- strarray_exists( &make->extradllflags, "-mwindows" );
- if (make->module && !make->install_lib.count && !make->install_dev.count)
- {
- if (make->importlib) strarray_add( &make->install_dev, make->importlib );
- if (make->staticlib) strarray_add( &make->install_dev, make->staticlib );
- else strarray_add( &make->install_lib, make->module );
- }
- make->include_paths = empty_strarray;
- make->include_args = empty_strarray;
- make->define_args = empty_strarray;
- strarray_add( &make->define_args, "-D__WINESRC__" );
- value = get_expanded_make_var_array( make, "EXTRAINCL" );
- for (i = 0; i < value.count; i++)
- if (!strncmp( value.str[i], "-I", 2 ))
- strarray_add_uniq( &make->include_paths, value.str[i] + 2 );
- else
- strarray_add_uniq( &make->define_args, value.str[i] );
- strarray_addall( &make->define_args, get_expanded_make_var_array( make, "EXTRADEFS" ));
- strarray_add( &make->include_args, strmake( "-I%s", obj_dir_path( make, "" )));
- if (make->src_dir)
- strarray_add( &make->include_args, strmake( "-I%s", make->src_dir ));
- if (make->parent_dir)
- strarray_add( &make->include_args, strmake( "-I%s", src_dir_path( make, make->parent_dir )));
- strarray_add( &make->include_args, "-Iinclude" );
- if (root_src_dir) strarray_add( &make->include_args, strmake( "-I%s", root_src_dir_path( "include" )));
- list_init( &make->sources );
- list_init( &make->includes );
- for (var = source_vars; *var; var++)
- {
- value = get_expanded_make_var_array( make, *var );
- for (i = 0; i < value.count; i++) add_src_file( make, value.str[i] );
- }
- add_generated_sources( make );
- if (!make->use_msvcrt && !has_object_file( make ))
- {
- strarray_add( &make->extradllflags, "-mno-cygwin" );
- make->use_msvcrt = 1;
- }
- if (make->use_msvcrt)
- {
- const char *crt_dll = add_crt_import( make, &make->imports );
- if (crt_dll && !strncmp( crt_dll, "ucrt", 4 )) strarray_add( &make->define_args, "-D_UCRT" );
- else
- {
- unsigned int msvcrt_version = 0;
- if (crt_dll) sscanf( crt_dll, "msvcr%u", &msvcrt_version );
- strarray_add( &make->define_args, strmake( "-D_MSVCR_VER=%u", msvcrt_version ));
- }
- }
- LIST_FOR_EACH_ENTRY( file, &make->includes, struct incl_file, entry ) parse_file( make, file, 0 );
- LIST_FOR_EACH_ENTRY( file, &make->sources, struct incl_file, entry ) get_dependencies( file, file );
- make->is_cross = crosstarget && make->use_msvcrt;
- if (make->is_cross)
- {
- strarray_addall_uniq( &cross_import_libs, make->imports );
- strarray_addall_uniq( &cross_import_libs, make->extra_imports );
- if (make->is_win16) strarray_add_uniq( &cross_import_libs, "kernel" );
- strarray_add_uniq( &cross_import_libs, "winecrt0" );
- strarray_add_uniq( &cross_import_libs, "kernel32" );
- strarray_add_uniq( &cross_import_libs, "ntdll" );
- }
- if (!*dll_ext || make->is_cross)
- for (i = 0; i < make->delayimports.count; i++)
- strarray_add_uniq( &delay_import_libs, get_base_name( make->delayimports.str[i] ));
- }
- /*******************************************************************
- * parse_makeflags
- */
- static void parse_makeflags( const char *flags )
- {
- const char *p = flags;
- char *var, *buffer = xmalloc( strlen(flags) + 1 );
- while (*p)
- {
- while (isspace(*p)) p++;
- var = buffer;
- while (*p && !isspace(*p))
- {
- if (*p == '\\' && p[1]) p++;
- *var++ = *p++;
- }
- *var = 0;
- if (var > buffer) set_make_variable( &cmdline_vars, buffer );
- }
- }
- /*******************************************************************
- * parse_option
- */
- static int parse_option( const char *opt )
- {
- if (opt[0] != '-')
- {
- if (strchr( opt, '=' )) return set_make_variable( &cmdline_vars, opt );
- return 0;
- }
- switch(opt[1])
- {
- case 'f':
- if (opt[2]) output_makefile_name = opt + 2;
- break;
- case 'R':
- relative_dir_mode = 1;
- break;
- default:
- fprintf( stderr, "Unknown option '%s'\n%s", opt, Usage );
- exit(1);
- }
- return 1;
- }
- /*******************************************************************
- * main
- */
- int main( int argc, char *argv[] )
- {
- const char *makeflags = getenv( "MAKEFLAGS" );
- int i, j;
- if (makeflags) parse_makeflags( makeflags );
- i = 1;
- while (i < argc)
- {
- if (parse_option( argv[i] ))
- {
- for (j = i; j < argc; j++) argv[j] = argv[j+1];
- argc--;
- }
- else i++;
- }
- if (relative_dir_mode)
- {
- char *relpath;
- if (argc != 3)
- {
- fprintf( stderr, "Option -R needs two directories\n%s", Usage );
- exit( 1 );
- }
- relpath = get_relative_path( argv[1], argv[2] );
- printf( "%s\n", relpath ? relpath : "." );
- exit( 0 );
- }
- if (argc > 1) fatal_error( "Directory arguments not supported in this mode\n" );
- atexit( cleanup_files );
- signal( SIGTERM, exit_on_signal );
- signal( SIGINT, exit_on_signal );
- #ifdef SIGHUP
- signal( SIGHUP, exit_on_signal );
- #endif
- for (i = 0; i < HASH_SIZE; i++) list_init( &files[i] );
- top_makefile = parse_makefile( NULL );
- target_flags = get_expanded_make_var_array( top_makefile, "TARGETFLAGS" );
- msvcrt_flags = get_expanded_make_var_array( top_makefile, "MSVCRTFLAGS" );
- dll_flags = get_expanded_make_var_array( top_makefile, "DLLFLAGS" );
- extra_cflags = get_expanded_make_var_array( top_makefile, "EXTRACFLAGS" );
- extra_cross_cflags = get_expanded_make_var_array( top_makefile, "EXTRACROSSCFLAGS" );
- cpp_flags = get_expanded_make_var_array( top_makefile, "CPPFLAGS" );
- lddll_flags = get_expanded_make_var_array( top_makefile, "LDDLLFLAGS" );
- libs = get_expanded_make_var_array( top_makefile, "LIBS" );
- enable_tests = get_expanded_make_var_array( top_makefile, "ENABLE_TESTS" );
- delay_load_flag = get_expanded_make_variable( top_makefile, "DELAYLOADFLAG" );
- top_install_lib = get_expanded_make_var_array( top_makefile, "TOP_INSTALL_LIB" );
- top_install_dev = get_expanded_make_var_array( top_makefile, "TOP_INSTALL_DEV" );
- root_src_dir = get_expanded_make_variable( top_makefile, "srcdir" );
- tools_dir = get_expanded_make_variable( top_makefile, "TOOLSDIR" );
- tools_ext = get_expanded_make_variable( top_makefile, "TOOLSEXT" );
- exe_ext = get_expanded_make_variable( top_makefile, "EXEEXT" );
- man_ext = get_expanded_make_variable( top_makefile, "api_manext" );
- dll_ext = (exe_ext && !strcmp( exe_ext, ".exe" )) ? "" : ".so";
- crosstarget = get_expanded_make_variable( top_makefile, "CROSSTARGET" );
- crossdebug = get_expanded_make_variable( top_makefile, "CROSSDEBUG" );
- fontforge = get_expanded_make_variable( top_makefile, "FONTFORGE" );
- convert = get_expanded_make_variable( top_makefile, "CONVERT" );
- flex = get_expanded_make_variable( top_makefile, "FLEX" );
- bison = get_expanded_make_variable( top_makefile, "BISON" );
- ar = get_expanded_make_variable( top_makefile, "AR" );
- ranlib = get_expanded_make_variable( top_makefile, "RANLIB" );
- rsvg = get_expanded_make_variable( top_makefile, "RSVG" );
- icotool = get_expanded_make_variable( top_makefile, "ICOTOOL" );
- dlltool = get_expanded_make_variable( top_makefile, "DLLTOOL" );
- msgfmt = get_expanded_make_variable( top_makefile, "MSGFMT" );
- sed_cmd = get_expanded_make_variable( top_makefile, "SED_CMD" );
- ln_s = get_expanded_make_variable( top_makefile, "LN_S" );
- if (root_src_dir && !strcmp( root_src_dir, "." )) root_src_dir = NULL;
- if (tools_dir && !strcmp( tools_dir, "." )) tools_dir = NULL;
- if (!exe_ext) exe_ext = "";
- if (!tools_ext) tools_ext = "";
- if (!man_ext) man_ext = "3w";
- top_makefile->src_dir = root_src_dir;
- subdirs = get_expanded_make_var_array( top_makefile, "SUBDIRS" );
- disabled_dirs = get_expanded_make_var_array( top_makefile, "DISABLED_SUBDIRS" );
- submakes = xmalloc( subdirs.count * sizeof(*submakes) );
- for (i = 0; i < subdirs.count; i++) submakes[i] = parse_makefile( subdirs.str[i] );
- load_sources( top_makefile );
- for (i = 0; i < subdirs.count; i++) load_sources( submakes[i] );
- output_dependencies( top_makefile );
- for (i = 0; i < subdirs.count; i++) output_dependencies( submakes[i] );
- return 0;
- }
|