Makefile 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. ## Temelia, C generic data structures library
  2. # to build for debugging level 3, invoke make CFLAGS=-g3
  3. ## To build a DLL you have to type make
  4. # compiler, archiver, linker
  5. CC = $(CROSS_COMPILE)gcc
  6. AR = $(CROSS_COMPILE)ar
  7. LD = $(CROSS_COMPILE)ld
  8. # configure dynamic linker
  9. LDCONF = /sbin/ldconfig
  10. # compiler flags. Optimization level etc.
  11. CFLAGS_BASE=-O3 -Wall -g
  12. CFLAGS += $(CFLAGS_BASE) -fpic
  13. CROSS_FLAGS="-DBUILD_DLL -DDLL"
  14. # project name
  15. PRJNAME = temelia
  16. # library name
  17. LIBNAME = lib$(PRJNAME).so.1
  18. # project's (svn) version
  19. SVN_VER = $(shell svn info | cut -f2 -d" " | head -5 | tail -1)
  20. # library real name
  21. LIBREALNAME := $(LIBNAME).$(SVN_VER)
  22. # library symbolic link name
  23. LIBSYMNAME = lib$(PRJNAME).so
  24. # repo directories
  25. SRCDIR = src
  26. HDRDIR = $(SRCDIR)/include
  27. DEBDIR = deb
  28. RPMDIR = rpm
  29. # processor architectures
  30. ARCH_32 = i386
  31. ARCH_64 = amd64
  32. # local install directories:
  33. # local dir for headers
  34. LOCINCDIR = usr/include/$(PRJNAME)
  35. # local dir for library
  36. LOCLIBDIR = usr/lib
  37. # package names
  38. PKGNAME_32 = $(PRJNAME)-1.0.$(SVN_VER)-1.$(ARCH_32)
  39. PKGNAME_64 = $(PRJNAME)-1.0.$(SVN_VER)-1.$(ARCH_64)
  40. # deb filesystem directory
  41. DEBFS = filesystem
  42. # deb files:
  43. CTRLBKP_FILE = control.sav
  44. DEBIAN_DIR = $(DEBFS)/DEBIAN
  45. CTRL_FILE = $(DEBIAN_DIR)/control
  46. POSTINST_FILE = $(DEBIAN_DIR)/postinst
  47. PRERM_FILE = $(DEBIAN_DIR)/prerm
  48. # variables:
  49. # library install size
  50. SIZE = `du $(DEBFS)/$(LOCINCDIR) | cut -f1`
  51. HDRS = $(HDRDIR)/*.h
  52. # list of object files. these should be C sources with their .c suffix changed to .o
  53. # HACK: build all the C files in the directory
  54. # should specify them by hand.
  55. OBJS = $(shell ls $(SRCDIR)/*.c|tr '\n' ' '|sed -n -e s/\\.c/.o/gp)
  56. # what to build: a shared library
  57. all: $(LIBREALNAME)
  58. # build the library, must have built the objects first
  59. $(LIBREALNAME): $(OBJS)
  60. $(CC) -shared -Wl,-soname,$(LIBNAME) -o $(LIBREALNAME) $(OBJS) -lc
  61. # given an object ($@) that has a corresponding C source ($<), build it
  62. # add CROSS_FLAGS for a gcc cross-compiler
  63. .c.o:
  64. ifeq ($(CC), gcc)
  65. $(CC) $(CFLAGS) -c "$<" -o "$@"
  66. else
  67. $(CC) $(CROSS_FLAGS) $(CFLAGS_BASE) -c "$<" -o "$@"
  68. endif
  69. # copy the header files and archive (needs the archive)
  70. install: $(LIBREALNAME)
  71. -mkdir -p /$(LOCINCDIR)
  72. cp $(HDRS) /$(LOCINCDIR)
  73. -mkdir -p /$(LOCLIBDIR)
  74. cp $(LIBREALNAME) $(DESTDIR)/$(LOCLIBDIR)
  75. ln -s /$(LOCLIBDIR)/$(LIBREALNAME) /$(LOCLIBDIR)/$(LIBNAME)
  76. ln -s /$(LOCLIBDIR)/$(LIBREALNAME) /$(LOCLIBDIR)/$(LIBSYMNAME)
  77. $(LDCONF)
  78. # build deb package (needs the archive)
  79. deb32: $(LIBREALNAME) $(DEBDIR)/$(ARCH_32)/$(PKGNAME_32).deb
  80. deb64: $(LIBREALNAME) $(DEBDIR)/$(ARCH_64)/$(PKGNAME_64).deb
  81. $(DEBDIR)/$(ARCH_32)/$(PKGNAME_32).deb: $(DEBDIR)/$(ARCH_32)
  82. -mkdir -p $</$(DEBFS)/$(LOCINCDIR)
  83. cp $(HDRS) $</$(DEBFS)/$(LOCINCDIR)
  84. -mkdir -p $</$(DEBFS)/$(LOCLIBDIR)
  85. cp $(LIBREALNAME) $</$(DEBFS)/$(LOCLIBDIR)
  86. -mkdir -p $</$(DEBIAN_DIR)
  87. echo "#!/bin/bash" >$</$(POSTINST_FILE)
  88. echo "ln -s /$(LOCLIBDIR)/$(LIBREALNAME) /$(LOCLIBDIR)/$(LIBNAME)" >>$</$(POSTINST_FILE)
  89. echo "ln -s /$(LOCLIBDIR)/$(LIBREALNAME) /$(LOCLIBDIR)/$(LIBSYMNAME)" >>$</$(POSTINST_FILE)
  90. echo "$(LDCONF)" >>$</$(POSTINST_FILE)
  91. echo "#!/bin/bash" >$</$(PRERM_FILE)
  92. echo "rm /$(LOCLIBDIR)/$(LIBSYMNAME)*" >>$</$(PRERM_FILE)
  93. echo "rm -r /$(LOCINCDIR)" >>$</$(PRERM_FILE)
  94. chmod +x $</$(POSTINST_FILE) $</$(PRERM_FILE)
  95. cp $</$(CTRLBKP_FILE) $</$(CTRL_FILE)
  96. echo "Installed-Size: $(SIZE)" >>$</$(CTRL_FILE)
  97. echo "Version: 1.0.$(SVN_VER)" >>$</$(CTRL_FILE)
  98. dpkg -b $</$(DEBFS) $</$(PKGNAME_32).deb
  99. $(DEBDIR)/$(ARCH_64)/$(PKGNAME_64).deb: $(DEBDIR)/$(ARCH_64)
  100. -mkdir -p $</$(DEBFS)/$(LOCINCDIR)
  101. cp $(HDRS) $</$(DEBFS)/$(LOCINCDIR)
  102. -mkdir -p $</$(DEBFS)/$(LOCLIBDIR)
  103. cp $(LIBREALNAME) $</$(DEBFS)/$(LOCLIBDIR)
  104. -mkdir -p $</$(DEBIAN_DIR)
  105. echo "#!/bin/bash" >$</$(POSTINST_FILE)
  106. echo "ln -s /$(LOCLIBDIR)/$(LIBREALNAME) /$(LOCLIBDIR)/$(LIBNAME)" >>$</$(POSTINST_FILE)
  107. echo "ln -s /$(LOCLIBDIR)/$(LIBREALNAME) /$(LOCLIBDIR)/$(LIBSYMNAME)" >>$</$(POSTINST_FILE)
  108. echo "$(LDCONF)" >>$</$(POSTINST_FILE)
  109. echo "#!/bin/bash" >$</$(PRERM_FILE)
  110. echo "rm /$(LOCLIBDIR)/$(LIBSYMNAME)*" >>$</$(PRERM_FILE)
  111. echo "rm -r /$(LOCINCDIR)" >>$</$(PRERM_FILE)
  112. chmod +x $</$(POSTINST_FILE) $</$(PRERM_FILE)
  113. cp $</$(CTRLBKP_FILE) $</$(CTRL_FILE)
  114. echo "Installed-Size: $(SIZE)" >>$</$(CTRL_FILE)
  115. echo "Version: 1.0.$(SVN_VER)" >>$</$(CTRL_FILE)
  116. dpkg -b $</$(DEBFS) $</$(PKGNAME_64).deb
  117. rpm32: deb32 $(RPMDIR)/$(ARCH_32)/$(PKGNAME_32).rpm
  118. rpm64: deb64 $(RPMDIR)/$(ARCH_64)/$(PKGNAME_64).rpm
  119. $(RPMDIR)/$(ARCH_32)/$(PKGNAME_32).rpm: $(RPMDIR)/$(ARCH_32)
  120. -mkdir -p $<
  121. cd $<; alien -rck ../../$(DEBDIR)/$(ARCH_32)/$(PKGNAME_32).deb
  122. $(RPMDIR)/$(ARCH_64)/$(PKGNAME_64).rpm: $(RPMDIR)/$(ARCH_64)
  123. dll: $(OBJS)
  124. $(CC) -shared -o $(PRJNAME).dll -Wl,--out-implib,lib$(PRJNAME)dll.a $(OBJS)
  125. dll_clean:
  126. -rm -rf $(PRJNAME).dll lib$(PRJNAME)dll.a
  127. -rm -f $(OBJS)
  128. debclean:
  129. rm -rf $(DEBDIR)/$(ARCH_32)/$(DEBFS) $(DEBDIR)/$(ARCH_64)/$(DEBFS)
  130. rm -f $(DEBDIR)/$(ARCH_32)/*.deb $(DEBDIR)/$(ARCH_64)/*.deb
  131. rpmclean:
  132. rm -rf $(RPMDIR)/$(ARCH_32)/*.rpm $(RPMDIR)/$(ARCH_64)/*.rpm
  133. clean: debclean rpmclean
  134. rm -f $(OBJS) $(LIBSYMNAME)*
  135. uninstall:
  136. -rm -r /$(LOCINCDIR)
  137. -rm /$(LOCLIBDIR)/$(LIBSYMNAME)*
  138. .PHONY: clean debclean uninstall