Makefile.lfs 12 KB

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