Makefile.fpc 13 KB

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