Makefile.fpc 14 KB

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