Makefile.lfs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. # Custom systemd Makefile that builds/installs udev only for LFS
  2. # Bruce Dubbs 2012-07-11
  3. # vim: tabstop=3
  4. SHELL=/bin/bash
  5. VERSION=193
  6. ifeq ($(V),)
  7. VB = @
  8. else
  9. VB =
  10. endif
  11. WARN = -Wall -W -Wextra -Wno-inline -Wvla -Wundef -Wformat=2 \
  12. -Wlogical-op -Wsign-compare -Wformat-security -Wmissing-include-dirs \
  13. -Wformat-nonliteral -Wold-style-definition -Wpointer-arith -Winit-self \
  14. -Wdeclaration-after-statement -Wfloat-equal -Wmissing-prototypes \
  15. -Wstrict-prototypes -Wredundant-decls -Wmissing-declarations \
  16. -Wmissing-noreturn -Wshadow -Wendif-labels -Wcast-align \
  17. -Wstrict-aliasing=2 -Wwrite-strings -Wno-overlength-strings \
  18. -Wno-unused-parameter -Wno-missing-field-initializers -Wno-unused-result \
  19. -Werror=overflow -Wp,-D_FORTIFY_SOURCE=2 -Wno-long-long
  20. OPTIONS = -O2 -pipe -ffast-math -fno-common -fdiagnostics-show-option \
  21. -fno-strict-aliasing -ffunction-sections -fdata-sections -fPIC
  22. OPTIONS2 := $(OPTIONS) -fvisibility=hidden
  23. LDFLAGS = -pthread -lrt -Wl,--as-needed -Wl,--gc-sections
  24. LDFLAGS2 := $(LDFLAGS) -lblkid -lkmod
  25. DEF = -include cfg.h \
  26. -DSYSCONFDIR=\"/etc\" \
  27. -DFIRMWARE_PATH="\"/lib/firmware/updates/\", \"/lib/firmware/\"" \
  28. -DUSB_DATABASE=\"/usr/share/misc/usb.ids\" \
  29. -DPCI_DATABASE=\"/usr/share/misc/pci.ids\" \
  30. -DROOTPREFIX= \
  31. -DUDEVLIBEXECDIR=\"/lib/udev\" \
  32. -D_LARGEFILE_SOURCE \
  33. -D_FILE_OFFSET_BITS=64
  34. INCLUDE = -I src/libudev -I src/shared -I src -I src/login -I src/systemd
  35. LIBUDEV_SRCS = libudev-device-private.c \
  36. libudev-device.c \
  37. libudev-enumerate.c \
  38. libudev-list.c \
  39. libudev-monitor.c \
  40. libudev-queue-private.c \
  41. libudev-queue.c \
  42. libudev-util.c \
  43. libudev.c
  44. LIBUDEV_OBJS := $(addprefix build/, $(LIBUDEV_SRCS:.c=.o))
  45. LIBUDEV = libudev
  46. LIBUDEV_MAJOR = .1
  47. LIBUDEV_MINOR = .0
  48. LIBUDEV_PATCH = .2
  49. LIBUDEV_SONAME := $(LIBUDEV).so
  50. LIBUDEV_LINK_NAME := $(LIBUDEV_SONAME)$(LIBUDEV_MAJOR)
  51. LIBUDEV_REAL_NAME := $(LIBUDEV_LINK_NAME)$(LIBUDEV_MINOR)$(LIBUDEV_PATCH)
  52. COMMON_LIB = udev-local.a
  53. COMMON_SRCS = log.c \
  54. label.c \
  55. mkdir.c \
  56. cgroup-util.c \
  57. strv.c \
  58. path-util.c \
  59. conf-files.c \
  60. hashmap.c \
  61. set.c \
  62. exit-status.c \
  63. util.c \
  64. dev-setup.c \
  65. sd-login.c \
  66. sd-daemon.c
  67. COMMON_OBJS := $(addprefix build/, $(COMMON_SRCS:.c=.o))
  68. UDEVD_SRCS = udev-ctrl.c \
  69. udev-rules.c \
  70. udev-watch.c \
  71. udev-event.c \
  72. udev-node.c \
  73. udev-builtin.c \
  74. udev-builtin-blkid.c \
  75. udev-builtin-firmware.c \
  76. udev-builtin-path_id.c \
  77. udev-builtin-hwdb.c \
  78. udev-builtin-kmod.c \
  79. udev-builtin-uaccess.c \
  80. udev-builtin-usb_id.c \
  81. udev-builtin-input_id.c \
  82. udev-builtin-btrfs.c
  83. UDEVD_OBJS := $(addprefix build/, $(UDEVD_SRCS:.c=.o))
  84. UDEV_ADMIN_SRCS = udevadm.c \
  85. udevadm-test.c \
  86. udevadm-monitor.c \
  87. udevadm-settle.c \
  88. udevadm-info.c \
  89. udevadm-test-builtin.c \
  90. udevadm-trigger.c \
  91. udevadm-control.c \
  92. udev-rules.c \
  93. udev-ctrl.c \
  94. udev-event.c \
  95. udev-node.c \
  96. udev-watch.c \
  97. udev-builtin.c \
  98. udev-builtin-blkid.c \
  99. udev-builtin-firmware.c \
  100. udev-builtin-path_id.c \
  101. udev-builtin-hwdb.c \
  102. udev-builtin-kmod.c \
  103. udev-builtin-uaccess.c \
  104. udev-builtin-usb_id.c \
  105. udev-builtin-input_id.c \
  106. udev-builtin-btrfs.c
  107. UDEV_ADMIN_OBJS := $(addprefix build/, $(UDEV_ADMIN_SRCS:.c=.o))
  108. LFS_RULES = 55-lfs.rules
  109. VPATH = src/login src/udev src/udev/accelerometer \
  110. src/udev/scsi_id src/udev/cdrom_id src/udev/v4l_id \
  111. src/udev/mtd_probe src/udev/collect src/udev/ata_id \
  112. src/libudev src/libsystemd-daemon
  113. SED_PROCESS = \
  114. sed -e 's|@VERSION@|$(VERSION)|g' \
  115. -e 's|@prefix@|/usr|g' \
  116. -e 's|@exec_prefix@|/usr|g' \
  117. -e 's|@udevlibexecdir@|/lib/udev|g' \
  118. -e 's|@libdir@|/usr/lib|g' \
  119. -e 's|@includedir@|/usr/include|g' \
  120. < $< > $@
  121. udev: common \
  122. build/$(COMMON_LIB) \
  123. build/$(LIBUDEV_REAL_NAME) \
  124. build/udevd \
  125. build/udevadm \
  126. build/accelerometer \
  127. build/ata_id \
  128. build/cdrom_id \
  129. build/scsi_id \
  130. build/v4l_id \
  131. build/mtd_probe \
  132. build/collect \
  133. build/udev.pc \
  134. build/libudev.pc
  135. common: udev-lfs-$(VERSION)/cfg.h
  136. @mkdir -p build
  137. sed -e 's/LFS-VERSION/$(VERSION)/' udev-lfs-$(VERSION)/cfg.h > ./cfg.h
  138. build/%o: %c common
  139. @echo CC $<
  140. $(VB)gcc -c $(WARN) $(OPTIONS2) $(INCLUDE) $(DEF) -o $@ $<
  141. # Sources from src/libudev use -fvisibility=hidden
  142. build/%o: src/libudev/%c common
  143. @echo CC $<
  144. $(VB)gcc -c $(WARN) $(OPTIONS) $(INCLUDE) $(DEF) -o $@ $<
  145. # Sources from src/shared use -fvisibility=hidden
  146. build/%o: src/shared/%c common
  147. @echo CC $<
  148. $(VB)gcc -c $(WARN) $(OPTIONS) $(INCLUDE) $(DEF) -o $@ $<
  149. # Build the dynamic library
  150. build/$(LIBUDEV_REAL_NAME): $(LIBUDEV_OBJS) build/$(COMMON_LIB)
  151. @echo LINK $@
  152. $(VB)gcc -shared -fPIC -DPIC \
  153. $(LIBUDEV_OBJS) \
  154. build/$(COMMON_LIB) \
  155. -Wl,--no-whole-archive -ldl -lrt -O2 \
  156. -Wl,--as-needed \
  157. -Wl,--gc-sections \
  158. -Wl,-soname,$(LIBUDEV_LINK_NAME) \
  159. -o build/$(LIBUDEV_REAL_NAME)
  160. ln -sfn $(LIBUDEV_REAL_NAME) build/$(LIBUDEV_LINK_NAME)
  161. ln -sfn $(LIBUDEV_REAL_NAME) build/$(LIBUDEV_SONAME)
  162. #-Wl,--whole-archive \
  163. #-Wl,--version-script=./src/libudev/libudev.sym \
  164. # Build the static library for internal use
  165. build/$(COMMON_LIB): $(COMMON_OBJS) $(LIBUDEV_OBJS) $(UDEVD_OBJS)
  166. @echo AR $@
  167. $(VB)ar rcs build/$(COMMON_LIB) $(COMMON_OBJS) $(LIBUDEV_OBJS)
  168. build/udevd: build/$(COMMON_LIB) build/udevd.o
  169. @echo LINK $@
  170. $(VB)gcc build/udevd.o $(UDEVD_OBJS) -o $@ $(LDFLAGS2) \
  171. build/udev-local.a build/$(COMMON_LIB)
  172. $(VB)strip --strip-unneeded $@
  173. build/udevadm: $(UDEV_ADMIN_OBJS)
  174. @echo LINK $@
  175. $(VB)gcc $(UDEV_ADMIN_OBJS) -o $@ $(LDFLAGS2) build/$(COMMON_LIB)
  176. $(VB)strip --strip-unneeded $@
  177. build/accelerometer: build/accelerometer.o build/$(COMMON_LIB)
  178. @echo LINK $@
  179. $(VB)gcc build/accelerometer.o -o $@ \
  180. build/udev-local.a build/$(COMMON_LIB) $(LDFLAGS) -lm
  181. $(VB)strip --strip-unneeded $@
  182. build/scsi_id: build/scsi_id.o build/scsi_serial.o build/$(COMMON_LIB)
  183. @echo LINK $@
  184. $(VB)gcc build/scsi_id.o build/scsi_serial.o -o $@ \
  185. build/udev-local.a build/$(COMMON_LIB) $(LDFLAGS)
  186. $(VB)strip --strip-unneeded $@
  187. build/ata_id: build/ata_id.o build/$(COMMON_LIB)
  188. @echo LINK $@
  189. $(VB)gcc build/ata_id.o -o $@ build/udev-local.a build/$(COMMON_LIB) $(LDFLAGS)
  190. $(VB)strip --strip-unneeded $@
  191. build/cdrom_id: build/cdrom_id.o build/$(COMMON_LIB)
  192. @echo LINK $@
  193. $(VB)gcc build/cdrom_id.o -o $@ build/udev-local.a build/$(COMMON_LIB) $(LDFLAGS)
  194. $(VB)strip --strip-unneeded $@
  195. build/v4l_id: build/v4l_id.o build/$(COMMON_LIB)
  196. @echo LINK $@
  197. $(VB)gcc build/v4l_id.o -o $@ build/udev-local.a build/$(COMMON_LIB) $(LDFLAGS)
  198. $(VB)strip --strip-unneeded $@
  199. build/mtd_probe: build/mtd_probe.o build/probe_smartmedia.o build/$(COMMON_LIB)
  200. @echo LINK $@
  201. $(VB)gcc build/mtd_probe.o build/probe_smartmedia.o -o $@ \
  202. build/udev-local.a build/$(COMMON_LIB) $(LDFLAGS)
  203. $(VB)strip --strip-unneeded $@
  204. build/collect: build/collect.o build/$(COMMON_LIB)
  205. @echo LINK $@
  206. $(VB)gcc build/collect.o -o $@ build/udev-local.a build/$(COMMON_LIB) $(LDFLAGS)
  207. $(VB)strip --strip-unneeded $@
  208. build/%pc: %pc.in common
  209. @echo GEN $@
  210. @$(SED_PROCESS)
  211. install: udev
  212. @mkdir -pv $(DESTDIR)/lib/udev/devices/pts $(DESTDIR)/lib/udev/rules.d \
  213. $(DESTDIR){,/usr}/lib/firmware $(DESTDIR)/sbin \
  214. $(DESTDIR)/usr/lib/pkgconfig $(DESTDIR)/etc/udev/rules.d \
  215. $(DESTDIR)/usr/share/doc/udev/lfs $(DESTDIR)/usr/include \
  216. $(DESTDIR)/usr/share/man/man{7,8}
  217. # Copy executables
  218. @cp -v build/udevadm $(DESTDIR)/sbin
  219. @cp -v build/{udevd,accelerometer,ata_id,cdrom_id,collect,mtd_probe,scsi_id,v4l_id} \
  220. $(DESTDIR)/lib/udev
  221. @cp -v udev-lfs-$(VERSION)/write* $(DESTDIR)/lib/udev
  222. @cp -v udev-lfs-$(VERSION)/*functions $(DESTDIR)/lib/udev
  223. # Copy and set up library and associated files
  224. @cp -v build/{lib,}udev.pc $(DESTDIR)/usr/lib/pkgconfig
  225. @cp -v build/$(LIBUDEV_REAL_NAME) $(DESTDIR)/lib
  226. ln -svfn ../../lib/$(LIBUDEV_REAL_NAME) $(DESTDIR)/usr/lib/$(LIBUDEV_SONAME)
  227. ln -svfn $(LIBUDEV_REAL_NAME) $(DESTDIR)/lib/$(LIBUDEV_LINK_NAME)
  228. # Copy the libudev header
  229. @cp -v src/libudev/libudev.h $(DESTDIR)/usr/include
  230. # Create null device and copy rules
  231. @cp -v rules/* $(DESTDIR)/lib/udev/rules.d
  232. @rm -v $(DESTDIR)/lib/udev/rules.d/99*
  233. @cp -v udev-lfs-$(VERSION)/*.rules $(DESTDIR)/etc/udev/rules.d
  234. # Copy documentation
  235. @cp -v man/udev.7 $(DESTDIR)/usr/share/man/man7
  236. @cp -v man/udevadm.8 $(DESTDIR)/usr/share/man/man8
  237. @cp -v udev-lfs-$(VERSION)/udevd.8 $(DESTDIR)/usr/share/man/man8
  238. @cp -v udev-lfs-$(VERSION)/README $(DESTDIR)/usr/share/doc/udev/lfs
  239. @cp -v udev-lfs-$(VERSION)/*.txt $(DESTDIR)/usr/share/doc/udev/lfs
  240. # Copy misc
  241. @cp -v udev-lfs-$(VERSION)/init-net-rules.sh $(DESTDIR)/lib/udev
  242. include udev-lfs-$(VERSION)/makefile-incl.gudev
  243. include udev-lfs-$(VERSION)/makefile-incl.gir
  244. include udev-lfs-$(VERSION)/makefile-incl.keymap
  245. all : udev keymap gudev gir-data
  246. install-all: install install-keymap install-gudev install-gir-data
  247. clean:
  248. rm -rf build
  249. rm -f cfg.h
  250. rm -f src/gudev/gudevmarshal.h
  251. rm -f src/gudev/gudevmarshal.c
  252. rm -f src/gudev/gudevenumtypes.h
  253. rm -f src/gudev/gudevenumtypes.c
  254. rm -f src/udev/keymap/keys.txt
  255. rm -f src/udev/keymap/keys-from-name.gperf
  256. rm -f src/udev/keymap/keys-from-name.h
  257. rm -f src/udev/keymap/keys-to-name.h
  258. .PHONY: clean build