Projecte

General

Perfil

Baixar (7.36 KB) Estadístiques
| Branca: | Etiqueta: | Revisió:
e518a2c2 Pau
# [qMp] firmware generator (http://qmp.cat)
#
5d7c38be Simó Albert i Beltran
# Copyright (C) 2011-2012 qmp.cat
2aaa878f Simó Albert i Beltran
#
e518a2c2 Pau
# Thiss program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
dc69d79d Simó Albert i Beltran
# Contributors: Simó Albert i Beltran
#
e518a2c2 Pau
ba9fab2c Agustí Moll Garcia
#OWRT_SVN = svn://svn.openwrt.org/openwrt/trunk
#OWRT_SVN_REV = 29592
OWRT_SVN = svn://svn.openwrt.org/openwrt/branches/backfire
21efcd34 p4u
OWRT_PKG_SVN = svn://svn.openwrt.org/openwrt/branches/packages_10.03.1
8be67335 p4u
QMP_GIT_RW = ssh://gitosis@qmp.cat:221/qmp.git
QMP_GIT_RO = git://qmp.cat/qmp.git
6f755fd4 p4u
QMP_GIT_BRANCH ?= master
ca89f12f Agustí Moll Garcia
B6M_GIT = git://qmp.cat/b6m.git
B6M_GIT_BRANCH = openwrt
e518a2c2 Pau
BUILD_DIR = build
CONFIG_DIR = configs
MY_CONFIGS = $(BUILD_DIR)/configs
7eff0866 p4u
IMAGES = images
e518a2c2 Pau
SHELL = bash
dbd4db87 p4u
QMP_FEED = package/feeds/qmp_packages
1209afe3 p4u
SCRIPTS_DIR= scripts
e518a2c2 Pau
J ?= 1
41464728 p4u
V ?= 0
e518a2c2 Pau
T =
884b8141 Agustí Moll Garcia
MAKE_SRC = -j$(J) V=$(V)
7eff0866 p4u
include targets.mk
e518a2c2 Pau
1f0387c1 p4u
TIMESTAMP = $(shell date +%Y%m%d_%H%M)
6b5e8a5c p4u
cce89d3e p4u
#Checking if developer mode is enabled and if target is defined before
8be67335 p4u
$(eval $(if $(DEV),QMP_GIT=$(QMP_GIT_RW),QMP_GIT=$(QMP_GIT_RO)))
ff488f02 p4u
$(eval $(if $(TARGET),,TARGET=$(T)))

cce89d3e p4u
#Getting output image names
IMAGE_PATH = $(shell echo $(IMAGE) | cut -d' ' -f1 )
SIMAGE_PATH = $(shell echo $(SYSUPGRADE) | cut -d' ' -f1 )
IM_NAME = $(shell echo $(IMAGE) | grep ' ' | cut -d' ' -f2 | sed s/TIMESTAMP/$(TIMESTAMP)/g )
$(eval $(if $(IM_NAME),,IM_NAME=$(NAME)-factory-$(TIMESTAMP).bin))
SIM_NAME = $(shell echo $(SYSUPGRADE) | grep ' ' | cut -d' ' -f2 | sed s/TIMESTAMP/$(TIMESTAMP)/g )
$(eval $(if $(SIM_NAME),,SIM_NAME=$(NAME)-sysupgrade-$(TIMESTAMP).bin))
884b8141 Agustí Moll Garcia
3ba6af84 p4u
CONFIG = $(BUILD_DIR)/$(TARGET)/.config
2aaa878f Simó Albert i Beltran
KCONFIG = $(BUILD_DIR)/$(TARGET)/target/linux/$(ARCH)/config-*
3ba6af84 p4u
dbd4db87 p4u
.PHONY: checkout update clean config menuconfig kernel_menuconfig list_targets build clean_qmp
e518a2c2 Pau
884b8141 Agustí Moll Garcia
e518a2c2 Pau
define build_src
ff488f02 p4u
make -C $(BUILD_DIR)/$(TARGET) $(MAKE_SRC) BRANCH_GIT=$(shell git --git-dir=$(BUILD_DIR)/qmp/.git branch|grep ^*|cut -d " " -f 2) REV_GIT=$(shell git --git-dir=$(BUILD_DIR)/qmp/.git --no-pager log -n 1 --oneline|cut -d " " -f 1)
e518a2c2 Pau
endef

define checkout_src
ba9fab2c Agustí Moll Garcia
svn --quiet co $(OWRT_SVN) $(BUILD_DIR)/$(TARGET)
a1fb6e5b Simó Albert i Beltran
mkdir -p dl
6f755fd4 p4u
ln -fs ../../dl $(BUILD_DIR)/$(TARGET)/dl
ln -fs ../qmp/files $(BUILD_DIR)/$(TARGET)/files
99db01bf Simó Albert i Beltran
ln -fs $(BUILD_DIR)/qmp/files
ff488f02 p4u
rm -rf $(BUILD_DIR)/$(TARGET)/feeds/
cp -f $(BUILD_DIR)/qmp/feeds.conf $(BUILD_DIR)/$(TARGET)/
sed -i -e "s|PATH|`pwd`/$(BUILD_DIR)|" $(BUILD_DIR)/$(TARGET)/feeds.conf
b9208096 p4u
endef

