Makefile.fpc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. #
  2. # Makefile.fpc for Free Pascal Compiler
  3. #
  4. [package]
  5. name=compiler
  6. version=1.1
  7. [target]
  8. dirs=utils
  9. [compiler]
  10. targetdir=$(CPU_UNITDIR)
  11. unitdir=$(COMPILERSOURCEDIR)
  12. includedir=$(PPC_TARGET)
  13. [require]
  14. packages=rtl
  15. tools=diff cmp
  16. [install]
  17. fpcpackage=y
  18. [default]
  19. fpcdir=..
  20. [prerules]
  21. # Don't export version it can change after the first compile
  22. unexport FPC_VERSION FPC_COMPILERINFO
  23. # Which platforms are ready for inclusion in the cycle
  24. CYCLETARGETS=i386 powerpc sparc m68k
  25. # Allow ALPHA, POWERPC, M68K, I386 defines for target cpu
  26. ifdef ALPHA
  27. PPC_TARGET=alpha
  28. endif
  29. ifdef POWERPC
  30. PPC_TARGET=powerpc
  31. endif
  32. ifdef SPARC
  33. PPC_TARGET=sparc
  34. endif
  35. ifdef M68K
  36. PPC_TARGET=m68k
  37. endif
  38. ifdef I386
  39. PPC_TARGET=i386
  40. endif
  41. ifdef X86_64
  42. PPC_TARGET=x86_64
  43. endif
  44. # Default is to generate a compiler for the same
  45. # platform as CPU_TARGET (a native compiler)
  46. ifndef PPC_TARGET
  47. PPC_TARGET=$(CPU_TARGET)
  48. endif
  49. export PPC_TARGET
  50. # Default is to generate a compiler for the same
  51. # target as OS_TARGET (a native compiler)
  52. ifndef PPC_OS
  53. PPC_OS=$(OS_TARGET)
  54. endif
  55. export PPC_OS
  56. # Where to place the unit files.
  57. CPU_UNITDIR=.
  58. # RTL
  59. UTILSDIR=../utils
  60. # Directories containing compiler sources
  61. COMPILERSOURCEDIR=$(PPC_TARGET) systems
  62. # Utils used by compiler development/installation
  63. COMPILERUTILSDIR=utils
  64. # Default language for the compiler
  65. ifndef FPCLANG
  66. FPCLANG=e
  67. endif
  68. # Local defines for the compiler only
  69. ifndef LOCALDEF
  70. LOCALDEF=
  71. endif
  72. # Local options for the compiler only
  73. ifndef LOCALOPT
  74. LOCALOPT=$(OPT)
  75. endif
  76. # Options for the RTL only when cycling
  77. ifndef RTLOPTS
  78. RTLOPTS=$(OPT)
  79. endif
  80. # Message files
  81. MSGFILES=$(wildcard msg/error*.msg)
  82. # ppcSUFFIX
  83. ifeq ($(PPC_TARGET),i386)
  84. CPUSUF=386
  85. endif
  86. ifeq ($(PPC_TARGET),alpha)
  87. CPUSUF=axp
  88. endif
  89. ifeq ($(PPC_TARGET),m68k)
  90. CPUSUF=68k
  91. endif
  92. ifeq ($(PPC_TARGET),powerpc)
  93. CPUSUF=ppc
  94. endif
  95. ifeq ($(PPC_TARGET),sparc)
  96. CPUSUF=sparc
  97. endif
  98. ifeq ($(PPC_TARGET),x86_64)
  99. CPUSUF=x64
  100. endif
  101. # Do not define the default -d$(CPU_TARGET) because that
  102. # will conflict with our -d$(PPC_TARGET)
  103. NOCPUDEF=1
  104. # Define Unix also for Linux
  105. ifeq ($(OS_TARGET),linux)
  106. ifneq ($(findstring 1.0.,$(FPC_VERSION)),)
  107. override LOCALDEF+=-dUNIX
  108. endif
  109. endif
  110. ifeq ($(OS_TARGET),freebsd)
  111. ifneq ($(findstring 1.0.,$(FPC_VERSION)),)
  112. override LOCALDEF+=-dUNIX
  113. endif
  114. endif
  115. # Default message file
  116. MSGFILE=msg/error$(FPCLANG).msg
  117. # set correct defines (-d$(CPU_TARGET) is automaticly added in makefile.fpc)
  118. override LOCALDEF+=-d$(PPC_TARGET) -dGDB -dBROWSERLOG
  119. # i386 specific
  120. ifeq ($(PPC_TARGET),i386)
  121. override LOCALDEF+=-dSUPPORT_MMX -Fux86
  122. endif
  123. # x86_64 specific
  124. ifeq ($(PPC_TARGET),x86_64)
  125. override LOCALDEF+=-dSUPPORT_MMX -Fux86 -dNOOPT
  126. endif
  127. # PowerPC specific
  128. ifeq ($(PPC_TARGET),powerpc)
  129. override LOCALDEF+=-dNOOPT
  130. endif
  131. # m68k specific
  132. ifeq ($(PPC_TARGET),m68k)
  133. override LOCALDEF+=-dNOOPT
  134. endif
  135. # Sparc specific
  136. ifeq ($(PPC_TARGET),sparc)
  137. override LOCALDEF+=-dNOOPT
  138. endif
  139. # m68k specific with low stack
  140. ifeq ($(PPC_TARGET),m68k)
  141. ifeq ($(OS_TARGET),amiga)
  142. override LOCALDEF+=-Ct
  143. endif
  144. endif
  145. ifeq ($(PPC_TARGET),m68k)
  146. ifeq ($(OS_TARGET),amiga)
  147. override LOCALDEF+=-Ct
  148. endif
  149. endif
  150. PASDOC:=$(strip $(wildcard $(addsuffix /pasdoc.exe,$(SEARCHPATH))))
  151. ifeq ($(PASDOC),)
  152. PASDOC:=$(strip $(wildcard $(addsuffix /pasdoc,$(SEARCHPATH))))
  153. endif
  154. ifeq ($(PASDOC),)
  155. PASDOC:=../projects/pasdoc/bin/pasdoc
  156. else
  157. PASDOC:=$(firstword $(PASDOC))
  158. endif
  159. override LOCALOPT+=$(LOCALDEF)
  160. override FPCOPT:=$(LOCALOPT)
  161. [rules]
  162. #####################################################################
  163. # Setup Targets
  164. #####################################################################
  165. ifeq ($(OS_TARGET),win32)
  166. ifdef CMP
  167. override DIFF:=$(CMP) -i218
  168. endif
  169. # force try to smartlink for windows unit
  170. override COMPILER+=-XX
  171. endif
  172. # Used to avoid unnecessary steps in remake3
  173. ifdef DIFF
  174. ifdef OLDFPC
  175. DIFFRESULT:=$(shell $(DIFF) $(OLDFPC) $(FPC))
  176. else
  177. DIFFRESULT=Not equal
  178. endif
  179. else
  180. DIFFRESULT=No diff program
  181. endif
  182. #####################################################################
  183. # Setup os-independent filenames
  184. #####################################################################
  185. ifndef EXENAME
  186. EXENAME=ppc$(CPUSUF)$(EXEEXT)
  187. endif
  188. PPEXENAME=pp$(EXEEXT)
  189. TEMPNAME=ppc$(SRCEXEEXT)
  190. PPCROSSNAME=ppcross$(CPUSUF)$(SRCEXEEXT)
  191. TEMPNAME1=ppc1$(EXEEXT)
  192. TEMPNAME2=ppc2$(EXEEXT)
  193. TEMPNAME3=ppc3$(EXEEXT)
  194. MAKEDEP=ppdep$(EXEEXT)
  195. MSG2INC=./msg2inc$(EXEEXT)
  196. #####################################################################
  197. # CPU targets
  198. #####################################################################
  199. .PHONY: alpha i386 m68k powerpc sparc
  200. alpha:
  201. $(MAKE) PPC_TARGET=alpha CPU_UNITDIR=alpha all
  202. i386:
  203. $(MAKE) PPC_TARGET=i386 CPU_UNITDIR=i386 all
  204. m68k:
  205. $(MAKE) PPC_TARGET=m68k CPU_UNITDIR=m68k all
  206. powerpc:
  207. $(MAKE) PPC_TARGET=powerpc CPU_UNITDIR=powerpc all
  208. sparc:
  209. $(MAKE) PPC_TARGET=sparc CPU_UNITDIR=sparc all
  210. #####################################################################
  211. # Default makefile
  212. #####################################################################
  213. .PHONY: all compiler echotime ppuclean execlean clean distclean
  214. all: $(EXENAME) $(addsuffix _all,$(TARGET_DIRS))
  215. compiler: $(EXENAME)
  216. ifeq ($(MAKELEVEL),0)
  217. ifndef STARTTIME
  218. ifdef DATE
  219. STARTTIME:=$(shell $(DATE) +%T)
  220. else
  221. STARTTIME:=unknown
  222. endif
  223. endif
  224. endif
  225. export STARTTIME
  226. ifdef DATE
  227. ENDTIME=$(shell $(DATE) +%T)
  228. else
  229. ENDTIME:=unknown
  230. endif
  231. echotime:
  232. @echo Start $(STARTTIME) now $(ENDTIME)
  233. ppuclean:
  234. -$(DEL) *$(OEXT) *$(PPUEXT) *$(RSTEXT) *$(ASMEXT) *$(STATICLIBEXT) *$(SHAREDLIBEXT) *$(PPLEXT)
  235. -$(DEL) $(addsuffix /*$(PPUEXT),$(COMPILERSOURCEDIR))
  236. execlean :
  237. -$(DEL) ppc386$(EXEEXT) ppcaxp$(EXEEXT) ppc68k$(EXEEXT) ppcppc$(EXEEXT) ppcsparc$(EXEEXT) $(EXENAME)
  238. $(addsuffix _clean,$(CYCLETARGETS)):
  239. -$(DEL) $(addprefix $(subst _clean,,$@)/,*$(OEXT) *$(PPUEXT) *$(RSTEXT) *$(ASMEXT) *$(STATICLIBEXT) *$(SHAREDLIBEXT) *$(PPLEXT))
  240. -$(DEL) $(addprefix $(subst _clean,,$@)/,ppc386$(EXEEXT) ppcaxp$(EXEEXT) ppc68k$(EXEEXT) ppcppc$(EXEEXT) ppcppc$(EXEEXT) $(EXENAME))
  241. clean : execlean fpc_cleanall $(addsuffix _clean,$(TARGET_DIRS)) $(addsuffix _clean,$(CYCLETARGETS))
  242. distclean: execlean fpc_cleanall $(addsuffix _distclean,$(TARGET_DIRS))
  243. -$(DEL) $(PPCROSSNAME) $(TEMPNAME) $(TEMPNAME1) $(TEMPNAME2) $(TEMPNAME3) $(MSG2INC)
  244. #####################################################################
  245. # Include depencies
  246. #####################################################################
  247. $(MAKEDEP): $(UTILSDIR)/ppdep.pp
  248. $(COMPILER) $(UTILSDIR)/ppdep.pp
  249. $(COPY) $(UTILSDIR)/$(MAKEDEP) $(MAKEDEP)
  250. dependencies : $(MAKEDEP)
  251. $(MAKEDEP) pp.pas $(FPCOPTDEF) $(LOCALDEF) '-F$$(COMPILER) $$(LOCALOPT)' > depend
  252. ifdef USEDEPEND
  253. include depend
  254. endif
  255. #####################################################################
  256. # Make targets
  257. #####################################################################
  258. $(MSG2INC): $(COMPILERUTILSDIR)/msg2inc.pp
  259. $(COMPILER) -FE. $(COMPILERUTILSDIR)/msg2inc.pp
  260. # The msgtxt.inc only depends on the error?.msg file, not on msg2inc,
  261. # because that one will be new almost everytime
  262. msgtxt.inc: $(MSGFILE)
  263. $(MAKE) $(MSG2INC)
  264. $(MSG2INC) $(MSGFILE) msg msg
  265. msg: msgtxt.inc
  266. # Make only the compiler
  267. ifndef COMPLETE
  268. $(EXENAME) : $(wildcard *.pas) $(wildcard *.inc) msg \
  269. $(wildcard systems/*.pas) $(wilcard systems/*.inc) \
  270. $(wildcard $(PPC_TARGET)/*.pas) $(wildcard $(PPC_TARGET)/*.inc)
  271. $(COMPILER) pp.pas
  272. $(EXECPPAS)
  273. $(MOVE) $(COMPILER_TARGETDIR)/$(PPEXENAME) $(EXENAME)
  274. else
  275. $(EXENAME) : $(wildcard *.pas) $(wildcard *.inc) msg \
  276. $(wildcard systems/*.pas) $(wilcard systems/*.inc) \
  277. $(wildcard $(PPC_TARGET)/*.pas) $(wildcard $(PPC_TARGET)/*.inc)
  278. $(COMPILER) pp.pas
  279. $(EXECPPAS)
  280. $(COMPILER) pp.pas
  281. $(EXECPPAS)
  282. $(COMPILER) pp.pas
  283. $(EXECPPAS)
  284. $(MOVE) $(COMPILER_TARGETDIR)/$(PPEXENAME) $(EXENAME)
  285. endif
  286. tokens.dat : $(wildcard *.pas) $(wildcard *.inc)
  287. $(COMPILER) tokendat.pas
  288. ./tokendat
  289. #####################################################################
  290. # Cycle targets
  291. #
  292. # 1. Source CPU = Target CPU and Source OS = Target OS
  293. # Normal cycle
  294. # 2. Source CPU = Target CPU and Source OS <> Target OS
  295. # First source native compiler
  296. # Second target native compiler
  297. #
  298. # 3. Source CPU <> Target CPU
  299. # First source native compiler
  300. # Second cross compiler
  301. # Third target native compiler
  302. #
  303. #####################################################################
  304. ifeq ($(CPU_SOURCE),$(PPC_TARGET))
  305. ifeq ($(OS_SOURCE),$(OS_TARGET))
  306. ##########################
  307. # Normal cycle
  308. #
  309. ifndef DIFFRESULT
  310. next :
  311. @echo $(OLDFPC) and $(FPC) are equal
  312. $(COPY) $(FPC) $(EXENAME)
  313. else
  314. next :
  315. $(MAKE) execlean
  316. $(MAKE) -C $(UNITDIR_RTL) clean
  317. $(MAKE) -C $(UNITDIR_RTL) 'FPC=$(FPC)' 'OPT=$(RTLOPTS)'
  318. $(MAKE) clean
  319. $(MAKE) $(EXENAME)
  320. $(MAKE) echotime
  321. endif
  322. $(TEMPNAME1) : $(EXENAME)
  323. -$(DEL) $(TEMPNAME1)
  324. $(MOVE) $(EXENAME) $(TEMPNAME1)
  325. $(TEMPNAME2) : $(TEMPNAME1)
  326. $(MAKE) 'FPC=$(BASEDIR)/$(TEMPNAME1)' 'OLDFPC=' next
  327. -$(DEL) $(TEMPNAME2)
  328. $(MOVE) $(EXENAME) $(TEMPNAME2)
  329. $(TEMPNAME3) : $(TEMPNAME2)
  330. $(MAKE) 'FPC=$(BASEDIR)/$(TEMPNAME2)' 'OLDFPC=$(BASEDIR)/$(TEMPNAME1)' next
  331. -$(DEL) $(TEMPNAME3)
  332. $(MOVE) $(EXENAME) $(TEMPNAME3)
  333. # This target remakes the units with the currently made version
  334. remake: $(EXENAME)
  335. $(MOVE) $(EXENAME) $(TEMPNAME)
  336. $(MAKE) execlean
  337. $(MAKE) -C $(UNITDIR_RTL) clean
  338. $(MAKE) clean
  339. $(MAKE) 'FPC=$(BASEDIR)/$(TEMPNAME)' all
  340. remake3: $(TEMPNAME3)
  341. $(MAKE) 'FPC=$(BASEDIR)/$(TEMPNAME3)' 'OLDFPC=$(BASEDIR)/$(TEMPNAME2)' next
  342. $(DIFF) $(TEMPNAME3) $(EXENAME)
  343. cycle:
  344. $(MAKE) clean
  345. $(MAKE) -C $(UNITDIR_RTL) clean
  346. $(MAKE) -C $(UNITDIR_RTL) 'OPT=$(RTLOPTS)' all
  347. $(MAKE) remake3
  348. $(MAKE) $(addsuffix _all,$(TARGET_DIRS)) 'FPC=$(BASEDIR)/$(EXENAME)'
  349. $(MAKE) echotime
  350. else
  351. ##########################
  352. # Cross Target cycle
  353. #
  354. cycle:
  355. # ppc (source native)
  356. $(MAKE) OS_TARGET=$(OS_SOURCE) rtlclean rtl
  357. $(MAKE) OS_TARGET=$(OS_SOURCE) EXENAME=$(TEMPNAME) clean compiler
  358. # ppcross<ARCH> (source native)
  359. $(MAKE) 'FPC=$(BASEDIR)/$(TEMPNAME)' OS_TARGET=$(OS_SOURCE) rtlclean rtl
  360. $(MAKE) 'FPC=$(BASEDIR)/$(TEMPNAME)' OS_TARGET=$(OS_SOURCE) EXENAME=$(PPCROSSNAME) clean compiler
  361. # ppc<ARCH> (target native)
  362. $(MAKE) 'FPC=$(BASEDIR)/$(PPCROSSNAME)' rtlclean rtl
  363. $(MAKE) 'FPC=$(BASEDIR)/$(PPCROSSNAME)' clean compiler
  364. endif
  365. else
  366. ##########################
  367. # Cross CPU cycle
  368. #
  369. # ppc1 = native
  370. # ppc2 = cross running on this platform
  371. # ppc3/ppcXXX = native
  372. #
  373. cycle:
  374. # ppc (source native)
  375. $(MAKE) OS_TARGET=$(OS_SOURCE) CPU_TARGET=$(CPU_SOURCE) rtlclean rtl
  376. $(MAKE) OS_TARGET=$(OS_SOURCE) CPU_TARGET=$(CPU_SOURCE) EXENAME=$(TEMPNAME) clean compiler
  377. # ppcross<ARCH> (source native)
  378. $(MAKE) 'FPC=$(BASEDIR)/$(TEMPNAME)' OS_TARGET=$(OS_SOURCE) CPU_TARGET=$(CPU_SOURCE) rtlclean rtl
  379. $(MAKE) 'FPC=$(BASEDIR)/$(TEMPNAME)' OS_TARGET=$(OS_SOURCE) CPU_TARGET=$(CPU_SOURCE) PPC_TARGET=$(CPU_TARGET) EXENAME=$(PPCROSSNAME) clean compiler
  380. # ppc<ARCH> (target native)
  381. $(MAKE) 'FPC=$(BASEDIR)/$(PPCROSSNAME)' rtlclean rtl
  382. $(MAKE) 'FPC=$(BASEDIR)/$(PPCROSSNAME)' clean compiler
  383. endif
  384. cycledep:
  385. $(MAKE) cycle USEDEPEND=1
  386. cvstest:
  387. $(MAKE) cycle 'LOCALOPT=-n -Se' 'RTLOPTS=-n -Se'
  388. ##########################
  389. # Full cycle
  390. #
  391. # 1. build a compiler using cycle
  392. # 2. remove all .ppufiles
  393. # 3. build all supported cross compilers except the
  394. # current PPC_TARGET which was already build
  395. #
  396. full: fullcycle
  397. fullcycle:
  398. $(MAKE) cycle
  399. $(MAKE) ppuclean
  400. $(MAKE) $(filter-out $(PPC_TARGET),$(CYCLETARGETS)) 'FPC=$(BASEDIR)/$(EXENAME)'
  401. #####################################################################
  402. # Docs
  403. #####################################################################
  404. htmldocs:
  405. $(PASDOC) -p -h -o html$(PATHSEP)$(PPC_TARGET) -d fpc -d gdb -d $(PPC_TARGET) -u $(PPC_TARGET) $(PPC_TARGET)$(PATHSEP)*.pas systems$(PATHSEP)*.pas *.pas
  406. #####################################################################
  407. # Installation
  408. #####################################################################
  409. .PHONY: quickinstall install installsym
  410. MSGINSTALLDIR=$(INSTALL_BASEDIR)/msg
  411. override PPEXEFILE:=$(wildcard $(EXENAME))
  412. # This will only install the ppc386.exe, not the message files etc.
  413. quickinstall: $(addsuffix _install,$(TARGET_DIRS))
  414. # Install ppc386.exe
  415. ifneq ($(PPEXEFILE),)
  416. ifdef UPXPROG
  417. -$(UPXPROG) $(EXENAME)
  418. endif
  419. ifdef UNIXINSTALLDIR
  420. $(MKDIR) $(INSTALL_BASEDIR)
  421. $(INSTALLEXE) $(EXENAME) $(INSTALL_BASEDIR)
  422. else
  423. $(MKDIR) $(INSTALL_BINDIR)
  424. $(INSTALLEXE) $(EXENAME) $(INSTALL_BINDIR)
  425. endif
  426. endif
  427. install: quickinstall
  428. ifdef UNIXINSTALLDIR
  429. $(MKDIR) $(INSTALL_BASEDIR)
  430. $(INSTALLEXE) $(COMPILERUTILSDIR)/samplecfg $(INSTALL_BASEDIR)/samplecfg
  431. endif
  432. $(MKDIR) $(MSGINSTALLDIR)
  433. $(INSTALL) $(MSGFILES) $(MSGINSTALLDIR)
  434. # this also installs the link /usr/bin/ppc386. The .deb does that later
  435. installsymlink: install
  436. ifdef UNIXINSTALLDIR
  437. $(MKDIR) $(INSTALL_BINDIR)
  438. ln -sf $(INSTALL_BASEDIR)/ppc386 $(INSTALL_BINDIR)/ppc386
  439. endif
  440. #####################################################################
  441. # RTL
  442. #####################################################################
  443. .PHONY: rtl rtlclean rtlinstall
  444. rtl:
  445. $(MAKE) -C $(UNITDIR_RTL) 'OPT=$(RTLOPTS)' all
  446. rtlclean:
  447. $(MAKE) -C $(UNITDIR_RTL) clean
  448. rtlinstall:
  449. $(MAKE) -C $(UNITDIR_RTL) install
  450. #####################################################################
  451. # local user configurable file
  452. # in makefile.loc you can add any desired target
  453. #####################################################################
  454. localmake:=$(strip $(wildcard makefile.loc))
  455. ifdef localmake
  456. include ./$(localmake)
  457. endif