makefile.fpc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  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. endif
  222. # set the prefix directory where to install everything
  223. ifndef PREFIXINSTALLDIR
  224. ifdef inlinux
  225. PREFIXINSTALLDIR=/usr
  226. else
  227. PREFIXINSTALLDIR=/pp
  228. endif
  229. endif
  230. # set the base directory where to install everything
  231. ifndef BASEINSTALLDIR
  232. ifdef inlinux
  233. BASEINSTALLDIR=$(PREFIXINSTALLDIR)/lib/fpc/$(RELEASEVER)
  234. else
  235. BASEINSTALLDIR=$(PREFIXINSTALLDIR)
  236. endif
  237. endif
  238. #####################################################################
  239. # Install Directories based on BASEINSTALLDIR
  240. #####################################################################
  241. # Linux binary really goes to baseinstalldir
  242. ifndef LIBINSTALLDIR
  243. ifdef inlinux
  244. LIBINSTALLDIR=$(BASEINSTALLDIR)
  245. else
  246. LIBINSTALLDIR=$(BASEINSTALLDIR)/lib
  247. endif
  248. endif
  249. # set the directory where to install the binaries
  250. ifndef BININSTALLDIR
  251. ifdef inlinux
  252. BININSTALLDIR=$(PREFIXINSTALLDIR)/bin
  253. else
  254. BININSTALLDIR=$(BASEINSTALLDIR)/bin/$(OS_TARGET)
  255. endif
  256. endif
  257. # set the directory where to install the units.
  258. ifndef UNITINSTALLDIR
  259. ifdef inlinux
  260. UNITINSTALLDIR=$(BASEINSTALLDIR)/linuxunits
  261. else
  262. UNITINSTALLDIR=$(BASEINSTALLDIR)/rtl/$(OS_TARGET)
  263. endif
  264. endif
  265. # set the directory where to install the units.
  266. ifndef STATIC_UNITINSTALLDIR
  267. ifdef inlinux
  268. STATIC_UNITINSTALLDIR=$(BASEINSTALLDIR)/staticunits
  269. else
  270. STATIC_UNITINSTALLDIR=$(BASEINSTALLDIR)/rtl/$(OS_TARGET)/static
  271. endif
  272. endif
  273. # set the directory where to install the units.
  274. ifndef SHARED_UNITINSTALLDIR
  275. ifdef inlinux
  276. SHARED_UNITINSTALLDIR=$(BASEINSTALLDIR)/sharedunits
  277. else
  278. SHARED_UNITINSTALLDIR=$(BASEINSTALLDIR)/rtl/$(OS_TARGET)/shared
  279. endif
  280. endif
  281. # set the directory where to install the libs (must exist)
  282. ifndef STATIC_LIBINSTALLDIR
  283. ifdef inlinux
  284. STATIC_LIBINSTALLDIR=$(BASEINSTALLDIR)/staticunits
  285. else
  286. STATIC_LIBINSTALLDIR=$(STATIC_UNITINSTALLDIR)
  287. endif
  288. endif
  289. # set the directory where to install the libs (must exist)
  290. ifndef SHARED_LIBINSTALLDIR
  291. ifdef inlinux
  292. SHARED_LIBINSTALLDIR=$(PREFIXINSTALLDIR)/lib
  293. else
  294. SHARED_LIBINSTALLDIR=$(SHARED_UNITINSTALLDIR)
  295. endif
  296. endif
  297. # Where the .msg files will be stored
  298. ifndef MSGINSTALLDIR
  299. ifdef inlinux
  300. MSGINSTALLDIR=$(BASEINSTALLDIR)/msg
  301. else
  302. MSGINSTALLDIR=$(BININSTALLDIR)
  303. endif
  304. endif
  305. # Where the doc files will be stored
  306. ifndef DOCINSTALLDIR
  307. ifdef inlinux
  308. DOCINSTALLDIR=$(PREFIXINSTALLDIR)/doc/fpc/$(RELEASEVER)
  309. else
  310. DOCINSTALLDIR=$(BASEINSTALLDIR)/doc
  311. endif
  312. endif
  313. #####################################################################
  314. # Compiler Command Line
  315. #####################################################################
  316. # Load commandline OPTDEF and add CPU define
  317. override PPOPTDEF=$(OPTDEF) -d$(CPU)
  318. # Load commandline OPT and add target and unit dir to be sure
  319. override PPOPT=$(OPT) -T$(OS_TARGET) -Fu$(UNITDIR) $(NEEDOPT)
  320. # Add include dirs INC and PROCINC
  321. ifdef INC
  322. override PPOPT+=-I$(INC)
  323. endif
  324. ifdef PROCINC
  325. override PPOPT+=-I$(PROCINC)
  326. endif
  327. ifdef OSINC
  328. override PPOPT+=-I$(OSINC)
  329. endif
  330. # Target dirs
  331. ifdef TARGETDIR
  332. override PPOPT+=-FE$(TARGETDIR)
  333. endif
  334. ifdef UNITTARGETDIR
  335. override PPOPT+=-FU$(UNITTARGETDIR)
  336. endif
  337. # Smartlinking
  338. ifeq ($(SMARTLINK),YES)
  339. ifeq ($(LIBTYPE),shared)
  340. override SMARTLINK=NO
  341. else
  342. override PPOPT+=-Cx
  343. endif
  344. endif
  345. # Add library type, for static libraries smartlinking is automatic used
  346. ifeq ($(LIBTYPE),shared)
  347. override PPOPT+=-CD
  348. else
  349. ifeq ($(LIBTYPE),static)
  350. override PPOPT+=-CS
  351. endif
  352. endif
  353. # Add library name
  354. ifneq ($(LIBNAME),)
  355. override PPOPT:=$(PPOPT) -o$(LIBNAME)
  356. endif
  357. # Add defines from PPOPTDEF to PPOPT
  358. override PPOPT:=$(PPOPT) $(PPOPTDEF)
  359. # Was a config file specified ?
  360. ifdef CFGFILE
  361. override PPOPT:=$(PPOPT) @$(CFGFILE)
  362. endif
  363. override COMPILER=$(PP) $(PPOPT)
  364. #####################################################################
  365. # Default extensions
  366. #####################################################################
  367. # Default needed extensions (Go32v2,Linux)
  368. PPLEXT=.ppl
  369. PPUEXT=.ppu
  370. OEXT=.o
  371. ASMEXT=.s
  372. SMARTEXT=.sl
  373. STATICLIBEXT=.a
  374. SHAREDLIBEXT=.so
  375. # Executable extension
  376. ifdef inlinux
  377. EXEEXT=
  378. else
  379. EXEEXT=.exe
  380. endif
  381. # Go32v1
  382. ifeq ($(OS_TARGET),go32v1)
  383. PPUEXT=.pp1
  384. OEXT=.o1
  385. ASMEXT=.s1
  386. SMARTEXT=.sl1
  387. STATICLIBEXT=.a1
  388. SHAREDLIBEXT=.so1
  389. endif
  390. # Win32
  391. ifeq ($(OS_TARGET),win32)
  392. PPUEXT=.ppw
  393. OEXT=.ow
  394. ASMEXT=.sw
  395. SMARTEXT=.slw
  396. STATICLIBEXT=.aw
  397. SHAREDLIBEXT=.dll
  398. endif
  399. # OS/2
  400. ifeq ($(OS_TARGET),os2)
  401. PPUEXT=.ppo
  402. ASMEXT=.so2
  403. OEXT=.o2
  404. SMARTEXT=.so
  405. STATICLIBEXT=.ao
  406. SHAREDLIBEXT=.dll
  407. endif
  408. # determine libary extension.
  409. ifeq ($(LIBTYPE),static)
  410. LIBEXT=$(STATICLIBEXT)
  411. else
  412. LIBEXT=$(SHAREDLIBEXT)
  413. endif
  414. # library prefix
  415. LIBPREFIX=lib
  416. ifeq ($(OS_TARGET),go32v2)
  417. LIBPREFIX=
  418. endif
  419. ifeq ($(OS_TARGET),go32v1)
  420. LIBPREFIX=
  421. endif
  422. # determine with .pas extension is used
  423. ifdef EXEOBJECTS
  424. override TESTPAS:=$(strip $(wildcard $(addsuffix .pas,$(firstword $(EXEOBJECTS)))))
  425. else
  426. override TESTPAS:=$(strip $(wildcard $(addsuffix .pas,$(firstword $(UNITOBJECTS)))))
  427. endif
  428. ifeq ($(TESTPAS),)
  429. PASEXT=.pp
  430. else
  431. PASEXT=.pas
  432. endif
  433. #####################################################################
  434. # Export commandline values, so nesting use the same values
  435. #####################################################################
  436. export OS_SOURCE OS_TARGET OPT OPTDEF CPU PP RELEASE VERBOSE
  437. export SMARTLINK LIBTYPE LIBNAME
  438. export BASEINSTALLDIR
  439. #####################################################################
  440. # General compile rules
  441. #####################################################################
  442. # Create Filenames
  443. EXEFILES=$(addsuffix $(EXEEXT),$(EXEOBJECTS))
  444. UNITFILES=$(addsuffix $(PPUEXT),$(UNITOBJECTS))
  445. UNITOFILES=$(addsuffix $(OEXT),$(UNITOBJECTS))
  446. .PHONY : all clean install \
  447. info cfginfo objectinfo installinfo filesinfo
  448. .SUFFIXES : $(EXEEXT) $(PPUEXT) $(PASEXT)
  449. ifdef DEFAULTUNITS
  450. all: units
  451. else
  452. all: units exes
  453. endif
  454. units: $(UNITFILES)
  455. exes: $(EXEFILES)
  456. # General compile rules
  457. %$(PPUEXT): %$(PASEXT)
  458. $(COMPILER) $<
  459. %$(EXEEXT): %$(PASEXT)
  460. $(COMPILER) $<
  461. #####################################################################
  462. # Install rules
  463. #####################################################################
  464. install : all
  465. ifdef EXEOBJECTS
  466. $(MKDIR) $(BININSTALLDIR)
  467. $(INSTALLEXE) $(EXEFILES) $(BININSTALLDIR)
  468. endif
  469. ifdef UNITOBJECTS
  470. $(MKDIR) $(UNITINSTALLDIR)
  471. ifeq ($(SMARTLINK),YES)
  472. $(INSTALL) $(LIBPREFIX)$(LIBNAME)$(LIBEXT) $(UNITINSTALLDIR)
  473. else
  474. $(INSTALL) $(UNITFILES) $(UNITOFILES) $(UNITINSTALLDIR)
  475. endif
  476. endif
  477. #####################################################################
  478. # Clean rules
  479. #####################################################################
  480. clean:
  481. -$(DEL) *$(OEXT) *$(ASMEXT) *$(PPUEXT) *$(STATICLIBEXT) *$(SHAREDLIBEXT) $(PPAS) link.res log
  482. -$(DELTREE) *$(SMARTEXT)
  483. ifdef EXEOBJECTS
  484. -$(DEL) $(EXEFILES)
  485. endif
  486. #####################################################################
  487. # Depend rules
  488. #####################################################################
  489. depend:
  490. makedep $(UNITOBJECTS)
  491. #####################################################################
  492. # Info rules
  493. #####################################################################
  494. info: cfginfo objectinfo installinfo
  495. cfginfo:
  496. @echo
  497. @echo == Configuration info ==
  498. @echo
  499. @echo Source.... $(OS_SOURCE)
  500. @echo Target.... $(OS_TARGET)
  501. @echo Basedir... $(BASEDIR)
  502. @echo Pwd....... $(PWD)
  503. ifdef SED
  504. @echo Sed....... $(SED)
  505. endif
  506. @echo
  507. objectinfo:
  508. @echo
  509. @echo == Object info ==
  510. @echo
  511. @echo UnitObjects... $(UNITOBJECTS)
  512. @echo ExeObjects.... $(EXEOBJECTS)
  513. @echo
  514. installinfo:
  515. @echo
  516. @echo == Install info ==
  517. @echo
  518. @echo BaseInstallDir....... $(BASEINSTALLDIR)
  519. @echo BinInstallDir........ $(BININSTALLDIR)
  520. @echo UnitInstallDir....... $(UNITINSTALLDIR)
  521. @echo StaticUnitInstallDir. $(STATIC_UNITINSTALLDIR)
  522. @echo SharedUnitInstallDir. $(SHARED_UNITINSTALLDIR)
  523. @echo LibInstallDir........ $(LIBINSTALLDIR)
  524. @echo StaticLibInstallDir.. $(STATIC_LIBINSTALLDIR)
  525. @echo SharedLibInstallDir.. $(SHARED_LIBINSTALLDIR)
  526. @echo MsgInstallDir........ $(MSGINSTALLDIR)
  527. @echo DocInstallDir........ $(DOCINSTALLDIR)
  528. @echo
  529. # try to get the files in the currentdir
  530. PASFILES:=$(wildcard *.pas)
  531. PPFILES:=$(wildcard *.pp)
  532. INCFILES:=$(wildcard *.inc)
  533. MSGFILES:=$(wildcard *.msg)
  534. ASFILES:=$(wildcard *.as)
  535. filesinfo:
  536. @echo
  537. @echo == Files info ==
  538. @echo
  539. ifdef PASFILES
  540. @echo Pas files are $(PASFILES)
  541. endif
  542. ifdef PPFILES
  543. @echo PP files are $(PPFILES)
  544. endif
  545. ifdef INCFILES
  546. @echo Inc files are $(INCFILES)
  547. endif
  548. ifdef MSGFILES
  549. @echo Msg files are $(MSGFILES)
  550. endif
  551. ifdef ASFILES
  552. @echo As files are $(ASFILES)
  553. endif