6f755fd4 p4u
define checkout_owrt_pkg_override
svn --quiet co ${OWRT_PKG_SVN} $(BUILD_DIR)/packages.$(TARGET)
2aaa878f Simó Albert i Beltran
sed -i -e "s|src-link packages .*|src-link packages `pwd`/$(BUILD_DIR)/packages.$(TARGET)|" $(BUILD_DIR)/$(TARGET)/feeds.conf
6f755fd4 p4u
endef

b9208096 p4u
define copy_config
79a54fd5 p4u
cp -f $(CONFIG_DIR)/$(TARGET)/config $(CONFIG) || echo "WARNING: Config file not found!"
2aaa878f Simó Albert i Beltran
cd $(BUILD_DIR)/$(TARGET) && ./scripts/diffconfig.sh > .config.tmp
ff488f02 p4u
cp -f $(BUILD_DIR)/$(TARGET)/.config.tmp $(BUILD_DIR)/$(TARGET)/.config
2aaa878f Simó Albert i Beltran
cd $(BUILD_DIR)/$(TARGET) && make defconfig
ff488f02 p4u
[ -f $(CONFIG_DIR)/$(TARGET)/kernel_config ] && cat $(CONFIG_DIR)/$(TARGET)/kernel_config >> $(CONFIG) || true
e518a2c2 Pau
endef

define update_feeds
e4a024c9 p4u
@echo "Updating feed $(1)"
./$(BUILD_DIR)/$(1)/scripts/feeds update -a
./$(BUILD_DIR)/$(1)/scripts/feeds install -a
e518a2c2 Pau
endef

define menuconfig_owrt
ff488f02 p4u
make -C $(BUILD_DIR)/$(TARGET) menuconfig
a88f4272 Simó Albert i Beltran
mkdir -p $(MY_CONFIGS)/$(TARGET)
ff488f02 p4u
cp -f $(CONFIG) $(MY_CONFIGS)/$(TARGET)/config
e518a2c2 Pau
endef

define kmenuconfig_owrt
ff488f02 p4u
make -C $(BUILD_DIR)/$(TARGET) kernel_menuconfig
a88f4272 Simó Albert i Beltran
mkdir -p $(MY_CONFIGS)/$(TARGET)
ff488f02 p4u
cp -f $(KCONFIG) $(MY_CONFIGS)/$(TARGET)/kernel_config
7eff0866 p4u
endef

