makefile.fpc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. #
  2. # $Id$
  3. # Copyright (c) 1998 by the Free Pascal Development Team
  4. #
  5. # Common makefile for Free Pascal
  6. #
  7. # See the file COPYING.FPC, included in this distribution,
  8. # for details about the copyright.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. #
  14. #####################################################################
  15. # Force default settings
  16. #####################################################################
  17. # Latest release version
  18. override RELEASEVER:=0.99.9
  19. #####################################################################
  20. # Autodetect OS (Linux or Dos or Windows NT)
  21. # define inlinux when running under linux
  22. # define inWinNT when running under WinNT
  23. #####################################################################
  24. PWD=$(strip $(wildcard $(addsuffix /pwd.exe,$(subst ;, ,$(PATH)))))
  25. ifeq ($(PWD),)
  26. PWD=$(strip $(wildcard $(addsuffix /pwd,$(subst :, ,$(PATH)))))
  27. ifeq ($(PWD),)
  28. nopwd:
  29. @echo
  30. @echo You need the GNU pwd,cp,mv,rm,install utils to use this makefile!
  31. @echo Get ftp://tflily.fys.kuleuven.ac.be/pub/fpc/dist/gnuutils.zip
  32. @echo
  33. @exit
  34. else
  35. inlinux=1
  36. endif
  37. else
  38. PWD:=$(subst \,/,$(firstword $(PWD)))
  39. endif
  40. # Detect NT - NT sets OS to Windows_NT
  41. ifndef inlinux
  42. ifeq ($(OS),Windows_NT)
  43. inWinNT=1
  44. endif
  45. endif
  46. #####################################################################
  47. # Targets
  48. #####################################################################
  49. # Target OS
  50. ifndef OS_TARGET
  51. ifdef inlinux
  52. OS_TARGET=linux
  53. else
  54. ifdef inWinNT
  55. OS_TARGET=win32
  56. else
  57. OS_TARGET=go32v2
  58. endif
  59. endif
  60. endif
  61. # Source OS
  62. ifndef OS_SOURCE
  63. ifdef inlinux
  64. OS_SOURCE=linux
  65. else
  66. ifndef inWinNT
  67. OS_SOURCE=win32
  68. else
  69. OS_SOURCE=go32v2
  70. endif
  71. endif
  72. endif
  73. # CPU
  74. ifndef CPU
  75. CPU=i386
  76. endif
  77. # Options
  78. ifndef OPT
  79. OPT=
  80. endif
  81. # What compiler to use ?
  82. ifndef PP
  83. PP=ppc386
  84. endif
  85. # assembler, redefine it if cross compiling
  86. ifndef AS
  87. AS=as
  88. endif
  89. # linker, but probably not used
  90. ifndef LD
  91. LD=ld
  92. endif
  93. # Release ? Then force OPT and don't use extra opts via commandline
  94. ifdef RELEASE
  95. override OPT:=-Xs -OG2p2 -n
  96. endif
  97. # Verbose settings (warning,note,info)
  98. ifdef VERBOSE
  99. override OPT+=-vwni
  100. endif
  101. #####################################################################
  102. # Shell commands
  103. #####################################################################
  104. # To copy pograms
  105. ifndef COPY
  106. COPY=cp -fp
  107. endif
  108. # To move pograms
  109. ifndef MOVE
  110. MOVE=mv -f
  111. endif
  112. # Check delete program
  113. ifndef DEL
  114. DEL=rm -f
  115. endif
  116. # Check deltree program
  117. ifndef DELTREE
  118. DELTREE=rm -rf
  119. endif
  120. # To install files
  121. ifndef INSTALL
  122. ifdef inlinux
  123. INSTALL=install -m 644
  124. else
  125. INSTALL=$(COPY)
  126. # ginstall has the strange thing to stubify all .o files !
  127. #INSTALL=ginstall -m 644
  128. endif
  129. endif
  130. # To install programs
  131. ifndef INSTALLEXE
  132. ifdef inlinux
  133. INSTALLEXE=install -m 755
  134. else
  135. INSTALLEXE=$(COPY)
  136. # ginstall has the strange thing to stubify all .o files !
  137. #INSTALLEXE=ginstall -m 755
  138. endif
  139. endif
  140. # To make a directory.
  141. ifndef MKDIR
  142. ifdef inlinux
  143. MKDIR=install -m 755 -d
  144. else
  145. MKDIR=ginstall -m 755 -d
  146. endif
  147. endif
  148. #####################################################################
  149. # Default Tools
  150. #####################################################################
  151. # ppas.bat / ppas.sh
  152. ifdef inlinux
  153. PPAS=ppas.sh
  154. else
  155. PPAS=ppas.bat
  156. endif
  157. # ldconfig to rebuild .so cache
  158. ifdef inlinux
  159. LDCONFIG=ldconfig
  160. else
  161. LDCONFIG=
  162. endif
  163. # Where is the ppumove program ?
  164. ifndef PPUMOVE
  165. PPUMOVE=ppumove
  166. endif
  167. # diff
  168. ifndef DIFF
  169. DIFF=diff
  170. endif
  171. # date
  172. ifndef DATE
  173. # first try go32v2 specific gdate
  174. DATE=$(strip $(wildcard $(addsuffix /gdate.exe,$(subst ;, ,$(PATH)))))
  175. # try generic date.exe
  176. ifeq ($(DATE),)
  177. DATE=$(strip $(wildcard $(addsuffix /date.exe,$(subst ;, ,$(PATH)))))
  178. # finally try for linux
  179. ifeq ($(DATE),)
  180. DATE=$(strip $(wildcard $(addsuffix /date,$(subst :, ,$(PATH)))))
  181. ifeq ($(DATE),)
  182. DATE=
  183. endif
  184. else
  185. DATE:=$(subst \,/,$(firstword $(DATE)))
  186. endif
  187. else
  188. DATE:=$(subst \,/,$(firstword $(DATE)))
  189. endif
  190. endif
  191. # Sed
  192. ifndef SED
  193. SED=$(strip $(wildcard $(addsuffix /sed.exe,$(subst ;, ,$(PATH)))))
  194. ifeq ($(SED),)
  195. SED=$(strip $(wildcard $(addsuffix /sed,$(subst :, ,$(PATH)))))
  196. ifeq ($(SED),)
  197. SED=
  198. endif
  199. else
  200. SED:=$(subst \,/,$(firstword $(SED)))
  201. endif
  202. endif
  203. #####################################################################
  204. # Default Directories
  205. #####################################################################
  206. # Base dir
  207. ifdef PWD
  208. BASEDIR=$(shell $(PWD))
  209. endif
  210. # set the directory to the rtl base
  211. ifndef RTLDIR
  212. ifdef RTL
  213. RTLDIR=$(RTL)
  214. else
  215. RTLDIR:=$(BASEDIR)/../rtl
  216. endif
  217. endif
  218. # specify where units are.
  219. ifndef UNITDIR
  220. UNITDIR=$(RTLDIR)/$(OS_TARGET)
  221. ifeq ($(OS_TARGET),go32v1)
  222. UNITDIR=$(RTLDIR)/dos/go32v1
  223. endif
  224. ifeq ($(OS_TARGET),go32v2)
  225. UNITDIR=$(RTLDIR)/dos/go32v2
  226. endif
  227. endif
  228. # set the prefix directory where to install everything
  229. ifndef PREFIXINSTALLDIR
  230. ifdef inlinux
  231. PREFIXINSTALLDIR=/usr
  232. else
  233. PREFIXINSTALLDIR=/pp
  234. endif
  235. endif
  236. # set the base directory where to install everything
  237. ifndef BASEINSTALLDIR
  238. ifdef inlinux
  239. BASEINSTALLDIR=$(PREFIXINSTALLDIR)/lib/fpc/$(RELEASEVER)
  240. else
  241. BASEINSTALLDIR=$(PREFIXINSTALLDIR)
  242. endif
  243. endif
  244. #####################################################################
  245. # Install Directories based on BASEINSTALLDIR
  246. #####################################################################
  247. # Linux binary really goes to baseinstalldir
  248. ifndef LIBINSTALLDIR
  249. ifdef inlinux
  250. LIBINSTALLDIR=$(BASEINSTALLDIR)
  251. else
  252. LIBINSTALLDIR=$(BASEINSTALLDIR)/lib
  253. endif
  254. endif
  255. # set the directory where to install the binaries
  256. ifndef BININSTALLDIR
  257. ifdef inlinux
  258. BININSTALLDIR=$(PREFIXINSTALLDIR)/bin
  259. else
  260. BININSTALLDIR=$(BASEINSTALLDIR)/bin/$(OS_TARGET)
  261. endif
  262. endif
  263. # set the directory where to install the units.
  264. ifndef UNITINSTALLDIR
  265. ifdef inlinux
  266. UNITINSTALLDIR=$(BASEINSTALLDIR)/linuxunits
  267. else
  268. UNITINSTALLDIR=$(BASEINSTALLDIR)/rtl/$(OS_TARGET)
  269. endif
  270. endif
  271. # set the directory where to install the units.
  272. ifndef STATIC_UNITINSTALLDIR
  273. ifdef inlinux
  274. STATIC_UNITINSTALLDIR=$(BASEINSTALLDIR)/staticunits
  275. else
  276. STATIC_UNITINSTALLDIR=$(BASEINSTALLDIR)/rtl/$(OS_TARGET)/static
  277. endif
  278. endif
  279. # set the directory where to install the units.
  280. ifndef SHARED_UNITINSTALLDIR
  281. ifdef inlinux
  282. SHARED_UNITINSTALLDIR=$(BASEINSTALLDIR)/sharedunits
  283. else
  284. SHARED_UNITINSTALLDIR=$(BASEINSTALLDIR)/rtl/$(OS_TARGET)/shared
  285. endif
  286. endif
  287. # set the directory where to install the libs (must exist)
  288. ifndef STATIC_LIBINSTALLDIR
  289. ifdef inlinux
  290. STATIC_LIBINSTALLDIR=$(BASEINSTALLDIR)/staticunits
  291. else
  292. STATIC_LIBINSTALLDIR=$(STATIC_UNITINSTALLDIR)
  293. endif
  294. endif
  295. # set the directory where to install the libs (must exist)
  296. ifndef SHARED_LIBINSTALLDIR
  297. ifdef inlinux
  298. SHARED_LIBINSTALLDIR=$(PREFIXINSTALLDIR)/lib
  299. else
  300. SHARED_LIBINSTALLDIR=$(SHARED_UNITINSTALLDIR)
  301. endif
  302. endif
  303. # Where the .msg files will be stored
  304. ifndef MSGINSTALLDIR
  305. ifdef inlinux
  306. MSGINSTALLDIR=$(BASEINSTALLDIR)/msg
  307. else
  308. MSGINSTALLDIR=$(BININSTALLDIR)
  309. endif
  310. endif
  311. # Where the doc files will be stored
  312. ifndef DOCINSTALLDIR
  313. ifdef inlinux
  314. DOCINSTALLDIR=$(PREFIXINSTALLDIR)/doc/fpc/$(RELEASEVER)
  315. else
  316. DOCINSTALLDIR=$(BASEINSTALLDIR)/doc
  317. endif
  318. endif
  319. #####################################################################
  320. # Compiler Command Line
  321. #####################################################################
  322. # Load commandline OPTDEF and add CPU define
  323. override PPOPTDEF=$(OPTDEF) -d$(CPU)
  324. # Load commandline OPT and add target and unit dir to be sure
  325. override PPOPT=$(OPT) -T$(OS_TARGET) -Fu$(UNITDIR) $(NEEDOPT)
  326. # Add include dirs INC and PROCINC
  327. ifdef INC
  328. override PPOPT+=-I$(INC)
  329. endif
  330. ifdef PROCINC
  331. override PPOPT+=-I$(PROCINC)
  332. endif
  333. ifdef OSINC
  334. override PPOPT+=-I$(OSINC)
  335. endif
  336. # Target dirs
  337. ifdef TARGETDIR
  338. override PPOPT+=-FE$(TARGETDIR)
  339. endif
  340. ifdef UNITTARGETDIR
  341. override PPOPT+=-FU$(UNITTARGETDIR)
  342. endif
  343. # Smartlinking
  344. ifeq ($(SMARTLINK),YES)
  345. ifeq ($(LIBTYPE),shared)
  346. override SMARTLINK=NO
  347. else
  348. override PPOPT+=-Cx
  349. endif
  350. endif
  351. # Add library type, for static libraries smartlinking is automatic used
  352. ifeq ($(LIBTYPE),shared)
  353. override PPOPT+=-CD
  354. else
  355. ifeq ($(LIBTYPE),static)
  356. override PPOPT+=-CS
  357. endif
  358. endif
  359. # Add library name
  360. ifneq ($(LIBNAME),)
  361. override PPOPT:=$(PPOPT) -o$(LIBNAME)
  362. endif
  363. # Add defines from PPOPTDEF to PPOPT
  364. override PPOPT:=$(PPOPT) $(PPOPTDEF)
  365. # Was a config file specified ?
  366. ifdef CFGFILE
  367. override PPOPT:=$(PPOPT) @$(CFGFILE)
  368. endif
  369. override COMPILER=$(PP) $(PPOPT)
  370. #####################################################################
  371. # Default extensions
  372. #####################################################################
  373. # Default needed extensions (Go32v2,Linux)
  374. PPLEXT=.ppl
  375. PPUEXT=.ppu
  376. OEXT=.o
  377. ASMEXT=.s
  378. SMARTEXT=.sl
  379. STATICLIBEXT=.a
  380. SHAREDLIBEXT=.so
  381. # Executable extension
  382. ifdef inlinux
  383. EXEEXT=
  384. else
  385. EXEEXT=.exe
  386. endif
  387. # Go32v1
  388. ifeq ($(OS_TARGET),go32v1)
  389. PPUEXT=.pp1
  390. OEXT=.o1
  391. ASMEXT=.s1
  392. SMARTEXT=.sl1
  393. STATICLIBEXT=.a1
  394. SHAREDLIBEXT=.so1
  395. endif
  396. # Win32
  397. ifeq ($(OS_TARGET),win32)
  398. PPUEXT=.ppw
  399. OEXT=.ow
  400. ASMEXT=.sw
  401. SMARTEXT=.slw
  402. STATICLIBEXT=.aw
  403. SHAREDLIBEXT=.dll
  404. endif
  405. # OS/2
  406. ifeq ($(OS_TARGET),os2)
  407. PPUEXT=.ppo
  408. ASMEXT=.so2
  409. OEXT=.o2
  410. SMARTEXT=.so
  411. STATICLIBEXT=.ao
  412. SHAREDLIBEXT=.dll
  413. endif
  414. # determine libary extension.
  415. ifeq ($(LIBTYPE),static)
  416. LIBEXT=$(STATICLIBEXT)
  417. else
  418. LIBEXT=$(SHAREDLIBEXT)
  419. endif
  420. # library prefix
  421. LIBPREFIX=lib
  422. ifeq ($(OS_TARGET),go32v2)
  423. LIBPREFIX=
  424. endif
  425. ifeq ($(OS_TARGET),go32v1)
  426. LIBPREFIX=
  427. endif
  428. # determine with .pas extension is used
  429. ifdef EXEOBJECTS
  430. override TESTPAS:=$(strip $(wildcard $(addsuffix .pas,$(firstword $(EXEOBJECTS)))))
  431. else
  432. override TESTPAS:=$(strip $(wildcard $(addsuffix .pas,$(firstword $(UNITOBJECTS)))))
  433. endif
  434. ifeq ($(TESTPAS),)
  435. PASEXT=.pp
  436. else
  437. PASEXT=.pas
  438. endif
  439. #####################################################################
  440. # Export commandline values, so nesting use the same values
  441. #####################################################################
  442. export OS_SOURCE OS_TARGET OPT OPTDEF CPU PP RELEASE VERBOSE
  443. export SMARTLINK LIBTYPE LIBNAME
  444. export BASEINSTALLDIR
  445. #####################################################################
  446. # General compile rules
  447. #####################################################################
  448. # Create Filenames
  449. EXEFILES=$(addsuffix $(EXEEXT),$(EXEOBJECTS))
  450. UNITFILES=$(addsuffix $(PPUEXT),$(UNITOBJECTS))
  451. UNITOFILES=$(addsuffix $(OEXT),$(UNITOBJECTS))
  452. .PHONY : all clean install \
  453. info cfginfo objectinfo installinfo filesinfo
  454. .SUFFIXES : $(EXEEXT) $(PPUEXT) $(PASEXT)
  455. ifdef DEFAULTUNITS
  456. all: units
  457. else
  458. all: units exes
  459. endif
  460. units: $(UNITFILES)
  461. exes: $(EXEFILES)
  462. # General compile rules
  463. %$(PPUEXT): %$(PASEXT)
  464. $(COMPILER) $<
  465. %$(EXEEXT): %$(PASEXT)
  466. $(COMPILER) $<
  467. #####################################################################
  468. # Install rules
  469. #####################################################################
  470. install : all
  471. ifdef EXEOBJECTS
  472. $(MKDIR) $(BININSTALLDIR)
  473. $(INSTALLEXE) $(EXEFILES) $(BININSTALLDIR)
  474. endif
  475. ifdef UNITOBJECTS
  476. $(MKDIR) $(UNITINSTALLDIR)
  477. ifeq ($(SMARTLINK),YES)
  478. $(INSTALL) $(LIBPREFIX)$(LIBNAME)$(LIBEXT) $(UNITINSTALLDIR)
  479. else
  480. $(INSTALL) $(UNITFILES) $(UNITOFILES) $(UNITINSTALLDIR)
  481. endif
  482. endif
  483. #####################################################################
  484. # Clean rules
  485. #####################################################################
  486. clean:
  487. -$(DEL) *$(OEXT) *$(ASMEXT) *$(PPUEXT) *$(STATICLIBEXT) *$(SHAREDLIBEXT) $(PPAS) link.res log
  488. -$(DELTREE) *$(SMARTEXT)
  489. ifdef EXEOBJECTS
  490. -$(DEL) $(EXEFILES)
  491. endif
  492. #####################################################################
  493. # Depend rules
  494. #####################################################################
  495. depend:
  496. makedep $(UNITOBJECTS)
  497. #####################################################################
  498. # Info rules
  499. #####################################################################
  500. info: cfginfo objectinfo installinfo
  501. cfginfo:
  502. @echo
  503. @echo == Configuration info ==
  504. @echo
  505. @echo Source.... $(OS_SOURCE)
  506. @echo Target.... $(OS_TARGET)
  507. @echo Basedir... $(BASEDIR)
  508. @echo Pwd....... $(PWD)
  509. ifdef SED
  510. @echo Sed....... $(SED)
  511. endif
  512. @echo
  513. objectinfo:
  514. @echo
  515. @echo == Object info ==
  516. @echo
  517. @echo UnitObjects... $(UNITOBJECTS)
  518. @echo ExeObjects.... $(EXEOBJECTS)
  519. @echo
  520. installinfo:
  521. @echo
  522. @echo == Install info ==
  523. @echo
  524. @echo BaseInstallDir....... $(BASEINSTALLDIR)
  525. @echo BinInstallDir........ $(BININSTALLDIR)
  526. @echo UnitInstallDir....... $(UNITINSTALLDIR)
  527. @echo StaticUnitInstallDir. $(STATIC_UNITINSTALLDIR)
  528. @echo SharedUnitInstallDir. $(SHARED_UNITINSTALLDIR)
  529. @echo LibInstallDir........ $(LIBINSTALLDIR)
  530. @echo StaticLibInstallDir.. $(STATIC_LIBINSTALLDIR)
  531. @echo SharedLibInstallDir.. $(SHARED_LIBINSTALLDIR)
  532. @echo MsgInstallDir........ $(MSGINSTALLDIR)
  533. @echo DocInstallDir........ $(DOCINSTALLDIR)
  534. @echo
  535. # try to get the files in the currentdir
  536. PASFILES:=$(wildcard *.pas)
  537. PPFILES:=$(wildcard *.pp)
  538. INCFILES:=$(wildcard *.inc)
  539. MSGFILES:=$(wildcard *.msg)
  540. ASFILES:=$(wildcard *.as)
  541. filesinfo:
  542. @echo
  543. @echo == Files info ==
  544. @echo
  545. ifdef PASFILES
  546. @echo Pas files are $(PASFILES)
  547. endif
  548. ifdef PPFILES
  549. @echo PP files are $(PPFILES)
  550. endif
  551. ifdef INCFILES
  552. @echo Inc files are $(INCFILES)
  553. endif
  554. ifdef MSGFILES
  555. @echo Msg files are $(MSGFILES)
  556. endif
  557. ifdef ASFILES
  558. @echo As files are $(ASFILES)
  559. endif