1209afe3 p4u
define pre_build
$(foreach SCRIPT, $(wildcard $(SCRIPTS_DIR)/*.script), $(shell $(SCRIPT) PRE_BUILD $(TARGET)) )
endef

7eff0866 p4u
define post_build
cce89d3e p4u
$(eval COMP=$(shell ls $(BUILD_DIR)/$(TARGET)/$(IMAGE_PATH) 2>/dev/null | grep -c \\.gz))
a1fb6e5b Simó Albert i Beltran
mkdir -p $(IMAGES)
cce89d3e p4u
@[ $(COMP) -eq 1 ] && gunzip $(BUILD_DIR)/$(TARGET)/$(IMAGE_PATH) -c > $(IMAGES)/$(IM_NAME) || true
@[ $(COMP) -ne 1 ] && cp -f $(BUILD_DIR)/$(TARGET)/$(IMAGE_PATH) $(IMAGES)/$(IM_NAME) || true
ea02c353 Simó Albert i Beltran
@[ $(COMP) -eq 1 -a -n "$(SYSUPGRADE)" ] && gunzip $(BUILD_DIR)/$(TARGET)/$(SIMAGE_PATH) -c > $(IMAGES)/$(SIM_NAME) || true
@[ $(COMP) -ne 1 -a -n "$(SYSUPGRADE)" ] && cp -f $(BUILD_DIR)/$(TARGET)/$(SIMAGE_PATH) $(IMAGES)/$(SIM_NAME) || true
cce89d3e p4u
@[ -f $(IMAGES)/$(IM_NAME) ] || false
@echo $(IM_NAME)
64f33346 Simó Albert i Beltran
$(if $(SYSUPGRADE),@echo $(SIM_NAME))
1209afe3 p4u
$(foreach SCRIPT, $(wildcard $(SCRIPTS_DIR)/*.script), $(shell $(SCRIPT) POST_BUILD $(TARGET)) )
cce89d3e p4u
@echo "qMp firmware compiled, you can find output files in $(IMAGES) directory."
e518a2c2 Pau
endef

define clean_all
a88f4272 Simó Albert i Beltran
rm -rf $(BUILD_DIR)/*
rm -f .checkout_*
rm -f $(IMAGES)/*
e518a2c2 Pau
endef

define clean_target
a88f4272 Simó Albert i Beltran
rm -rf $(BUILD_DIR)/$(TARGET)
rm -f .checkout_$(TARGET)
rm -rf $(BUILD_DIR)/packages.$(TARGET)
rm -f .checkout_owrt_pkg_override_$(TARGET)
e518a2c2 Pau
endef

dbd4db87 p4u
define clean_pkg
echo "Cleaning package $1"
2aaa878f Simó Albert i Beltran
make $1/clean
dbd4db87 p4u
endef

e518a2c2 Pau
define target_error
@echo "You must specify target using T var (make T=alix build)"
@echo "To see avialable targets run: make list_targets"
@exit 1
endef

.checkout_qmp:
8be67335 p4u
@[ "$(DEV)" == "1" ] && echo "Using developer enviroment" || true
e518a2c2 Pau
git clone $(QMP_GIT) $(BUILD_DIR)/qmp
b4656cb9 Agustí Moll Garcia
cd $(BUILD_DIR)/qmp; git checkout $(QMP_GIT_BRANCH); cd ..
7eff0866 p4u
@touch $@
e518a2c2 Pau
e6c8d8eb Agustí Moll Garcia
.checkout_b6m:
git clone $(B6M_GIT) $(BUILD_DIR)/b6m
ca89f12f Agustí Moll Garcia
cd $(BUILD_DIR)/b6m; git checkout --track origin/$(B6M_GIT_BRANCH); cd ..
2aaa878f Simó Albert i Beltran
@touch $@
e6c8d8eb Agustí Moll Garcia
ca89f12f Agustí Moll Garcia
.checkout_owrt_pkg:
ba9fab2c Agustí Moll Garcia
svn --quiet co ${OWRT_PKG_SVN} $(BUILD_DIR)/packages
ca89f12f Agustí Moll Garcia
@touch $@

6f755fd4 p4u
.checkout_owrt_pkg_override:
$(if $(filter $(origin OWRT_PKG_SVN),override),$(if $(wildcard .checkout_owrt_pkg_override_$(TARGET)),,$(call checkout_owrt_pkg_override)),)
@touch .checkout_owrt_pkg_override_$(TARGET)

.checkout_owrt:
ff488f02 p4u
$(if $(TARGET),,$(call target_error))
$(if $(wildcard .checkout_$(TARGET)),,$(call checkout_src))
6f755fd4 p4u
c947bbe6 p4u
checkout: .checkout_qmp .checkout_b6m .checkout_owrt .checkout_owrt_pkg .checkout_owrt_pkg_override .checkout_qmp
ff488f02 p4u
$(if $(wildcard .checkout_$(TARGET)),,$(call update_feeds,$(TARGET)))
$(if $(wildcard .checkout_$(TARGET)),,$(call copy_config))
@touch .checkout_$(TARGET)
8fee292e p4u
sync_config:
ff488f02 p4u
$(if $(TARGET),,$(call target_error))
8fee292e p4u
$(call copy_config)
2aaa878f Simó Albert i Beltran
6f755fd4 p4u
update: .checkout_owrt_pkg .checkout_owrt_pkg_override .checkout_qmp .checkout_b6m
e518a2c2 Pau
cd $(BUILD_DIR)/qmp && git pull
8fee292e p4u
cd $(BUILD_DIR)/b6m && git pull
e4a024c9 p4u
update_all: update
efd8371e Simó Albert i Beltran
$(if $(TARGET),$(call update_feeds,$(TARGET)),$(foreach dir,$(HW_AVAILABLE),$(if $(wildcard $(BUILD_DIR)/$(dir)),$(call update_feeds,$(dir)))))
e518a2c2 Pau
menuconfig: checkout
6b5e8a5c p4u
$(call menuconfig_owrt)
2aaa878f Simó Albert i Beltran
e518a2c2 Pau
kernel_menuconfig: checkout
6b5e8a5c p4u
$(call kmenuconfig_owrt)
e518a2c2 Pau
clean:
ff488f02 p4u
$(if $(TARGET),$(call clean_target),$(call clean_all))
e518a2c2 Pau
dbd4db87 p4u
clean_qmp:
ff488f02 p4u
cd $(BUILD_DIR)/$(TARGET) ; \
dbd4db87 p4u
for d in $(QMP_FEED)/*; do make $$d/clean ; done

1209afe3 p4u
post_build: checkout
cce89d3e p4u
$(call post_build)

1209afe3 p4u
pre_build: checkout
$(call pre_build)


e518a2c2 Pau
list_targets:
7eff0866 p4u
$(info $(HW_AVAILABLE))
@exit 0
e518a2c2 Pau
config:
1209afe3 p4u
@select HW in $(HW_AVAILABLE); do break; done; echo $$HW > .config.tmp;
2aaa878f Simó Albert i Beltran
mv .config.tmp .config
e518a2c2 Pau
8be67335 p4u
help:
7c460e47 p4u
cat README | more || true
8be67335 p4u
e518a2c2 Pau
build: checkout
ff488f02 p4u
$(if $(TARGET),$(call build_src))
6b5e8a5c p4u
$(call post_build)
e518a2c2 Pau
e0248f77 p4u
all: build

4bdd4ad8 p4u
default: build